use of org.wso2.carbon.apimgt.core.configuration.models.MultiEnvironmentOverview in project carbon-apimgt by wso2.
the class AuthenticatorService method getAuthenticationConfigurations.
/**
* This method returns the details of a DCR application.
*
* @param appName Name of the application to be created
* @return oAuthData - A JsonObject with DCR application details, scopes, auth endpoint, and SSO is enabled or not
* @throws APIManagementException When creating DCR application fails
*/
public JsonObject getAuthenticationConfigurations(String appName) throws APIManagementException {
JsonObject oAuthData = new JsonObject();
MultiEnvironmentOverview multiEnvironmentOverviewConfigs = apimConfigurationService.getEnvironmentConfigurations().getMultiEnvironmentOverview();
boolean isMultiEnvironmentOverviewEnabled = multiEnvironmentOverviewConfigs.isEnabled();
List<String> grantTypes = new ArrayList<>();
grantTypes.add(KeyManagerConstants.PASSWORD_GRANT_TYPE);
grantTypes.add(KeyManagerConstants.AUTHORIZATION_CODE_GRANT_TYPE);
grantTypes.add(KeyManagerConstants.REFRESH_GRANT_TYPE);
if (isMultiEnvironmentOverviewEnabled) {
grantTypes.add(KeyManagerConstants.JWT_GRANT_TYPE);
}
APIMAppConfigurations appConfigs = apimAppConfigurationService.getApimAppConfigurations();
String callBackURL = appConfigs.getApimBaseUrl() + AuthenticatorConstants.AUTHORIZATION_CODE_CALLBACK_URL + appName;
// Get scopes of the application
String scopes = getApplicationScopes(appName);
log.debug("Set scopes for {} application using swagger definition.", appName);
OAuthApplicationInfo oAuthApplicationInfo;
try {
oAuthApplicationInfo = createDCRApplication(appName, callBackURL, grantTypes);
if (oAuthApplicationInfo != null) {
log.debug("Created DCR Application successfully for {}.", appName);
String oAuthApplicationClientId = oAuthApplicationInfo.getClientId();
String oAuthApplicationCallBackURL = oAuthApplicationInfo.getCallBackURL();
oAuthData.addProperty(KeyManagerConstants.OAUTH_CLIENT_ID, oAuthApplicationClientId);
oAuthData.addProperty(KeyManagerConstants.OAUTH_CALLBACK_URIS, oAuthApplicationCallBackURL);
oAuthData.addProperty(KeyManagerConstants.TOKEN_SCOPES, scopes);
oAuthData.addProperty(KeyManagerConstants.AUTHORIZATION_ENDPOINT, appConfigs.getAuthorizationEndpoint());
oAuthData.addProperty(AuthenticatorConstants.SSO_ENABLED, appConfigs.isSsoEnabled());
oAuthData.addProperty(AuthenticatorConstants.MULTI_ENVIRONMENT_OVERVIEW_ENABLED, isMultiEnvironmentOverviewEnabled);
} else {
String errorMsg = "No information available in OAuth application.";
log.error(errorMsg, ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
}
} catch (APIManagementException e) {
String errorMsg = "Error while creating the keys for OAuth application : " + appName;
log.error(errorMsg, e, ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
throw new APIManagementException(errorMsg, e, ExceptionCodes.OAUTH2_APP_CREATION_FAILED);
}
return oAuthData;
}
Aggregations