|
|
@ -26,9 +26,12 @@ import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.UserCredentialWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
@ -85,11 +88,13 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Exception in trying to add user '" + userWrapper.getUsername() + "' to the user store";
|
|
|
|
String msg = "Exception in trying to add user '" + userWrapper.getUsername() + "' to the user store";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String msg = "ErrorResponse occurred while inviting user to enroll the device";
|
|
|
|
String msg = "ErrorResponse occurred while inviting user to enroll the device";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -142,10 +147,10 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
Properties props = new Properties();
|
|
|
|
Properties props = new Properties();
|
|
|
|
props.setProperty("username", usernameBits[1]);
|
|
|
|
props.setProperty("username", usernameBits[1]);
|
|
|
|
props.setProperty("domain-name", tenantDomain);
|
|
|
|
props.setProperty("domain-name", tenantDomain);
|
|
|
|
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
|
|
|
props.setProperty("first-name", getClaimValue(usernameBits[1], Constants.USER_CLAIM_FIRST_NAME));
|
|
|
|
props.setProperty("password", password);
|
|
|
|
props.setProperty("password", password);
|
|
|
|
|
|
|
|
|
|
|
|
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
|
|
|
String recipient = getClaimValue(usernameBits[1], Constants.USER_CLAIM_EMAIL_ADDRESS);
|
|
|
|
|
|
|
|
|
|
|
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
|
|
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
|
|
|
|
|
|
|
|
|
|
@ -187,7 +192,8 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving information of the user '" + username + "'";
|
|
|
|
String msg = "ErrorResponse occurred while retrieving information of the user '" + username + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -203,9 +209,8 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
userWrapper.getEmailAddress());
|
|
|
|
userWrapper.getEmailAddress());
|
|
|
|
if (StringUtils.isNotEmpty(userWrapper.getPassword())) {
|
|
|
|
if (StringUtils.isNotEmpty(userWrapper.getPassword())) {
|
|
|
|
// Decoding Base64 encoded password
|
|
|
|
// Decoding Base64 encoded password
|
|
|
|
byte[] decodedBytes = Base64.decodeBase64(userWrapper.getPassword());
|
|
|
|
|
|
|
|
userStoreManager.updateCredentialByAdmin(userWrapper.getUsername(),
|
|
|
|
userStoreManager.updateCredentialByAdmin(userWrapper.getUsername(),
|
|
|
|
new String(decodedBytes, "UTF-8"));
|
|
|
|
userWrapper.getPassword());
|
|
|
|
log.debug("User credential of username: " + userWrapper.getUsername() + " has been changed");
|
|
|
|
log.debug("User credential of username: " + userWrapper.getUsername() + " has been changed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<String> currentRoles = this.getFilteredRoles(userStoreManager, userWrapper.getUsername());
|
|
|
|
List<String> currentRoles = this.getFilteredRoles(userStoreManager, userWrapper.getUsername());
|
|
|
@ -242,10 +247,11 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
userWrapper.getUsername() + " doesn't exists. Therefore, request made to update user was " +
|
|
|
|
userWrapper.getUsername() + " doesn't exists. Therefore, request made to update user was " +
|
|
|
|
"refused.").build();
|
|
|
|
"refused.").build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UserStoreException | UnsupportedEncodingException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
|
|
|
|
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -293,11 +299,12 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Exception in trying to remove user by username: " + username;
|
|
|
|
String msg = "Exception in trying to remove user by username: " + username;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
@GET
|
|
|
|
@Path("/{username}/roles")
|
|
|
|
@Path("/{username}/roles")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getRolesOfUser(@PathParam("username") String username) {
|
|
|
|
public Response getRolesOfUser(@PathParam("username") String username) {
|
|
|
@ -317,7 +324,8 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Exception in trying to retrieve roles for user by username: " + username;
|
|
|
|
String msg = "Exception in trying to retrieve roles for user by username: " + username;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -329,10 +337,15 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<UserWrapper> userList;
|
|
|
|
List<UserWrapper> userList, offsetList;
|
|
|
|
|
|
|
|
String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter);
|
|
|
|
|
|
|
|
int appliedLimit = (limit <= 0) ? -1 : (limit + offset);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
String[] users = userStoreManager.listUsers("*", -1);
|
|
|
|
|
|
|
|
|
|
|
|
//As the listUsers function accepts limit only to accommodate offset we are passing offset + limit
|
|
|
|
|
|
|
|
String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit);
|
|
|
|
userList = new ArrayList<>(users.length);
|
|
|
|
userList = new ArrayList<>(users.length);
|
|
|
|
UserWrapper user;
|
|
|
|
UserWrapper user;
|
|
|
|
for (String username : users) {
|
|
|
|
for (String username : users) {
|
|
|
@ -343,14 +356,27 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
|
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
|
|
userList.add(user);
|
|
|
|
userList.add(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userList.size() <= 0) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity("No user is available to be retrieved").build();
|
|
|
|
if (offset <= userList.size()) {
|
|
|
|
|
|
|
|
offsetList = userList.subList(offset, userList.size());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
offsetList = new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(userList).build();
|
|
|
|
|
|
|
|
|
|
|
|
// if (offsetList.size() <= 0) {
|
|
|
|
|
|
|
|
// return Response.status(Response.Status.NOT_FOUND).entity("No users available for retrieval").build();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserList result = new UserList();
|
|
|
|
|
|
|
|
result.setList(offsetList);
|
|
|
|
|
|
|
|
result.setCount(offsetList.size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(result).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the list of users";
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the list of users.";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -376,22 +402,23 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
|
|
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
|
|
|
|
userList.add(user);
|
|
|
|
userList.add(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userList.size() <= 0) {
|
|
|
|
// if (userList.size() <= 0) {
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity("No user is available to be retrieved").build();
|
|
|
|
// return Response.status(Response.Status.NOT_FOUND).entity("No user is available to be retrieved").build();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
return Response.status(Response.Status.OK).entity(userList).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(userList).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the list of users using the filter : " + filter;
|
|
|
|
String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|
@Path("/{username}/credentials")
|
|
|
|
@Path("/{username}/credentials")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response resetPassword(@PathParam("username") String username, UserCredentialWrapper credentials) {
|
|
|
|
public Response resetPassword(@PathParam("username") String username, OldPasswordResetWrapper credentials) {
|
|
|
|
return CredentialManagementResponseBuilder.buildChangePasswordResponse(credentials);
|
|
|
|
return CredentialManagementResponseBuilder.buildChangePasswordResponse(username, credentials);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|