Search in sources :

Example 6 with MultiEnvironmentOverview

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo) ArrayList(java.util.ArrayList) APIMAppConfigurations(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations) JsonObject(com.google.gson.JsonObject) MultiEnvironmentOverview(org.wso2.carbon.apimgt.core.configuration.models.MultiEnvironmentOverview)

Aggregations

MultiEnvironmentOverview (org.wso2.carbon.apimgt.core.configuration.models.MultiEnvironmentOverview)6 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 Test (org.junit.Test)4 KeyManager (org.wso2.carbon.apimgt.core.api.KeyManager)4 APIMConfigurationService (org.wso2.carbon.apimgt.core.configuration.APIMConfigurationService)4 EnvironmentConfigurations (org.wso2.carbon.apimgt.core.configuration.models.EnvironmentConfigurations)4 SystemApplicationDao (org.wso2.carbon.apimgt.core.dao.SystemApplicationDao)4 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)4 APIMAppConfigurationService (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.APIMAppConfigurationService)4 JsonObject (com.google.gson.JsonObject)3 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)3 AccessTokenInfo (org.wso2.carbon.apimgt.core.models.AccessTokenInfo)3 ArrayList (java.util.ArrayList)1 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)1 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)1 AccessTokenRequest (org.wso2.carbon.apimgt.core.models.AccessTokenRequest)1 AuthResponseBean (org.wso2.carbon.apimgt.rest.api.authenticator.utils.bean.AuthResponseBean)1