Cleaning up UserManagementService API implementation

revert-70aa11f8
prabathabey 9 years ago
parent f1eca17991
commit 0c54753b34

@ -0,0 +1,68 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "BasicUserInfo", description = "Basic user information and the roles of the user.")
public class BasicUserInfo {
private String username;
@ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true )
private String firstname;
@ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true )
private String lastname;
@ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true )
private String emailAddress;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
}

@ -0,0 +1,57 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
@ApiModel(value = "BasicUserInfoList", description = "This contains basic details of a set of users that matches " +
"a given criteria as a collection")
public class BasicUserInfoList extends BasePaginatedResult {
private List<BasicUserInfo> users = new ArrayList<>();
@ApiModelProperty(value = "List of devices returned")
@JsonProperty("users")
public List<BasicUserInfo> getList() {
return users;
}
public void setList(List<BasicUserInfo> users) {
this.users = users;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{\n");
sb.append(" count: ").append(getCount()).append(",\n");
sb.append(" next: ").append(getNext()).append(",\n");
sb.append(" previous: ").append(getPrevious()).append(",\n");
sb.append(" users: [").append(users).append("\n");
sb.append("]}\n");
return sb.toString();
}
}

@ -21,60 +21,23 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "UserWrapper", description = "User details and the roles of the user.")
public class UserWrapper {
private String username;
/*
Base64 encoded password
*/
@ApiModel(value = "UserInfo", description = "User details and the roles of the user.")
public class UserInfo extends BasicUserInfo {
@ApiModelProperty(name = "password", value = "Base64 encoded password.", required = true )
private String password;
@ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true )
private String firstname;
@ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true )
private String lastname;
@ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true )
private String emailAddress;
@ApiModelProperty(name = "roles", value = "List of roles.", required = true )
private String[] roles;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmailAddress() {
return emailAddress;
public String getPassword() {
return password;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
public void setPassword(String password) {
this.password = password;
}
/*
Giving a clone of the array since arrays are mutable
*/
public String[] getRoles() {
String[] copiedRoles = roles;
if (roles != null){
@ -87,11 +50,4 @@ public class UserWrapper {
this.roles = roles;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -27,17 +27,17 @@ import java.util.List;
@ApiModel(value = "List of users", description = "This contains a set of users that matches a given " +
"criteria as a collection")
public class UserList extends BasePaginatedResult {
public class UserInfoList extends BasePaginatedResult {
private List<UserWrapper> users = new ArrayList<>();
private List<UserInfo> users = new ArrayList<>();
@ApiModelProperty(value = "List of devices returned")
@JsonProperty("users")
public List<UserWrapper> getList() {
public List<UserInfo> getList() {
return users;
}
public void setList(List<UserWrapper> users) {
public void setList(List<UserInfo> users) {
this.users = users;
}
@ -54,5 +54,4 @@ public class UserList extends BasePaginatedResult {
return sb.toString();
}
}

@ -21,10 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
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.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@ -95,7 +92,7 @@ public interface UserManagementService {
@ApiParam(
name = "user",
value = "User related details.",
required = true) UserWrapper user);
required = true) UserInfo user);
@GET
@Path("/{username}")
@ -105,13 +102,13 @@ public interface UserManagementService {
value = "Getting details of a user.",
notes = "If you wish to get the details of a specific user that is registered with EMM,"
+ " you can do so using the REST API.",
response = UserWrapper.class,
response = BasicUserInfo.class,
tags = "User Management")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the requested role.",
response = UserWrapper.class,
response = BasicUserInfo.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
@ -209,7 +206,7 @@ public interface UserManagementService {
@ApiParam(
name = "userData",
value = "User related details.",
required = true) UserWrapper userData);
required = true) UserInfo userData);
@DELETE
@Path("/{username}")
@ -247,15 +244,12 @@ public interface UserManagementService {
value = "Get the role list of a user.",
notes = "A user can be assigned to one or more role in EMM. Using this REST API you are "
+ "able to get the role/roles a user is assigned to.",
response = String.class,
responseContainer = "List",
tags = "User Management")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the role list assigned to the user.",
response = String.class,
responseContainer = "List",
response = RoleList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
@ -297,15 +291,12 @@ public interface UserManagementService {
value = "Get user list",
notes = "If you wish to get the details of all the users registered with EMM, you can do so "
+ "using the REST API",
response = UserList.class,
responseContainer = "List",
tags = "User Management")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the requested role.",
response = UserList.class,
responseContainer = "List",
response = UserInfoList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
@ -364,8 +355,6 @@ public interface UserManagementService {
+ "search for that user by giving a character or a few characters in the username. "
+ "You will be given a list of users having the user name with the exact order of the "
+ "characters you provided.",
response = String.class,
responseContainer = "List",
tags = "User Management")
@ApiResponses(value = {
@ApiResponse(

@ -18,7 +18,6 @@
*/
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -26,12 +25,9 @@ import org.wso2.carbon.context.CarbonContext;
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.EmailMetaInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
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.service.impl.util.NotFoundException;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
@ -55,7 +51,7 @@ public class UserManagementServiceImpl implements UserManagementService {
@POST
@Override
public Response addUser(UserWrapper userWrapper) {
public Response addUser(UserInfo userWrapper) {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
@ -172,7 +168,7 @@ public class UserManagementServiceImpl implements UserManagementService {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(username)) {
UserWrapper user = new UserWrapper();
BasicUserInfo user = new BasicUserInfo();
user.setUsername(username);
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
@ -203,7 +199,7 @@ public class UserManagementServiceImpl implements UserManagementService {
@PUT
@Path("/{username}")
@Override
public Response updateUser(@PathParam("username") String username, UserWrapper userWrapper) {
public Response updateUser(@PathParam("username") String username, UserInfo userWrapper) {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(userWrapper.getUsername())) {
@ -316,8 +312,9 @@ public class UserManagementServiceImpl implements UserManagementService {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (userStoreManager.isExistingUser(username)) {
return Response.status(Response.Status.OK).entity(Collections.singletonList(
getFilteredRoles(userStoreManager, username))).build();
RoleList result = new RoleList();
result.setList(getFilteredRoles(userStoreManager, username));
return Response.status(Response.Status.OK).entity(result).build();
} else {
// Outputting debug message upon trying to remove non-existing user
if (log.isDebugEnabled()) {
@ -343,7 +340,7 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information");
}
List<UserWrapper> userList, offsetList;
List<BasicUserInfo> userList, offsetList;
String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter);
int appliedLimit = (limit <= 0) ? -1 : (limit + offset);
@ -353,9 +350,9 @@ public class UserManagementServiceImpl implements UserManagementService {
//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);
UserWrapper user;
BasicUserInfo user;
for (String username : users) {
user = new UserWrapper();
user = new BasicUserInfo();
user.setUsername(username);
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
@ -368,12 +365,7 @@ public class UserManagementServiceImpl implements UserManagementService {
} else {
offsetList = new ArrayList<>();
}
// if (offsetList.size() <= 0) {
// return Response.status(Response.Status.NOT_FOUND).entity("No users available for retrieval").build();
// }
UserList result = new UserList();
BasicUserInfoList result = new BasicUserInfoList();
result.setList(offsetList);
result.setCount(offsetList.size());
@ -394,14 +386,14 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information using the filter : " + filter);
}
List<UserWrapper> userList;
List<UserInfo> userList;
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
String[] users = userStoreManager.listUsers(filter + "*", -1);
userList = new ArrayList<>(users.length);
UserWrapper user;
UserInfo user;
for (String username : users) {
user = new UserWrapper();
user = new UserInfo();
user.setUsername(username);
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));

Loading…
Cancel
Save