|
|
@ -160,37 +160,40 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
|
|
|
|
|
|
|
|
String tenantDomain = MultitenantUtils.getTenantDomain(application.getOwner());
|
|
|
|
String tenantDomain = MultitenantUtils.getTenantDomain(application.getOwner());
|
|
|
|
|
|
|
|
|
|
|
|
String username, password;
|
|
|
|
// String username, password;
|
|
|
|
if (KeyMgtConstants.SUPER_TENANT.equals(tenantDomain)) {
|
|
|
|
// if (KeyMgtConstants.SUPER_TENANT.equals(tenantDomain)) {
|
|
|
|
kmConfig = getKeyManagerConfig();
|
|
|
|
// kmConfig = getKeyManagerConfig();
|
|
|
|
username = kmConfig.getAdminUsername();
|
|
|
|
// username = kmConfig.getAdminUsername();
|
|
|
|
password = kmConfig.getAdminUsername();
|
|
|
|
// password = kmConfig.getAdminPassword();
|
|
|
|
} else {
|
|
|
|
// } else {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
username = getRealmService()
|
|
|
|
// username = getRealmService()
|
|
|
|
.getTenantUserRealm(-1234).getRealmConfiguration()
|
|
|
|
// .getTenantUserRealm(-1234).getRealmConfiguration()
|
|
|
|
.getRealmProperty("reserved_tenant_user_username") + "@" + tenantDomain;
|
|
|
|
// .getRealmProperty("reserved_tenant_user_username") + "@" + tenantDomain;
|
|
|
|
password = getRealmService()
|
|
|
|
// password = getRealmService()
|
|
|
|
.getTenantUserRealm(-1234).getRealmConfiguration()
|
|
|
|
// .getTenantUserRealm(-1234).getRealmConfiguration()
|
|
|
|
.getRealmProperty("reserved_tenant_user_password");
|
|
|
|
// .getRealmProperty("reserved_tenant_user_password");
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
// } catch (UserStoreException e) {
|
|
|
|
msg = "Error while loading user realm configuration";
|
|
|
|
// msg = "Error while loading user realm configuration";
|
|
|
|
log.error(msg);
|
|
|
|
// log.error(msg);
|
|
|
|
throw new KeyMgtException(msg);
|
|
|
|
// throw new KeyMgtException(msg);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
RequestBody appTokenPayload;
|
|
|
|
RequestBody appTokenPayload;
|
|
|
|
switch (tokenRequest.getGrantType()) {
|
|
|
|
switch (tokenRequest.getGrantType()) {
|
|
|
|
case "client_credentials":
|
|
|
|
case "client_credentials":
|
|
|
|
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
|
|
|
|
.add("grant_type", "client_credentials")
|
|
|
|
|
|
|
|
.add("scope", tokenRequest.getScope()).build();
|
|
|
|
|
|
|
|
break;
|
|
|
|
case "password":
|
|
|
|
case "password":
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
.add("grant_type", "password")
|
|
|
|
.add("grant_type", "password")
|
|
|
|
.add("username", username)
|
|
|
|
.add("username", tokenRequest.getUsername())
|
|
|
|
.add("password", password)
|
|
|
|
.add("password", tokenRequest.getPassword())
|
|
|
|
.add("scope", tokenRequest.getScope()).build();
|
|
|
|
.add("scope", tokenRequest.getScope()).build();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "refresh_token":
|
|
|
|
case "refresh_token":
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
appTokenPayload = new FormBody.Builder()
|
|
|
|
.add("grant_type", "refresh_token")
|
|
|
|
.add("grant_type", "refresh_token")
|
|
|
@ -239,12 +242,19 @@ public class KeyMgtServiceImpl implements KeyMgtService {
|
|
|
|
.getTenantManager().getTenantId(tenantDomain);
|
|
|
|
.getTenantManager().getTenantId(tenantDomain);
|
|
|
|
accessToken = tenantId + "_" + responseObj.getString("access_token");
|
|
|
|
accessToken = tenantId + "_" + responseObj.getString("access_token");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new TokenResponse(accessToken,
|
|
|
|
|
|
|
|
responseObj.getString("refresh_token"),
|
|
|
|
|
|
|
|
responseObj.getString("scope"),
|
|
|
|
|
|
|
|
responseObj.getString("token_type"),
|
|
|
|
|
|
|
|
responseObj.getInt("expires_in"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tokenRequest.getGrantType().equals("client_credentials")) {
|
|
|
|
|
|
|
|
return new TokenResponse(accessToken,
|
|
|
|
|
|
|
|
responseObj.getString("scope"),
|
|
|
|
|
|
|
|
responseObj.getString("token_type"),
|
|
|
|
|
|
|
|
responseObj.getInt("expires_in"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return new TokenResponse(accessToken,
|
|
|
|
|
|
|
|
responseObj.getString("refresh_token"),
|
|
|
|
|
|
|
|
responseObj.getString("scope"),
|
|
|
|
|
|
|
|
responseObj.getString("token_type"),
|
|
|
|
|
|
|
|
responseObj.getInt("expires_in"));
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (APIManagementException e) {
|
|
|
|
} catch (APIManagementException e) {
|
|
|
|
msg = "Error occurred while retrieving application";
|
|
|
|
msg = "Error occurred while retrieving application";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|