revert-70aa11f8
hasuniea 8 years ago
commit b3582f9d47

@ -134,14 +134,14 @@ public class UserManagementServiceImpl implements UserManagementService {
public Response updateUser(@PathParam("username") String username, UserInfo userInfo) {
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (!userStoreManager.isExistingUser(userInfo.getUsername())) {
if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) {
log.debug("User by username: " + userInfo.getUsername() +
log.debug("User by username: " + username +
" doesn't exists. Therefore, request made to update user was refused.");
}
return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
userInfo.getUsername() + " doesn't exist.").build()).build();
username + " doesn't exist.").build()).build();
}
Map<String, String> defaultUserClaims =
@ -149,11 +149,11 @@ public class UserManagementServiceImpl implements UserManagementService {
userInfo.getEmailAddress());
if (StringUtils.isNotEmpty(userInfo.getPassword())) {
// Decoding Base64 encoded password
userStoreManager.updateCredentialByAdmin(userInfo.getUsername(),
userStoreManager.updateCredentialByAdmin(username,
userInfo.getPassword());
log.debug("User credential of username: " + userInfo.getUsername() + " has been changed");
log.debug("User credential of username: " + username + " has been changed");
}
List<String> currentRoles = this.getFilteredRoles(userStoreManager, userInfo.getUsername());
List<String> currentRoles = this.getFilteredRoles(userStoreManager, username);
List<String> newRoles = Arrays.asList(userInfo.getRoles());
List<String> rolesToAdd = new ArrayList<>(newRoles);
@ -167,19 +167,19 @@ public class UserManagementServiceImpl implements UserManagementService {
}
}
rolesToDelete.remove(ROLE_EVERYONE);
userStoreManager.updateRoleListOfUser(userInfo.getUsername(),
userStoreManager.updateRoleListOfUser(username,
rolesToDelete.toArray(new String[rolesToDelete.size()]),
rolesToAdd.toArray(new String[rolesToAdd.size()]));
userStoreManager.setUserClaimValues(userInfo.getUsername(), defaultUserClaims, null);
userStoreManager.setUserClaimValues(username, defaultUserClaims, null);
// Outputting debug message upon successful addition of user
if (log.isDebugEnabled()) {
log.debug("User by username: " + userInfo.getUsername() + " was successfully updated.");
log.debug("User by username: " + username + " was successfully updated.");
}
BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username);
return Response.ok().entity(updatedUserInfo).build();
} catch (UserStoreException e) {
String msg = "Error occurred while trying to update user '" + userInfo.getUsername() + "'";
String msg = "Error occurred while trying to update user '" + username + "'";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();

@ -1,52 +0,0 @@
package org.wso2.carbon.device.mgt.core.internal;
///**
// * @scr.component name="org.wso2.carbon.certificate.mgt.core.scep" immediate="true"
// * @scr.reference name="app.mgt.service"
// * interface="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService"
// * cardinality="1..1"
// * policy="dynamic"
// * bind="setApplicationManagementProviderService"
// * unbind="unsetApplicationManagementProviderService"
// */
//public class SCEPManagerServiceComponent {
//
// private static final Log log = LogFactory.getLog(SCEPManagerServiceComponent.class);
//
// protected void activate(ComponentContext componentContext) {
//
// try {
// if (log.isDebugEnabled()) {
// log.debug("Initializing SCEP core bundle");
// }
//
// BundleContext bundleContext = componentContext.getBundleContext();
// bundleContext.registerService(SCEPManager.class.getName(),
// new SCEPManagerImpl(), null);
//
// if (log.isDebugEnabled()) {
// log.debug("SCEP core bundle has been successfully initialized");
// }
// } catch (Throwable e) {
// String msg = "Error occurred while initializing SCEP core bundle";
// log.error(msg, e);
// }
// }
//
// protected void deactivate(ComponentContext ctx) {
// if (log.isDebugEnabled()) {
// log.debug("Deactivating SCEP core bundle");
// }
// }
//
// protected void unsetApplicationManagementProviderService(ApplicationManagementProviderService
// applicationManagementProviderService) {
// //do nothing
// }
//
// protected void setApplicationManagementProviderService(ApplicationManagementProviderService
// applicationManagementProviderService) {
// //do nothing
// }
//
//}

@ -35,18 +35,20 @@ function appendQueryParam (url, queryParam , value) {
if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
var url = request.getParameter("url");
var targetURL = devicemgtProps["httpsURL"] + request.getParameter("url");
//noinspection JSUnresolvedFunction getAllParameters
var allParams = request.getAllParameters();
for (var key in allParams) {
if (allParams.hasOwnProperty(key)) {
if(key == "limit" || key == "offset"){
targetURL = appendQueryParam(targetURL, key, allParams[key]);
for (var allParamsKey in allParams) {
if (allParams.hasOwnProperty(allParamsKey)) {
if (allParamsKey == "limit" || allParamsKey == "offset") {
targetURL = appendQueryParam(targetURL, allParamsKey, allParams[allParamsKey]);
} else if (allParamsKey == "filter") {
if (allParams[allParamsKey]) {
var searchPayload = JSON.parse(allParams[allParamsKey]);
for (var searchPayloadKey in searchPayload) {
if (searchPayload.hasOwnProperty(searchPayloadKey)) {
targetURL = appendQueryParam(targetURL, searchPayloadKey, searchPayload[searchPayloadKey]);
}
if(key == "filter"){
if(allParams[key]){
var searchPayload = JSON.parse(allParams[key]);
for (var key in searchPayload) {
targetURL = appendQueryParam(targetURL, key, searchPayload[key]);
}
}
}

@ -32,8 +32,8 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) {
var length = request.getParameter("length");
var search = request.getParameter("search[value]");
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/" +
deviceType + "/" + deviceId + "/operations?offset=" + index + "&limit=" + length;
var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/devices/" + deviceType + "/" + deviceId + "/operations?offset=" + index + "&limit=" + length;
serviceInvokers.XMLHttp.get(
restAPIEndpoint,
@ -46,7 +46,7 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) {
paginatedResult["recordsFiltered"] = responsePayload["count"];
paginatedResult["data"] = responsePayload["operations"];
response["status"] = 200;
response["status"] = restAPIResponse["status"];
response["content"] = paginatedResult;
} else {
response["status"] = restAPIResponse["status"];

@ -26,11 +26,11 @@ var constants = require("/app/modules/constants.js");
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var utility = require("/app/modules/utility.js").utility;
var utility = require("/app/modules/utility.js")["utility"];
var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"];
var util = require("/app/modules/oauth/token-handler-utils.js")["utils"];
var responseProcessor = require('utils').response;
var responseProcessor = require("utils").response;
var result;
@ -69,9 +69,9 @@ if (uriMatcher.match("/{context}/api/user/authenticate")) {
apiWrapperUtil.setupTokenPairByPasswordGrantType(username, password);
var permissions = userModule.getUIPermissions();
if (permissions.VIEW_DASHBOARD) {
response.sendRedirect(constants.WEB_APP_CONTEXT);
response.sendRedirect(devicemgtProps["appContext"]);
} else {
response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices");
response.sendRedirect(devicemgtProps["appContext"] + "devices");
}
}, function () {
response.sendRedirect(devicemgtProps.appContext + "login?#auth-failed");

@ -22,7 +22,7 @@ deviceModule = function () {
var utility = require('/app/modules/utility.js').utility;
var constants = require('/app/modules/constants.js');
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
// var ArrayList = Packages.java.util.ArrayList;
@ -244,7 +244,7 @@ deviceModule = function () {
try {
utility.startTenantFlow(carbonUser);
//var url = mdmProps["httpsURL"] + "/mdm-admin/devices/view?type=" + deviceType + "&id=" + deviceId;
var url = mdmProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId;
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId;
return serviceInvokers.XMLHttp.get(
url,
function (backendResponse) {
@ -294,10 +294,11 @@ deviceModule = function () {
var uiPermissions = userModule.getUIPermissions();
var url;
if (uiPermissions.LIST_DEVICES) {
url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count";
url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/count";
} else if (uiPermissions.LIST_OWN_DEVICES) {
url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username
+ "/count";
url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] +
"/devices/user/" + carbonUser.username + "/count";
} else {
log.error("Access denied for user: " + carbonUser.username);
return -1;
@ -351,7 +352,8 @@ deviceModule = function () {
// };
publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + userName;
var url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/user/" + userName;
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
for (var i = 0; i < responsePayload.length; i++) {

@ -26,7 +26,8 @@ var groupModule = {};
var utility = require("/app/modules/utility.js").utility;
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
var groupServiceEndpoint = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/groups";
var groupServiceEndpoint = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/groups";
var user = session.get(constants.USER_SESSION_KEY);

@ -38,7 +38,7 @@ var operationModule = function () {
}
privateMethods.getOperationsFromFeatures = function (deviceType, operationType) {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType;
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/features/" + deviceType;
var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
var features = responsePayload;
var featureList = [];

@ -16,9 +16,6 @@
* under the License.
*/
var WEB_APP_TITLE = "WSO2 CDM";
var WEB_APP_CONTEXT = "/devicemgt";
var ADMIN_SERVICE_CONTEXT = "/api/device-mgt/v1.0";
var USER_SESSION_KEY = "_UUF_USER";
var UNSPECIFIED = "Unspecified";
var httpURL = "httpURL";
@ -72,12 +69,6 @@ var HTTP_GET = "GET";
var HTTP_POST = "POST";
var HTTP_PUT = "PUT";
var HTTP_DELETE = "DELETE";
var REFERER = "referer"
var GRANT_TYPE_PASSWORD = "password";
var GRANT_TYPE_SAML = "saml";
var MQTT_QUEUE_CONFIG_NAME = "MQTT";
var HTTP_CONFLICT = 409;
var HTTP_CREATED = 201;

@ -18,17 +18,20 @@
var carbonModule = require("carbon");
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var utility = require("/app/modules/utility.js")["utility"];
//noinspection JSUnresolvedFunction Server
var carbonServer = new carbonModule.server.Server({
tenanted: true,
url: devicemgtProps["httpsURL"] + "/admin"
});
application.put("carbonServer", carbonServer);
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var utility = require("/app/modules/utility.js")["utility"];
//var permissions = {
// "/permission/admin/device-mgt/user": ["ui.execute"],
// "/permission/admin/manage/api/subscribe": ["ui.execute"]
//};
var permissions = {
'/permission/admin/device-mgt/user': ['ui.execute'],
'/permission/admin/manage/api/subscribe': ['ui.execute']
};
//userModule.addRole("internal/devicemgt-user", ["admin"], permissions);

@ -152,11 +152,11 @@ var utils = function () {
}
};
publicMethods["getTokenPairByPasswordGrantType"] = function (username, password, encodedClientAppCredentials, scopes) {
publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password, encodedClientAppCredentials, scopes) {
if (!username || !password || !encodedClientAppCredentials || !scopes) {
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " +
"grant type. No username, password, encoded client app credentials or scopes are " +
"found - getTokenPairByPasswordGrantType(a, b, c, d)");
"found - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
return null;
} else {
// calling oauth provider token service endpoint
@ -179,17 +179,17 @@ var utils = function () {
return tokenData;
} else {
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
"by password grant type - getTokenPairByPasswordGrantType(a, b, c, d)");
"by password grant type - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)");
return null;
}
}
};
publicMethods["getTokenPairBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) {
publicMethods["getTokenPairAndScopesBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) {
if (!assertion || !encodedClientAppCredentials || !scopes) {
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml " +
"grant type. No assertion, encoded client app credentials or scopes are " +
"found - getTokenPairBySAMLGrantType(x, y, z)");
"found - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
return null;
} else {
var assertionXML = publicMethods.decode(assertion);
@ -205,7 +205,7 @@ var utils = function () {
var extractedAssertion;
if (assertionStartIndex == -1 || assertionEndIndex == -1) {
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access " +
"token by saml grant type. Issue in assertion format - getTokenPairBySAMLGrantType(x, y, z)");
"token by saml grant type. Issue in assertion format - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
return null;
} else {
extractedAssertion = assertionXML.
@ -232,7 +232,7 @@ var utils = function () {
return tokenData;
} else {
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token " +
"by password grant type - getTokenPairBySAMLGrantType(x, y, z)");
"by password grant type - getTokenPairAndScopesBySAMLGrantType(x, y, z)");
return null;
}
}

@ -53,7 +53,7 @@ var handlers = function () {
stringOfScopes += entry + " ";
});
tokenData = tokenUtil.
getTokenPairByPasswordGrantType(username,
getTokenPairAndScopesByPasswordGrantType(username,
encodeURIComponent(password), encodedClientAppCredentials, stringOfScopes);
if (!tokenData) {
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up " +
@ -90,7 +90,7 @@ var handlers = function () {
var tokenData;
// accessTokenPair will include current access token as well as current refresh token
tokenData = tokenUtil.
getTokenPairBySAMLGrantType(samlToken, encodedClientAppCredentials, "PRODUCTION");
getTokenPairAndScopesBySAMLGrantType(samlToken, encodedClientAppCredentials, "PRODUCTION");
if (!tokenData) {
throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up token " +
"pair by password grant type. Error in token " +

@ -60,21 +60,6 @@ utility = function () {
return getOsgiService("org.wso2.carbon.policy.mgt.core.PolicyManagerService");
};
publicMethods.getIoTServerConfig = function (configName) {
var path = "/config/iot-config.json";
var file = new File(path);
try {
file.open("r");
var content = file.readAll();
} catch (err) {
log.error("Error while reading IoT server config file `" + path + "`: " + err);
} finally {
file.close();
}
var json = parse(content);
return json[configName];
};
publicMethods.getDeviceTypeConfig = function (deviceType) {
var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view");

@ -16,25 +16,25 @@
* under the License.
*/
function onRequest(context) {
function onRequest() {
var constants = require("/app/modules/constants.js");
var user = session.get(constants.USER_SESSION_KEY);
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var permissions = userModule.getUIPermissions();
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"];
var user = session.get(constants["USER_SESSION_KEY"]);
var permissions = userModule.getUIPermissions();
if (!permissions.VIEW_DASHBOARD) {
response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices");
response.sendRedirect(devicemgtProps["appContext"] + "devices");
return;
}
var page = {};
page.permissions = permissions;
page.enrollmentURL = devicemgtProps.enrollmentURL;
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"];
page.device_count = deviceModule.getDevicesCount();
page.group_count = groupModule.getGroupCount();
page.user_count = userModule.getUsers()["content"].length;

@ -31,6 +31,9 @@ function onRequest() {
if (response["status"] == "success") {
page["roles"] = response["content"];
}
var userStores = userModule.getSecondaryUserStores();
page["userStores"] = userStores;
page["charLimit"] = devicemgtProps["usernameLength"];
page["usernameJSRegEx"] = devicemgtProps["userValidationConfig"]["usernameJSRegEx"];
page["usernameHelpMsg"] = devicemgtProps["userValidationConfig"]["usernameHelpMsg"];

@ -1,9 +0,0 @@
{
"grantType": "password urn:ietf:params:oauth:grant-type:saml2-bearer refresh_token",
"saasApp": true,
"tokenScope": "admin",
"requireDynamicClientRegistration": true,
"audience": "https://localhost:9443/oauth2/token",
"assertionConsumerURL": "https://localhost:9443/devicemgt/sso/acs",
"recepientValidationURL": "https://localhost:9443/oauth2/token"
}
Loading…
Cancel
Save