Partial commit for APIM Gateway migration

revert-70aa11f8
mharindu 8 years ago
parent fe447f4325
commit 66ccad65cf

@ -47,7 +47,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
public Response register(@PathParam("tenantDomain") String tenantDomain,
@QueryParam("applicationName") String applicationName) {
String authenticatedTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
if (authenticatedTenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
if (!authenticatedTenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
try {

@ -2,7 +2,7 @@
"appContext" : "/devicemgt/",
"webAgentContext" : "/devicemgt-web-agent/",
"apiContext" : "api",
"httpsURL" : "%https.ip%",
"httpsURL" : "https://localhost:8243",
"httpURL" : "%http.ip%",
"enrollmentDir": "/emm-web-agent/enrollment",
"iOSConfigRoot" : "%https.ip%/ios-enrollment/",

@ -21,6 +21,7 @@ var apiWrapperUtil = function () {
var tokenUtil = require("/app/modules/util.js").util;
var constants = require("/app/modules/constants.js");
var constants = require("/app/modules/constants.js");
var log = new Log("/app/modules/api-wrapper-util.js");
module.refreshToken = function () {
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
@ -31,6 +32,10 @@ var apiWrapperUtil = function () {
module.setupAccessTokenPair = function (type, properties) {
var tokenPair;
var clientData = tokenUtil.getDyanmicCredentials(properties);
log.info(">>>>>>>>>>>>>>>>>>>>");
var jwtToken = tokenUtil.getTokenWithJWTGrantType(clientData);
tokenUtil.getTenantBasedAppCredentials(jwtToken);
log.info("*******************");
var encodedClientKeys = tokenUtil.encode(clientData.clientId + ":" + clientData.clientSecret);
session.put(constants.ENCODED_CLIENT_KEYS_IDENTIFIER, encodedClientKeys);
if (type == constants.GRANT_TYPE_PASSWORD) {

@ -35,7 +35,7 @@ var onFail;
}
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var carbonServer = require("carbon").server;
(new carbonServer.Server({url: devicemgtProps["httpsURL"]}))
(new carbonServer.Server({url: devicemgtProps["adminService"]}))
.login(context.input.username, context.input.password);
};

@ -23,16 +23,15 @@ var util = function () {
var String = Packages.java.lang.String;
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var carbon = require('carbon');
var realmService = carbon.server.osgiService('org.wso2.carbon.user.core.service.RealmService');
var adminUserName = realmService.getBootstrapRealmConfiguration().getAdminUserName();
var constants = require("/app/modules/constants.js");
var adminUser = devicemgtProps["adminUser"];
module.getDyanmicCredentials = function (owner) {
var payload = {
"callbackUrl": devicemgtProps.callBackUrl,
"clientName": "devicemgt",
"tokenScope": "admin",
"owner": adminUserName,
"owner": adminUser,
"applicationType": "webapp",
"grantType": "password refresh_token urn:ietf:params:oauth:grant-type:saml2-bearer",
"saasApp" :true
@ -47,6 +46,7 @@ var util = function () {
var data = parse(xhr.responseText);
clientData.clientId = data.client_id;
clientData.clientSecret = data.client_secret;
} else if (xhr.status == 400) {
throw "Invalid client meta data";
} else {
@ -137,6 +137,7 @@ var util = function () {
}
return tokenPair;
};
module.refreshToken = function (tokenPair, clientData, scope) {
var xhr = new XMLHttpRequest();
var tokenEndpoint = devicemgtProps.idPServer + "/oauth2/token";
@ -163,5 +164,37 @@ var util = function () {
}
return tokenPair;
};
module.getTokenWithJWTGrantType = function (clientData) {
var jwtService = carbon.server.osgiService('org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService');
var jwtClient = jwtService.getJWTClient();
var jwtToken = jwtClient.getAccessToken(clientData.clientId, clientData.clientSecret, adminUser, null);
return jwtToken;
};
module.getTenantBasedAppCredentials = function (token) {
var tenantDomain = "carbon.super";
var applicationName = "webapp_" + tenantDomain;
var xhr = new XMLHttpRequest();
var endpoint = devicemgtProps["adminService"] + "/register/tenants/" + tenantDomain + "?applicationName=" +
applicationName;
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>APIM App Register endpoint: " + endpoint);
xhr.open("POST", endpoint, false);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "X-JWT-Assertion " + token.accessToken);
xhr.send();
var clientData = {};
if (xhr.status == 201) {
var data = parse(xhr.responseText);
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>lllllllllllllllllll: " + stringify(data));
//clientData.clientId = data.client_id;
//clientData.clientSecret = data.client_secret;
} else if (xhr.status == 400) {
throw "Invalid client meta data";
} else {
throw "Error in obtaining client id and secret from APIM";
}
}
return module;
}();

@ -41,7 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* This creates JWT Client for each tenant and implements the JWTClientManagerService interface.
*/
public class JWTClientManagerServiceImpl implements JWTClientManagerService{
public class JWTClientManagerServiceImpl implements JWTClientManagerService {
private static Map<String, JWTClient> jwtClientMap;
private static final Log log = LogFactory.getLog(JWTClientManagerServiceImpl.class);

Loading…
Cancel
Save