diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index aec751658b3..473c6354a8f 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -771,6 +771,7 @@ deleteLdapConfiguration=3 listLdapUsers=3 ldapCreateAccount=3 importLdapUsers=3 +linkDomainToLdap=3 #### juniper-contrail commands diff --git a/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml b/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml index 8ae4009367f..07d6b381328 100644 --- a/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml +++ b/plugins/user-authenticators/ldap/resources/META-INF/cloudstack/ldap/spring-ldap-context.xml @@ -35,5 +35,6 @@ + diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java index 8e5cd0c5176..8601c2d2298 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java @@ -20,8 +20,10 @@ package org.apache.cloudstack.api.command; import javax.inject.Inject; +import com.cloud.exception.InvalidParameterValueException; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; @@ -32,7 +34,8 @@ import org.apache.log4j.Logger; import com.cloud.user.Account; -@APICommand(name = "linkDomainToLdap", description = "link an existing cloudstack domain to group or OU in ldap", responseObject = LinkDomainToLdapResponse.class, since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +@APICommand(name = "linkDomainToLdap", description = "link an existing cloudstack domain to group or OU in ldap", responseObject = LinkDomainToLdapResponse.class, since = "4.6.0", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LinkDomainToLdapCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(LinkDomainToLdapCmd.class.getName()); private static final String s_name = "linkdomaintoldapresponse"; @@ -55,7 +58,14 @@ public class LinkDomainToLdapCmd extends BaseCmd { @Override public void execute() throws ServerApiException { // TODO Auto-generated method stub - + try { + LinkDomainToLdapResponse response = _ldapManager.linkDomainToLdap(domainId, type, name); + response.setObjectName("LinkDomainToLdap"); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (final InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString()); + } } @Override diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java index 31205c457ad..88f11ad12bb 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManager.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.response.LdapUserResponse; import com.cloud.exception.InvalidParameterValueException; import com.cloud.utils.Pair; import com.cloud.utils.component.PluggableService; +import org.apache.cloudstack.api.response.LinkDomainToLdapResponse; public interface LdapManager extends PluggableService { @@ -49,4 +50,6 @@ public interface LdapManager extends PluggableService { Pair, Integer> listConfigurations(LdapListConfigurationCmd cmd); List searchUsers(String query) throws NoLdapUserMatchingQueryException; + + LinkDomainToLdapResponse linkDomainToLdap(Long domainId, String type, String name); } \ No newline at end of file diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java index 8e912b8b030..d0f5d9fddd7 100644 --- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java @@ -25,6 +25,9 @@ import javax.inject.Inject; import javax.naming.NamingException; import javax.naming.ldap.LdapContext; +import org.apache.cloudstack.api.command.LinkDomainToLdapCmd; +import org.apache.cloudstack.api.response.LinkDomainToLdapResponse; +import org.apache.cloudstack.ldap.dao.LdapTrustMapDao; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -61,6 +64,9 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { @Inject LdapUserManagerFactory _ldapUserManagerFactory; + @Inject + LdapTrustMapDao _ldapTrustMapDao; + public LdapManagerImpl() { super(); @@ -168,6 +174,7 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { cmdList.add(LdapImportUsersCmd.class); cmdList.add(LDAPConfigCmd.class); cmdList.add(LDAPRemoveCmd.class); + cmdList.add(LinkDomainToLdapCmd.class); return cmdList; } @@ -243,4 +250,11 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { closeContext(context); } } + + @Override + public LinkDomainToLdapResponse linkDomainToLdap(Long domainId, String type, String name) { + // TODO Auto-generated method stub + LdapTrustMapVO ldapTrustMapVO = _ldapTrustMapDao.persist(new LdapTrustMapVO(domainId, type, name)); + return null; + } } diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapTrustMapVO.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapTrustMapVO.java new file mode 100644 index 00000000000..e4a9407ec6b --- /dev/null +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapTrustMapVO.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.ldap; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name = "ldap_trust_map") +public class LdapTrustMapVO implements InternalIdentity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "type") + private String type; + + @Column(name = "name") + private String name; + + @Column(name = "domain_id") + private long domainId; + + public LdapTrustMapVO(long domainId, String type, String name) { + this.domainId = domainId; + this.type = type; + this.name = name; + } + + @Override + public long getId() { + return id; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public long getDomainId() { + return domainId; + } + + public LdapTrustMapVO() { + } +} diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/dao/LdapTrustMapDao.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/dao/LdapTrustMapDao.java new file mode 100644 index 00000000000..c4173fe1961 --- /dev/null +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/dao/LdapTrustMapDao.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.ldap.dao; + +import org.apache.cloudstack.ldap.LdapTrustMapVO; + +import com.cloud.utils.db.GenericDao; + +public interface LdapTrustMapDao extends GenericDao { +} diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/dao/LdapTrustMapDaoImpl.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/dao/LdapTrustMapDaoImpl.java new file mode 100644 index 00000000000..a6ce2b1053f --- /dev/null +++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/dao/LdapTrustMapDaoImpl.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.ldap.dao; + +import javax.ejb.Local; + +import org.apache.cloudstack.ldap.LdapTrustMapVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; + +@Component +@Local(value = {LdapTrustMapDao.class}) +public class LdapTrustMapDaoImpl extends GenericDaoBase implements LdapTrustMapDao { + public LdapTrustMapDaoImpl() { + super(); + } +} diff --git a/setup/db/db/schema-452to460.sql b/setup/db/db/schema-452to460.sql index e013b2bf85c..af313646bde 100644 --- a/setup/db/db/schema-452to460.sql +++ b/setup/db/db/schema-452to460.sql @@ -399,3 +399,13 @@ CREATE TABLE `cloud`.`external_bigswitch_bcf_devices` ( CONSTRAINT `fk_external_bigswitch_bcf_devices__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`ldap_trust_map` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `domain_id` bigint unsigned NOT NULL, + `type` varchar(10) NOT NULL, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_ldap_trust_map__domain_id` (`id`), + KEY `fk_ldap_trust_map__domain_id` (`domain_id`), + CONSTRAINT `fk_ldap_trust_map__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;