use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class LdapListUsersCmdTest method mockACSUserSearch.
private void mockACSUserSearch() {
UserResponse rmurphy = createMockUserResponse("rmurphy", User.Source.NATIVE);
UserResponse rohit = createMockUserResponse("rohit", User.Source.SAML2);
UserResponse abhi = createMockUserResponse("abhi", User.Source.LDAP);
ArrayList<UserResponse> responses = new ArrayList<>();
responses.add(rmurphy);
responses.add(rohit);
responses.add(abhi);
ListResponse<UserResponse> queryServiceResponse = new ListResponse<>();
queryServiceResponse.setResponses(responses);
doReturn(queryServiceResponse).when(queryService).searchForUsers(nullable(Long.class), nullable(Boolean.class));
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class LdapListUsersCmdTest method createMockUserResponse.
private UserResponse createMockUserResponse(String uid, User.Source source) {
UserResponse userResponse = new UserResponse();
userResponse.setUsername(uid);
userResponse.setUserSource(source);
// for now:
userResponse.setDomainId(LOCAL_DOMAIN_ID);
userResponse.setDomainName(LOCAL_DOMAIN_NAME);
return userResponse;
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class LdapListUsersCmd method traceUserList.
private void traceUserList() {
if (s_logger.isTraceEnabled()) {
StringBuilder users = new StringBuilder();
for (UserResponse user : cloudstackUsers) {
if (users.length() > 0) {
users.append(", ");
}
users.append(user.getUsername());
}
s_logger.trace(String.format("checking against %d cloudstackusers: %s.", this.cloudstackUsers.size(), users.toString()));
}
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class LdapListUsersCmd method filterLocalDomain.
/**
* filter the list of ldap users. no users visible to the caller already in the domain specified should be in the returned list
* @param input ldap response list of users
* @return a list of ldap users not already in ACS
*/
public List<LdapUserResponse> filterLocalDomain(List<LdapUserResponse> input) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("filtering local domain users");
}
final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
String domainId = getCurrentDomainId();
for (final LdapUserResponse user : input) {
UserResponse cloudstackUser = getCloudstackUser(user);
if (cloudstackUser == null || /*doesn't exist in cloudstack*/
!domainId.equals(cloudstackUser.getDomainId()) || /* doesn't exist in this domain */
!cloudstackUser.getUserSource().equalsIgnoreCase(User.Source.LDAP.toString())) /* is from another source */
{
ldapResponses.add(user);
}
}
annotateUserListWithSources(ldapResponses);
return ldapResponses;
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class LdapListUsersCmd method isACloudstackUser.
boolean isACloudstackUser(final LdapUser ldapUser) {
boolean rc = false;
final List<UserResponse> cloudstackUsers = getCloudstackUsers();
if (cloudstackUsers != null) {
for (final UserResponse cloudstackUser : cloudstackUsers) {
if (ldapUser.getUsername().equals(cloudstackUser.getUsername())) {
if (s_logger.isTraceEnabled()) {
s_logger.trace(String.format("found user %s in cloudstack", ldapUser.getUsername()));
}
rc = true;
} else {
if (s_logger.isTraceEnabled()) {
s_logger.trace(String.format("ldap user %s does not match cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername()));
}
}
}
}
return rc;
}
Aggregations