Skip to content

Commit ca8b375

Browse files
committed
CLOUDSTACK-8647: updated with review comments
made domainId compulsory in api LinkDomainToLdapCmd used accountServive from BaseCmd in LinkDomainToLdapCmd changed the allowed account type values to 0 and 2
1 parent 1c836a8 commit ca8b375

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import javax.inject.Inject;
2222

2323
import com.cloud.exception.InvalidParameterValueException;
24-
import com.cloud.user.AccountService;
2524
import com.cloud.user.User;
2625
import com.cloud.user.UserAccount;
2726
import org.apache.cloudstack.api.APICommand;
@@ -47,7 +46,8 @@ public class LinkDomainToLdapCmd extends BaseCmd {
4746
public static final Logger s_logger = Logger.getLogger(LinkDomainToLdapCmd.class.getName());
4847
private static final String s_name = "linkdomaintoldapresponse";
4948

50-
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "The id of the domain which has to be linked to LDAP.")
49+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "The id of the domain which has to be "
50+
+ "linked to LDAP.")
5151
private Long domainId;
5252

5353
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, required = true, description = "type of the ldap name. GROUP or OU")
@@ -59,16 +59,13 @@ public class LinkDomainToLdapCmd extends BaseCmd {
5959
@Parameter(name = ApiConstants.ADMIN, type = CommandType.STRING, required = false, description = "domain admin username in LDAP ")
6060
private String admin;
6161

62-
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.SHORT, required = true, description = "Type of the account to auto import. Specify 0 for user, 1 for root " +
63-
"admin, and 2 for domain admin")
62+
@Parameter(name = ApiConstants.ACCOUNT_TYPE, type = CommandType.SHORT, required = true, description = "Type of the account to auto import. Specify 0 for user and 2 for " +
63+
"domain admin")
6464
private short accountType;
6565

6666
@Inject
6767
private LdapManager _ldapManager;
6868

69-
@Inject
70-
public AccountService _accountService;
71-
7269
@Override
7370
public void execute() throws ServerApiException {
7471
try {

plugins/user-authenticators/ldap/src/org/apache/cloudstack/ldap/LdapManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ public LinkDomainToLdapResponse linkDomainToLdap(Long domainId, String type, Str
269269
Validate.notNull(type, "type cannot be null. It should either be GROUP or OU");
270270
Validate.notNull(domainId, "domainId cannot be null.");
271271
Validate.notEmpty(name, "GROUP or OU name cannot be empty");
272-
//Account type constants in com.cloud.user.Account
273-
Validate.isTrue(accountType>=0 && accountType<=5, "accountype should be a number from 0-5");
272+
//Account type should be 0 or 2. check the constants in com.cloud.user.Account
273+
Validate.isTrue(accountType==0 || accountType==2, "accountype should be either 0(normal user) or 2(domain admin)");
274274
LinkType linkType = LdapManager.LinkType.valueOf(type.toUpperCase());
275275
LdapTrustMapVO vo = _ldapTrustMapDao.persist(new LdapTrustMapVO(domainId, linkType, name, accountType));
276276
LinkDomainToLdapResponse response = new LinkDomainToLdapResponse(vo.getDomainId(), vo.getType().toString(), vo.getName(), vo.getAccountType());

plugins/user-authenticators/ldap/test/groovy/org/apache/cloudstack/ldap/LdapManagerImplSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class LdapManagerImplSpec extends spock.lang.Specification {
484484
then:
485485
thrown(IllegalArgumentException)
486486
where:
487-
accountType << [-1, 6, 20000, -500000]
487+
accountType << [-1, 1, 3, 4, 5, 6, 20000, -500000]
488488
}
489489
def "test linkDomainToLdap when all is well"(){
490490
def ldapManager = new LdapManagerImpl()

0 commit comments

Comments
 (0)