mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
f45dc6f739
@ -31,6 +31,7 @@ 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.*;
|
import org.wso2.carbon.user.api.*;
|
||||||
|
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;
|
||||||
@ -51,22 +52,29 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
|
|
||||||
private static final String API_BASE_PATH = "/roles";
|
private static final String API_BASE_PATH = "/roles";
|
||||||
private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class);
|
private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class);
|
||||||
|
private static final String PRIMARY_USER_STORE = "PRIMARY";
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Override
|
@Override
|
||||||
public Response getRoles(
|
public Response getRoles(
|
||||||
@QueryParam("filter") String filter,
|
@QueryParam("filter") String filter,
|
||||||
@QueryParam("user-store") String userStoreName,
|
@QueryParam("user-store") String userStore,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
||||||
List<String> filteredRoles;
|
List<String> filteredRoles;
|
||||||
RoleList targetRoles = new RoleList();
|
RoleList targetRoles = new RoleList();
|
||||||
|
|
||||||
|
//if user store is null set it to primary
|
||||||
|
if(userStore == null || "".equals(userStore)){
|
||||||
|
userStore = PRIMARY_USER_STORE;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//Get the total role count that matches the given filter
|
//Get the total role count that matches the given filter
|
||||||
filteredRoles = getRolesFromUserStore(filter);
|
filteredRoles = getRolesFromUserStore(filter, userStore);
|
||||||
targetRoles.setCount(filteredRoles.size());
|
targetRoles.setCount(filteredRoles.size());
|
||||||
|
|
||||||
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter), offset, limit);
|
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit);
|
||||||
targetRoles.setList(filteredRoles);
|
targetRoles.setList(filteredRoles);
|
||||||
|
|
||||||
return Response.ok().entity(targetRoles).build();
|
return Response.ok().entity(targetRoles).build();
|
||||||
@ -343,14 +351,14 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getRolesFromUserStore(String filter) throws UserStoreException {
|
private List<String> getRolesFromUserStore(String filter, String userStore) throws UserStoreException {
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] roles;
|
String[] roles;
|
||||||
boolean filterRolesByName = (!((filter == null) || filter.isEmpty()));
|
boolean filterRolesByName = (!((filter == null) || filter.isEmpty()));
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of user roles");
|
log.debug("Getting the list of user roles");
|
||||||
}
|
}
|
||||||
roles = userStoreManager.getRoleNames();
|
roles = userStoreManager.getRoleNames(userStore+"/*", -1, false, true, true);
|
||||||
// removing all internal roles, roles created for Service-providers and application related roles.
|
// removing all internal roles, roles created for Service-providers and application related roles.
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class DeviceIdentifier implements Serializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type.toLowerCase();
|
||||||
}
|
}
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|||||||
@ -95,7 +95,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
|
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
|
||||||
String type = null;
|
String type = null;
|
||||||
if (deviceIds.size() > 0) {
|
if (deviceIds.size() > 0) {
|
||||||
type = deviceIds.get(0).getType();
|
type = deviceIds.get(0).getType().toLowerCase();
|
||||||
}
|
}
|
||||||
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
|
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
|
||||||
addOperation(type, operation, deviceIds);
|
addOperation(type, operation, deviceIds);
|
||||||
|
|||||||
@ -41,7 +41,7 @@ var backendServiceInvoker = function () {
|
|||||||
* If the token pair s not set in the session this will send a redirect to the login page.
|
* If the token pair s not set in the session this will send a redirect to the login page.
|
||||||
*/
|
*/
|
||||||
privateMethods.getAccessToken = function () {
|
privateMethods.getAccessToken = function () {
|
||||||
var tokenPair = session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]);
|
var tokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]));
|
||||||
if (tokenPair) {
|
if (tokenPair) {
|
||||||
return tokenPair.accessToken;
|
return tokenPair.accessToken;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -23,20 +23,17 @@ var onFail;
|
|||||||
var log = new Log("/app/modules/login.js");
|
var log = new Log("/app/modules/login.js");
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
onSuccess = function (context) {
|
onSuccess = function (context) {
|
||||||
var properties;
|
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
if (context.input.samlToken) {
|
if (context.input.samlToken) {
|
||||||
properties = {samlToken: context.input.samlToken};
|
apiWrapperUtil.setupAccessTokenPairBySamlGrantType(context.input.username, context.input.samlToken);
|
||||||
apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_SAML, properties);
|
|
||||||
} else {
|
} else {
|
||||||
properties = {username: context.input.username, password: context.input.password};
|
apiWrapperUtil.setupAccessTokenPairByPasswordGrantType(context.input.username, context.input.password);
|
||||||
apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_PASSWORD, properties);
|
|
||||||
}
|
}
|
||||||
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var carbonServer = require("carbon").server;
|
var carbonServer = require("carbon").server;
|
||||||
(new carbonServer.Server({url: devicemgtProps["adminService"]}))
|
(new carbonServer.Server({url: devicemgtProps["adminService"]}))
|
||||||
.login(context.input.username, context.input.password);
|
.login(context.input.username, context.input.password);
|
||||||
};
|
};
|
||||||
|
|
||||||
onFail = function (error) {
|
onFail = function (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user