|
|
@ -270,9 +270,8 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/{username}")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain,
|
|
|
|
public Response getUser(@QueryParam("username") String username, @QueryParam("domain") String domain,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
username = domain + '/' + username;
|
|
|
|
username = domain + '/' + username;
|
|
|
@ -299,9 +298,8 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|
@Path("/{username}")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo) {
|
|
|
|
public Response updateUser(@QueryParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
username = domain + '/' + username;
|
|
|
|
username = domain + '/' + username;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -378,10 +376,9 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
@DELETE
|
|
|
|
@Path("/{username}")
|
|
|
|
|
|
|
|
@Consumes(MediaType.WILDCARD)
|
|
|
|
@Consumes(MediaType.WILDCARD)
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain) {
|
|
|
|
public Response removeUser(@QueryParam("username") String username, @QueryParam("domain") String domain) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
username = domain + '/' + username;
|
|
|
|
username = domain + '/' + username;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -413,9 +410,9 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/{username}/roles")
|
|
|
|
@Path("/roles")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain) {
|
|
|
|
public Response getRolesOfUser(@QueryParam("username") String username, @QueryParam("domain") String domain) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
username = domain + '/' + username;
|
|
|
|
username = domain + '/' + username;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -442,10 +439,11 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Path("/list")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp,
|
|
|
|
public Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp,
|
|
|
|
@QueryParam("offset") int offset,
|
|
|
|
@QueryParam("offset") int offset, @QueryParam("limit") int limit,
|
|
|
|
@QueryParam("limit") int limit) {
|
|
|
|
@QueryParam("domain") String domain) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting the list of users with all user-related information");
|
|
|
|
log.debug("Getting the list of users with all user-related information");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -464,8 +462,11 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
|
|
|
|
|
|
|
|
//As the listUsers function accepts limit only to accommodate offset we are passing offset + limit
|
|
|
|
//As the listUsers function accepts limit only to accommodate offset we are passing offset + limit
|
|
|
|
String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit);
|
|
|
|
List<String> users = Arrays.asList(userStoreManager.listUsers(appliedFilter, appliedLimit));
|
|
|
|
userList = new ArrayList<>(users.length);
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
|
|
|
|
users = getUsersFromDomain(domain, users);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
userList = new ArrayList<>(users.size());
|
|
|
|
BasicUserInfo user;
|
|
|
|
BasicUserInfo user;
|
|
|
|
for (String username : users) {
|
|
|
|
for (String username : users) {
|
|
|
|
user = getBasicUserInfo(username);
|
|
|
|
user = getBasicUserInfo(username);
|
|
|
@ -487,7 +488,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BasicUserInfoList result = new BasicUserInfoList();
|
|
|
|
BasicUserInfoList result = new BasicUserInfoList();
|
|
|
|
result.setList(offsetList);
|
|
|
|
result.setList(offsetList);
|
|
|
|
result.setCount(users.length);
|
|
|
|
result.setCount(userList.size());
|
|
|
|
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(result).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(result).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
@ -507,7 +508,7 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
@QueryParam("limit") int limit) {
|
|
|
|
@QueryParam("limit") int limit) {
|
|
|
|
|
|
|
|
|
|
|
|
if (RequestValidationUtil.isNonFilterRequest(username,firstName, lastName, emailAddress)) {
|
|
|
|
if (RequestValidationUtil.isNonFilterRequest(username,firstName, lastName, emailAddress)) {
|
|
|
|
return getUsers(null, timestamp, offset, limit);
|
|
|
|
return getUsers(null, timestamp, offset, limit, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
@ -693,7 +694,12 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
List<UserInfo> userList;
|
|
|
|
List<UserInfo> userList;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
String[] users = userStoreManager.listUsers(userStoreDomain + "/" + filter + "*", limit);
|
|
|
|
String[] users;
|
|
|
|
|
|
|
|
if (userStoreDomain.equals("all")) {
|
|
|
|
|
|
|
|
users = userStoreManager.listUsers(filter + "*", limit);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
users = userStoreManager.listUsers(userStoreDomain + "/" + filter + "*", limit);
|
|
|
|
|
|
|
|
}
|
|
|
|
userList = new ArrayList<>();
|
|
|
|
userList = new ArrayList<>();
|
|
|
|
UserInfo user;
|
|
|
|
UserInfo user;
|
|
|
|
for (String username : users) {
|
|
|
|
for (String username : users) {
|
|
|
@ -919,25 +925,29 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/claims/{username}")
|
|
|
|
@Path("/claims")
|
|
|
|
public Response updateUserClaimsForDevices(
|
|
|
|
public Response updateUserClaimsForDevices(
|
|
|
|
@PathParam("username") String username,
|
|
|
|
@QueryParam("username") String username, JsonArray deviceList,
|
|
|
|
JsonArray deviceList) {
|
|
|
|
@QueryParam("domain") String domain) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
|
|
|
|
.getUserRealm()
|
|
|
|
|
|
|
|
.getRealmConfiguration();
|
|
|
|
|
|
|
|
domain = realmConfiguration
|
|
|
|
|
|
|
|
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(domain)) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
String msg = "User by username: " + username + " does not exist.";
|
|
|
|
String msg = "User by username: " + username + " does not exist.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
|
|
|
|
.getUserRealm()
|
|
|
|
|
|
|
|
.getRealmConfiguration();
|
|
|
|
|
|
|
|
String domain = realmConfiguration
|
|
|
|
|
|
|
|
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(domain)) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ClaimMetadataManagementAdminService
|
|
|
|
ClaimMetadataManagementAdminService
|
|
|
|
claimMetadataManagementAdminService = new ClaimMetadataManagementAdminService();
|
|
|
|
claimMetadataManagementAdminService = new ClaimMetadataManagementAdminService();
|
|
|
|
//Get all available claim URIs
|
|
|
|
//Get all available claim URIs
|
|
|
@ -981,25 +991,29 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/claims/{username}")
|
|
|
|
@Path("/claims")
|
|
|
|
public Response getUserClaimsForDevices(
|
|
|
|
public Response getUserClaimsForDevices(
|
|
|
|
@PathParam("username") String username) {
|
|
|
|
@QueryParam("username") String username, @QueryParam("domain") String domain) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
Map<String, String> claims = new HashMap<>();
|
|
|
|
Map<String, String> claims = new HashMap<>();
|
|
|
|
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
|
|
|
|
.getUserRealm()
|
|
|
|
|
|
|
|
.getRealmConfiguration();
|
|
|
|
|
|
|
|
domain = realmConfiguration
|
|
|
|
|
|
|
|
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(domain)) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
String msg = "User by username: " + username + " does not exist.";
|
|
|
|
String msg = "User by username: " + username + " does not exist.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
|
|
|
|
.getUserRealm()
|
|
|
|
|
|
|
|
.getRealmConfiguration();
|
|
|
|
|
|
|
|
String domain = realmConfiguration
|
|
|
|
|
|
|
|
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(domain)) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
|
|
|
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
|
|
|
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
|
|
|
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -1019,25 +1033,29 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
@DELETE
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/claims/{username}")
|
|
|
|
@Path("/claims")
|
|
|
|
public Response deleteUserClaimsForDevices(
|
|
|
|
public Response deleteUserClaimsForDevices(
|
|
|
|
@PathParam("username") String username) {
|
|
|
|
@QueryParam("username") String username, @QueryParam("domain") String domain) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String[] claimArray = new String[1];
|
|
|
|
String[] claimArray = new String[1];
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
|
|
|
|
if (domain != null && !domain.isEmpty()) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
|
|
|
|
.getUserRealm()
|
|
|
|
|
|
|
|
.getRealmConfiguration();
|
|
|
|
|
|
|
|
domain = realmConfiguration
|
|
|
|
|
|
|
|
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(domain)) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
String msg = "User by username: " + username + " does not exist.";
|
|
|
|
String msg = "User by username: " + username + " does not exist.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RealmConfiguration realmConfiguration = PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
|
|
|
|
|
|
|
.getUserRealm()
|
|
|
|
|
|
|
|
.getRealmConfiguration();
|
|
|
|
|
|
|
|
String domain = realmConfiguration
|
|
|
|
|
|
|
|
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(domain)) {
|
|
|
|
|
|
|
|
username = domain + Constants.FORWARD_SLASH + username;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
|
|
|
String[] allUserClaims = userStoreManager.getClaimManager().getAllClaimUris();
|
|
|
|
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
|
|
|
if (!Arrays.asList(allUserClaims).contains(Constants.USER_CLAIM_DEVICES)) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -1306,4 +1324,23 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
userStoreList.setCount(userStores.size());
|
|
|
|
userStoreList.setCount(userStores.size());
|
|
|
|
return Response.status(Response.Status.OK).entity(userStoreList).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(userStoreList).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Iterates through the list of all users and returns a list of users from the specified user store domain
|
|
|
|
|
|
|
|
* @param domain user store domain name
|
|
|
|
|
|
|
|
* @param users list of all users from UserStoreManager
|
|
|
|
|
|
|
|
* @return list of users from specified user store domain
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public List<String> getUsersFromDomain(String domain, List<String> users) {
|
|
|
|
|
|
|
|
List<String> userList = new ArrayList<>();
|
|
|
|
|
|
|
|
for(String username : users) {
|
|
|
|
|
|
|
|
String[] domainName = username.split("/");
|
|
|
|
|
|
|
|
if(domain.equals(Constants.PRIMARY_USER_STORE) && domainName.length == 1) {
|
|
|
|
|
|
|
|
userList.add(username);
|
|
|
|
|
|
|
|
} else if (domainName[0].equals(domain) && domainName.length > 1) {
|
|
|
|
|
|
|
|
userList.add(username);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return userList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|