Skip to content

Commit 5da7330

Browse files
committed
CLOUDSTACK-5236 : ability to identify where the user is from (ex. LDAP)
Added a source column to the user table. Source now has only two values UNKNOWN,LDAP with UNKNOWN being the default and is an enum is com.cloud.User. When the source is UNKNOWN, the old method of authenticating against all the available authenticators is used. If a source is available, only that particular authenticator will be used. added overloaded methods in AccountService to createUserAccount and createUser with source specified.
1 parent 659edb4 commit 5da7330

28 files changed

Lines changed: 167 additions & 60 deletions

File tree

api/src/com/cloud/user/AccountService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public interface AccountService {
5757
UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName,
5858
short accountType, Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID);
5959

60+
UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain,
61+
Map<String, String> details, String accountUUID, String userUUID, User.Source source);
62+
6063
/**
6164
* Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses
6265
* allocated/etc.
@@ -70,8 +73,10 @@ UserAccount createUserAccount(String userName, String password, String firstName
7073

7174
User getSystemUser();
7275

73-
User
74-
createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID);
76+
User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID);
77+
78+
User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID,
79+
User.Source source);
7580

7681
boolean isAdmin(Long accountId);
7782

api/src/com/cloud/user/User.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import org.apache.cloudstack.api.InternalIdentity;
2222

2323
public interface User extends OwnedBy, InternalIdentity {
24+
25+
public enum Source {
26+
LDAP, UNKNOWN
27+
}
28+
2429
public static final long UID_SYSTEM = 1;
2530

2631
@Override
@@ -76,4 +81,6 @@ public interface User extends OwnedBy, InternalIdentity {
7681

7782
boolean isDefault();
7883

84+
public Source getSource();
85+
7986
}

api/src/com/cloud/user/UserAccount.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ public interface UserAccount extends InternalIdentity {
6161
boolean isRegistered();
6262

6363
int getLoginAttempts();
64+
65+
public User.Source getSource();
6466
}

engine/schema/src/com/cloud/user/UserAccountVO.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.EnumType;
24+
import javax.persistence.Enumerated;
2325
import javax.persistence.GeneratedValue;
2426
import javax.persistence.GenerationType;
2527
import javax.persistence.Id;
@@ -99,6 +101,10 @@ public class UserAccountVO implements UserAccount, InternalIdentity {
99101
@Column(name = "state", table = "account", insertable = false, updatable = false)
100102
private String accountState;
101103

104+
@Column(name = "source")
105+
@Enumerated(value = EnumType.STRING)
106+
private User.Source source;
107+
102108
public UserAccountVO() {
103109
}
104110

@@ -281,4 +287,13 @@ public void setLoginAttempts(int loginAttempts) {
281287
public int getLoginAttempts() {
282288
return loginAttempts;
283289
}
290+
291+
@Override
292+
public User.Source getSource() {
293+
return source;
294+
}
295+
296+
public void setSource(User.Source source) {
297+
this.source = source;
298+
}
284299
}

engine/schema/src/com/cloud/user/UserVO.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public class UserVO implements User, Identity, InternalIdentity {
9797
@Column(name = "default")
9898
boolean isDefault;
9999

100+
@Column(name = "source")
101+
@Enumerated(value = EnumType.STRING)
102+
private Source source;
103+
100104
public UserVO() {
101105
this.uuid = UUID.randomUUID().toString();
102106
}
@@ -106,7 +110,7 @@ public UserVO(long id) {
106110
this.uuid = UUID.randomUUID().toString();
107111
}
108112

109-
public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, String uuid) {
113+
public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, String uuid, Source source) {
110114
this.accountId = accountId;
111115
this.username = username;
112116
this.password = password;
@@ -116,6 +120,7 @@ public UserVO(long accountId, String username, String password, String firstName
116120
this.timezone = timezone;
117121
this.state = State.enabled;
118122
this.uuid = uuid;
123+
this.source = source;
119124
}
120125

121126
@Override
@@ -270,4 +275,12 @@ public boolean isDefault() {
270275
return isDefault;
271276
}
272277

278+
public Source getSource() {
279+
return source;
280+
}
281+
282+
public void setSource(Source source) {
283+
this.source = source;
284+
}
285+
273286
}

plugins/dedicated-resources/test/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626

2727
import javax.inject.Inject;
2828

29+
import com.cloud.user.User;
2930
import junit.framework.Assert;
3031

32+
import org.apache.cloudstack.dedicated.DedicatedResourceManagerImpl;
33+
import org.apache.cloudstack.test.utils.SpringUtils;
3134
import org.apache.log4j.Logger;
3235
import org.junit.After;
3336
import org.junit.Before;
@@ -49,9 +52,7 @@
4952
import org.apache.cloudstack.affinity.AffinityGroupService;
5053
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
5154
import org.apache.cloudstack.context.CallContext;
52-
import org.apache.cloudstack.dedicated.DedicatedResourceManagerImpl;
5355
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
54-
import org.apache.cloudstack.test.utils.SpringUtils;
5556

5657
import com.cloud.dc.DedicatedResourceVO;
5758
import com.cloud.dc.dao.ClusterDao;
@@ -118,7 +119,7 @@ public void setUp() {
118119
AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
119120
DomainVO domain = new DomainVO("rootDomain", 5L, 5L, "networkDomain");
120121

121-
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
122+
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
122123

123124
CallContext.register(user, account);
124125
when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(account);

plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import javax.inject.Inject;
3636

37+
import com.cloud.user.User;
3738
import org.junit.After;
3839
import org.junit.Before;
3940
import org.junit.Test;
@@ -164,7 +165,7 @@ public void setUp() {
164165
acct.setDomainId(domainId);
165166
acct.setId(accountId);
166167

167-
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
168+
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
168169
CallContext.register(user, acct);
169170
}
170171

@@ -592,4 +593,4 @@ public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOEx
592593
}
593594
}
594595
}
595-
}
596+
}

plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.user.Account;
3131
import com.cloud.user.AccountManager;
3232
import com.cloud.user.AccountVO;
33+
import com.cloud.user.User;
3334
import com.cloud.user.UserVO;
3435
import com.cloud.user.dao.AccountDao;
3536
import com.cloud.user.dao.UserDao;
@@ -256,6 +257,7 @@ public boolean start() {
256257
user.setFirstname(BaremetalUtils.BAREMETAL_SYSTEM_ACCOUNT_NAME);
257258
user.setLastname(BaremetalUtils.BAREMETAL_SYSTEM_ACCOUNT_NAME);
258259
user.setPassword(UUID.randomUUID().toString());
260+
user.setSource(User.Source.UNKNOWN);
259261
user = userDao.persist(user);
260262

261263
String[] keys = acntMgr.createApiKeyAndSecretKey(user.getId());

plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30+
import com.cloud.user.User;
3031
import org.junit.After;
3132
import org.junit.Before;
3233
import org.junit.BeforeClass;
@@ -177,7 +178,7 @@ public void testSetUp() {
177178
acct.setAccountName("admin");
178179
acct.setDomainId(domainId);
179180

180-
UserVO user1 = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
181+
UserVO user1 = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
181182

182183
CallContext.register(user1, acct);
183184

plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,26 @@ public User createUser(String arg0, String arg1, String arg2, String arg3, Strin
124124
return null;
125125
}
126126

127+
@Override public User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId,
128+
String userUUID, User.Source source) {
129+
// TODO Auto-generated method stub
130+
return null;
131+
}
132+
127133
@Override
128134
public UserAccount createUserAccount(String arg0, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6, short arg7, Long arg8, String arg9,
129135
Map<String, String> arg10, String arg11, String arg12) {
130136
// TODO Auto-generated method stub
131137
return null;
132138
}
133139

140+
@Override
141+
public UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType,
142+
Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID, User.Source source) {
143+
// TODO Auto-generated method stub
144+
return null;
145+
}
146+
134147
@Override
135148
public Account finalizeOwner(Account arg0, String arg1, Long arg2, Long arg3) {
136149
return _systemAccount;

0 commit comments

Comments
 (0)