mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Accept a role ID on linking an account to LDAP (#8236)
* accept role on link account to ldap * reformat tests * validation * Update plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmd.java Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
This commit is contained in:
		
							parent
							
								
									7f0d9a0304
								
							
						
					
					
						commit
						6d7c042bc1
					
				| @ -33,6 +33,7 @@ import org.apache.cloudstack.api.ServerApiException; | ||||
| import org.apache.cloudstack.api.response.DomainResponse; | ||||
| import org.apache.cloudstack.api.response.LinkAccountToLdapResponse; | ||||
| import org.apache.cloudstack.api.response.LinkDomainToLdapResponse; | ||||
| import org.apache.cloudstack.api.response.RoleResponse; | ||||
| import org.apache.cloudstack.ldap.LdapManager; | ||||
| import org.apache.cloudstack.ldap.LdapUser; | ||||
| import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException; | ||||
| @ -63,9 +64,12 @@ public class LinkAccountToLdapCmd extends BaseCmd { | ||||
|     @Parameter(name = ApiConstants.ADMIN, type = CommandType.STRING, required = false, description = "domain admin username in LDAP ") | ||||
|     private String admin; | ||||
| 
 | ||||
|     @Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.INTEGER, required = true, description = "Type of the account to auto import. Specify 0 for user and 2 for " | ||||
|     @Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.INTEGER, required = false, description = "Type of the account to auto import. Specify 0 for user and 2 for " | ||||
|             + "domain admin") | ||||
|     private int accountType; | ||||
|     private Integer accountType; | ||||
| 
 | ||||
|     @Parameter(name = ApiConstants.ROLE_ID, type = CommandType.UUID, entityType = RoleResponse.class, required = false, description = "Creates the account under the specified role.", since="4.19.1") | ||||
|     private Long roleId; | ||||
| 
 | ||||
|     @Inject | ||||
|     private LdapManager _ldapManager; | ||||
| @ -134,7 +138,14 @@ public class LinkAccountToLdapCmd extends BaseCmd { | ||||
|     } | ||||
| 
 | ||||
|     public Account.Type getAccountType() { | ||||
|         return Account.Type.getFromValue(accountType); | ||||
|         if (accountType == null) { | ||||
|             return RoleType.getAccountTypeByRole(roleService.findRole(roleId), null); | ||||
|         } | ||||
|         return RoleType.getAccountTypeByRole(roleService.findRole(roleId), Account.Type.getFromValue(accountType.intValue())); | ||||
|     } | ||||
| 
 | ||||
|     public Long getRoleId() { | ||||
|         return RoleType.getRoleByAccountType(roleId, getAccountType()); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | ||||
| @ -451,11 +451,12 @@ public class LdapManagerImpl extends ComponentLifecycleBase implements LdapManag | ||||
|         Validate.notEmpty(cmd.getLdapDomain(), "ldapDomain cannot be empty, please supply a GROUP or OU name"); | ||||
|         Validate.notNull(cmd.getType(), "type cannot be null. It should either be GROUP or OU"); | ||||
|         Validate.notEmpty(cmd.getLdapDomain(), "GROUP or OU name cannot be empty"); | ||||
|         Validate.isTrue(cmd.getAccountType() != null || cmd.getRoleId() != null, "Either account type or role ID must be given"); | ||||
| 
 | ||||
|         LinkType linkType = LdapManager.LinkType.valueOf(cmd.getType().toUpperCase()); | ||||
|         Account account = accountDao.findActiveAccount(cmd.getAccountName(),cmd.getDomainId()); | ||||
|         if (account == null) { | ||||
|             account = new AccountVO(cmd.getAccountName(), cmd.getDomainId(), null, cmd.getAccountType(), UUID.randomUUID().toString()); | ||||
|             account = new AccountVO(cmd.getAccountName(), cmd.getDomainId(), null, cmd.getAccountType(), cmd.getRoleId(), UUID.randomUUID().toString()); | ||||
|             accountDao.persist((AccountVO)account); | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -52,12 +52,7 @@ class TestLdap(cloudstackTestCase): | ||||
| 
 | ||||
|     @classmethod | ||||
|     def tearDownClass(cls): | ||||
|         try: | ||||
|             cleanup_resources(cls.api_client, cls._cleanup) | ||||
| 
 | ||||
|         except Exception as tde: | ||||
|             raise Exception("Warning: Exception during cleanup : %s" % tde) | ||||
|         return | ||||
|         super(TestLdap, cls).tearDownClass() | ||||
| 
 | ||||
|     def setUp(self): | ||||
| 
 | ||||
|  | ||||
| @ -101,7 +101,9 @@ class TestLDAP(cloudstackTestCase): | ||||
|     def tearDownClass(cls): | ||||
|         cls.logger.info("Tearing Down Class") | ||||
|         try: | ||||
|             cleanup_resources(cls.apiclient, reversed(cls._cleanup)) | ||||
|             super(TestLDAP, cls).tearDownClass() | ||||
|         finally: | ||||
|             try: | ||||
|                 cls.remove_ldap_configuration_for_domains() | ||||
|                 cls.logger.debug("done cleaning up resources in tearDownClass(cls) %s") | ||||
|             except Exception as e: | ||||
| @ -116,11 +118,7 @@ class TestLDAP(cloudstackTestCase): | ||||
|         return | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         try: | ||||
|             cleanup_resources(self.apiclient, self.cleanup) | ||||
|         except Exception as e: | ||||
|             raise Exception("Warning: Exception during cleanup : %s" % e) | ||||
|         return | ||||
|         super(TestLDAP, self).tearDown() | ||||
| 
 | ||||
|     @attr(tags=["smoke", "advanced"], required_hardware="false") | ||||
|     def test_01_manual(self): | ||||
| @ -349,8 +347,8 @@ class TestLDAP(cloudstackTestCase): | ||||
|         if parent_domain: | ||||
|             domain_to_create["parentdomainid"] = parent_domain | ||||
|         tmpDomain = Domain.create(cls.apiclient, domain_to_create) | ||||
|         cls.logger.debug("Created domain %s with id %s " % (tmpDomain.name, tmpDomain.id)) | ||||
|         cls._cleanup.append(tmpDomain) | ||||
|         cls.logger.debug("Created domain %s with id %s " % (tmpDomain.name, tmpDomain.id)) | ||||
|         return tmpDomain | ||||
| 
 | ||||
|     @classmethod | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user