|
|
@ -30,37 +30,20 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
|
|
|
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
|
|
|
import org.wso2.carbon.user.api.*;
|
|
|
|
import org.wso2.carbon.user.api.Permission;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.UserRealm;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
|
|
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
|
|
|
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
|
|
|
import org.wso2.carbon.user.mgt.UserRealmProxy;
|
|
|
|
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
|
|
|
import org.wso2.carbon.user.mgt.common.UIPermissionNode;
|
|
|
|
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
|
|
|
import org.wso2.carbon.user.mgt.common.UserAdminException;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
|
|
|
import javax.ws.rs.HeaderParam;
|
|
|
|
|
|
|
|
import javax.ws.rs.POST;
|
|
|
|
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.wso2.carbon.device.mgt.jaxrs.util.Constants.PRIMARY_USER_STORE;
|
|
|
|
import static org.wso2.carbon.device.mgt.jaxrs.util.Constants.PRIMARY_USER_STORE;
|
|
|
|
|
|
|
|
|
|
|
@ -105,6 +88,46 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Response getFilteredRoles(
|
|
|
|
|
|
|
|
@PathParam("prefix") String prefix,
|
|
|
|
|
|
|
|
@QueryParam("filter") String filter,
|
|
|
|
|
|
|
|
@QueryParam("user-store") String userStore,
|
|
|
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
|
|
|
|
|
|
|
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
|
|
|
|
|
List<String> finalRoleList;
|
|
|
|
|
|
|
|
RoleList targetRoles = new RoleList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if user store is null set it to primary
|
|
|
|
|
|
|
|
if (userStore == null || "".equals(userStore)) {
|
|
|
|
|
|
|
|
userStore = PRIMARY_USER_STORE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Get the total role count that matches the given filter
|
|
|
|
|
|
|
|
List<String> filteredRoles = getRolesFromUserStore(filter, userStore);
|
|
|
|
|
|
|
|
finalRoleList = new ArrayList<String>();
|
|
|
|
|
|
|
|
targetRoles.setCount(filteredRoles.size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit);
|
|
|
|
|
|
|
|
for (String rolename : filteredRoles){
|
|
|
|
|
|
|
|
if (rolename.startsWith(prefix)){
|
|
|
|
|
|
|
|
finalRoleList.add(rolename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
targetRoles.setList(finalRoleList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Response.ok().entity(targetRoles).build();
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving roles from the underlying user stores";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/{roleName}/permissions")
|
|
|
|
@Path("/{roleName}/permissions")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -404,7 +427,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
// Get all role permissions
|
|
|
|
// Get all role permissions
|
|
|
|
final UIPermissionNode rolePermissions = this.getAllRolePermissions(roleName, userRealm);
|
|
|
|
final UIPermissionNode rolePermissions = this.getAllRolePermissions(roleName, userRealm);
|
|
|
|
List<String> permissions = new ArrayList<String>();
|
|
|
|
List<String> permissions = new ArrayList<String>();
|
|
|
|
final UIPermissionNode emmRolePermissions = (UIPermissionNode)this.getRolePermissions(roleName);
|
|
|
|
final UIPermissionNode emmRolePermissions = (UIPermissionNode) this.getRolePermissions(roleName);
|
|
|
|
List<String> emmConsolePermissions = new ArrayList<String>();
|
|
|
|
List<String> emmConsolePermissions = new ArrayList<String>();
|
|
|
|
this.getAuthorizedPermissions(emmRolePermissions, emmConsolePermissions);
|
|
|
|
this.getAuthorizedPermissions(emmRolePermissions, emmConsolePermissions);
|
|
|
|
emmConsolePermissions.removeAll(new ArrayList<String>(Arrays.asList(roleInfo.getPermissions())));
|
|
|
|
emmConsolePermissions.removeAll(new ArrayList<String>(Arrays.asList(roleInfo.getPermissions())));
|
|
|
@ -413,7 +436,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
permissions.add(permission);
|
|
|
|
permissions.add(permission);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
permissions.removeAll(emmConsolePermissions);
|
|
|
|
permissions.removeAll(emmConsolePermissions);
|
|
|
|
String [] allApplicablePerms = new String[permissions.size()];
|
|
|
|
String[] allApplicablePerms = new String[permissions.size()];
|
|
|
|
allApplicablePerms = permissions.toArray(allApplicablePerms);
|
|
|
|
allApplicablePerms = permissions.toArray(allApplicablePerms);
|
|
|
|
roleInfo.setPermissions(allApplicablePerms);
|
|
|
|
roleInfo.setPermissions(allApplicablePerms);
|
|
|
|
|
|
|
|
|
|
|
|