|
|
@ -77,7 +77,7 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
String subTenantUserUsername, subTenantUserPassword, keyManagerName, msg = null;
|
|
|
|
String subTenantUserUsername, subTenantUserPassword, keyManagerName, msg = null;
|
|
|
|
|
|
|
|
|
|
|
|
public DCRResponse dynamicClientRegistration(String clientName, String owner, String grantTypes, String callBackUrl,
|
|
|
|
public DCRResponse dynamicClientRegistration(String clientName, String owner, String grantTypes, String callBackUrl,
|
|
|
|
String[] tags, boolean isSaasApp) throws KeyMgtException {
|
|
|
|
String[] tags, boolean isSaasApp, int validityPeriod) throws KeyMgtException {
|
|
|
|
|
|
|
|
|
|
|
|
if (owner == null) {
|
|
|
|
if (owner == null) {
|
|
|
|
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
@ -105,13 +105,13 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
kmConfig = getKeyManagerConfig();
|
|
|
|
kmConfig = getKeyManagerConfig();
|
|
|
|
|
|
|
|
|
|
|
|
if (KeyMgtConstants.SUPER_TENANT.equals(tenantDomain)) {
|
|
|
|
if (KeyMgtConstants.SUPER_TENANT.equals(tenantDomain)) {
|
|
|
|
OAuthApplication dcrApplication = createOauthApplication(clientName, kmConfig.getAdminUsername(), tags);
|
|
|
|
OAuthApplication dcrApplication = createOauthApplication(clientName, kmConfig.getAdminUsername(), tags, validityPeriod);
|
|
|
|
return new DCRResponse(dcrApplication.getClientId(), dcrApplication.getClientSecret());
|
|
|
|
return new DCRResponse(dcrApplication.getClientId(), dcrApplication.getClientSecret());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// super-tenant admin dcr and token generation
|
|
|
|
// super-tenant admin dcr and token generation
|
|
|
|
OAuthApplication superTenantOauthApp = createOauthApplication(
|
|
|
|
OAuthApplication superTenantOauthApp = createOauthApplication(
|
|
|
|
KeyMgtConstants.RESERVED_OAUTH_APP_NAME_PREFIX + KeyMgtConstants.SUPER_TENANT,
|
|
|
|
KeyMgtConstants.RESERVED_OAUTH_APP_NAME_PREFIX + KeyMgtConstants.SUPER_TENANT,
|
|
|
|
kmConfig.getAdminUsername(), null);
|
|
|
|
kmConfig.getAdminUsername(), null, validityPeriod);
|
|
|
|
String superAdminAccessToken = createAccessToken(superTenantOauthApp);
|
|
|
|
String superAdminAccessToken = createAccessToken(superTenantOauthApp);
|
|
|
|
|
|
|
|
|
|
|
|
// create new key manager for the tenant, under super-tenant space
|
|
|
|
// create new key manager for the tenant, under super-tenant space
|
|
|
@ -133,7 +133,7 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
createUserIfNotExists(subTenantUserUsername, subTenantUserPassword);
|
|
|
|
createUserIfNotExists(subTenantUserUsername, subTenantUserPassword);
|
|
|
|
|
|
|
|
|
|
|
|
// DCR for the requesting user
|
|
|
|
// DCR for the requesting user
|
|
|
|
OAuthApplication dcrApplication = createOauthApplication(clientName, owner, tags);
|
|
|
|
OAuthApplication dcrApplication = createOauthApplication(clientName, owner, tags, validityPeriod);
|
|
|
|
String requestingUserAccessToken = createAccessToken(dcrApplication);
|
|
|
|
String requestingUserAccessToken = createAccessToken(dcrApplication);
|
|
|
|
|
|
|
|
|
|
|
|
// get application id
|
|
|
|
// get application id
|
|
|
@ -167,7 +167,8 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
case "client_credentials":
|
|
|
|
case "client_credentials":
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
.add("grant_type", "client_credentials")
|
|
|
|
.add("grant_type", "client_credentials")
|
|
|
|
.add("scope", tokenRequest.getScope()).build();
|
|
|
|
.add("scope", tokenRequest.getScope())
|
|
|
|
|
|
|
|
.add("validityPeriod", String.valueOf(tokenRequest.getValidityPeriod())).build();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "password":
|
|
|
|
case "password":
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
@ -322,8 +323,8 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
* @return @{@link OAuthApplication} OAuth application object
|
|
|
|
* @return @{@link OAuthApplication} OAuth application object
|
|
|
|
* @throws KeyMgtException if any error occurs while creating response object
|
|
|
|
* @throws KeyMgtException if any error occurs while creating response object
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private OAuthApplication createOauthApplication (String clientName, String owner, String[] tags) throws KeyMgtException {
|
|
|
|
private OAuthApplication createOauthApplication (String clientName, String owner, String[] tags, int validityPeriod) throws KeyMgtException {
|
|
|
|
String oauthAppCreationPayloadStr = createOauthAppCreationPayload(clientName, owner, tags);
|
|
|
|
String oauthAppCreationPayloadStr = createOauthAppCreationPayload(clientName, owner, tags, validityPeriod);
|
|
|
|
RequestBody oauthAppCreationPayload = RequestBody.Companion.create(oauthAppCreationPayloadStr, JSON);
|
|
|
|
RequestBody oauthAppCreationPayload = RequestBody.Companion.create(oauthAppCreationPayloadStr, JSON);
|
|
|
|
kmConfig = getKeyManagerConfig();
|
|
|
|
kmConfig = getKeyManagerConfig();
|
|
|
|
String dcrEndpoint = kmConfig.getServerUrl() + KeyMgtConstants.DCR_ENDPOINT;
|
|
|
|
String dcrEndpoint = kmConfig.getServerUrl() + KeyMgtConstants.DCR_ENDPOINT;
|
|
|
@ -442,11 +443,12 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String createOauthAppCreationPayload(String clientName, String owner, String[] tags) {
|
|
|
|
private String createOauthAppCreationPayload(String clientName, String owner, String[] tags, int validityPeriod) {
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
jsonObject.put("applicationName", clientName);
|
|
|
|
jsonObject.put("applicationName", clientName);
|
|
|
|
jsonObject.put("username", owner);
|
|
|
|
jsonObject.put("username", owner);
|
|
|
|
jsonObject.put("tags", tags);
|
|
|
|
jsonObject.put("tags", tags);
|
|
|
|
|
|
|
|
jsonObject.put("validityPeriod", validityPeriod);
|
|
|
|
return jsonObject.toString();
|
|
|
|
return jsonObject.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|