Search in sources :

Example 1 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-apimgt by wso2.

the class RegistrationServiceImpl method createApplication.

/**
 * Create a new client application
 *
 * @param appRequest OAuthAppRequest object with client's payload content
 * @return created Application
 * @throws APIKeyMgtException if failed to create the a new application
 */
private OAuthApplicationInfo createApplication(String applicationName, OAuthAppRequest appRequest, String grantType) throws APIManagementException {
    String userName;
    OAuthApplicationInfo applicationInfo = appRequest.getOAuthApplicationInfo();
    String appName = applicationInfo.getClientName();
    String userId = (String) applicationInfo.getParameter(OAUTH_CLIENT_USERNAME);
    boolean isTenantFlowStarted = false;
    if (userId == null || userId.isEmpty()) {
        return null;
    }
    userName = MultitenantUtils.getTenantAwareUsername(userId);
    String tenantDomain = MultitenantUtils.getTenantDomain(userId);
    try {
        if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            isTenantFlowStarted = true;
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName);
        }
        // Creating the service provider
        ServiceProvider serviceProvider = new ServiceProvider();
        serviceProvider.setApplicationName(applicationName);
        serviceProvider.setDescription("Service Provider for application " + appName);
        serviceProvider.setSaasApp(applicationInfo.getIsSaasApplication());
        ServiceProviderProperty[] serviceProviderProperties = new ServiceProviderProperty[4];
        ServiceProviderProperty serviceProviderProperty = new ServiceProviderProperty();
        serviceProviderProperty.setName(APP_DISPLAY_NAME);
        serviceProviderProperty.setValue(applicationName);
        serviceProviderProperties[0] = serviceProviderProperty;
        ServiceProviderProperty tokenTypeProviderProperty = new ServiceProviderProperty();
        tokenTypeProviderProperty.setName(APIConstants.APP_TOKEN_TYPE);
        tokenTypeProviderProperty.setValue(applicationInfo.getTokenType());
        serviceProviderProperties[1] = tokenTypeProviderProperty;
        ServiceProviderProperty consentProperty = new ServiceProviderProperty();
        consentProperty.setDisplayName(APIConstants.APP_SKIP_CONSENT_DISPLAY);
        consentProperty.setName(APIConstants.APP_SKIP_CONSENT_NAME);
        consentProperty.setValue(APIConstants.APP_SKIP_CONSENT_VALUE);
        serviceProviderProperties[2] = consentProperty;
        ServiceProviderProperty logoutConsentProperty = new ServiceProviderProperty();
        logoutConsentProperty.setDisplayName(APIConstants.APP_SKIP_LOGOUT_CONSENT_DISPLAY);
        logoutConsentProperty.setName(APIConstants.APP_SKIP_LOGOUT_CONSENT_NAME);
        logoutConsentProperty.setValue(APIConstants.APP_SKIP_LOGOUT_CONSENT_VALUE);
        serviceProviderProperties[3] = logoutConsentProperty;
        serviceProvider.setSpProperties(serviceProviderProperties);
        ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
        appMgtService.createApplication(serviceProvider, tenantDomain, userName);
        // Retrieving the created service provider
        ServiceProvider createdServiceProvider = appMgtService.getApplicationExcludingFileBasedSPs(applicationName, tenantDomain);
        if (createdServiceProvider == null) {
            throw new APIManagementException("Error occurred while creating Service Provider " + "Application" + appName);
        }
        // creating the OAuth app
        OAuthConsumerAppDTO createdOauthApp = this.createOAuthApp(applicationName, applicationInfo, grantType, userName);
        // Set the OAuthApp in InboundAuthenticationConfig
        InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
        InboundAuthenticationRequestConfig[] inboundAuthenticationRequestConfigs = new InboundAuthenticationRequestConfig[1];
        InboundAuthenticationRequestConfig inboundAuthenticationRequestConfig = new InboundAuthenticationRequestConfig();
        String oAuthType = APIConstants.SWAGGER_12_OAUTH2;
        inboundAuthenticationRequestConfig.setInboundAuthType(oAuthType);
        inboundAuthenticationRequestConfig.setInboundAuthKey(createdOauthApp.getOauthConsumerKey());
        String oauthConsumerSecret = createdOauthApp.getOauthConsumerSecret();
        if (oauthConsumerSecret != null && !oauthConsumerSecret.isEmpty()) {
            Property property = new Property();
            property.setName(ApplicationConstants.INBOUNT_AUTH_CONSUMER_SECRET);
            property.setValue(oauthConsumerSecret);
            Property[] properties = { property };
            inboundAuthenticationRequestConfig.setProperties(properties);
        }
        inboundAuthenticationRequestConfigs[0] = inboundAuthenticationRequestConfig;
        inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(inboundAuthenticationRequestConfigs);
        createdServiceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
        // Setting the SaasApplication attribute to created service provider
        createdServiceProvider.setSaasApp(applicationInfo.getIsSaasApplication());
        createdServiceProvider.setSpProperties(serviceProviderProperties);
        // Updating the service provider with Inbound Authentication Configs and SaasApplication
        appMgtService.updateApplication(createdServiceProvider, tenantDomain, userName);
        Map<String, String> valueMap = new HashMap<String, String>();
        valueMap.put(OAUTH_REDIRECT_URIS, createdOauthApp.getCallbackUrl());
        valueMap.put(OAUTH_CLIENT_NAME, createdOauthApp.getApplicationName());
        valueMap.put(OAUTH_CLIENT_GRANT, createdOauthApp.getGrantTypes());
        return this.fromAppDTOToApplicationInfo(createdOauthApp.getOauthConsumerKey(), applicationName, createdOauthApp.getCallbackUrl(), createdOauthApp.getOauthConsumerSecret(), createdServiceProvider.isSaasApp(), userId, valueMap);
    } catch (IdentityApplicationManagementException e) {
        log.error("Error occurred while creating the client application " + appName, e);
    } finally {
        if (isTenantFlowStarted) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow();
        }
    }
    return null;
}
Also used : InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 2 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method addApplicationCertificateReferenceAsServiceProviderProperty.

/**
 * Add the given certificate ID as a property of the given service provider object.
 *
 * @param serviceProvider
 * @param newlyAddedCertificateID
 */
private void addApplicationCertificateReferenceAsServiceProviderProperty(ServiceProvider serviceProvider, int newlyAddedCertificateID) {
    ServiceProviderProperty[] serviceProviderProperties = serviceProvider.getSpProperties();
    ServiceProviderProperty[] newServiceProviderProperties;
    if (serviceProviderProperties != null) {
        newServiceProviderProperties = new ServiceProviderProperty[serviceProviderProperties.length + 1];
        for (int i = 0; i < serviceProviderProperties.length; i++) {
            newServiceProviderProperties[i] = serviceProviderProperties[i];
        }
    } else {
        newServiceProviderProperties = new ServiceProviderProperty[1];
    }
    ServiceProviderProperty propertyForCertificate = new ServiceProviderProperty();
    propertyForCertificate.setDisplayName("CERTIFICATE");
    propertyForCertificate.setName("CERTIFICATE");
    propertyForCertificate.setValue(String.valueOf(newlyAddedCertificateID));
    newServiceProviderProperties[newServiceProviderProperties.length - 1] = propertyForCertificate;
    serviceProvider.setSpProperties(newServiceProviderProperties);
}
Also used : ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 3 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method updateServiceProviderProperties.

/**
 * Update Service provider properties
 *
 * @param dbConnection
 * @param spId
 * @param properties
 * @throws SQLException
 */
private void updateServiceProviderProperties(Connection dbConnection, int spId, List<ServiceProviderProperty> properties, int tenantId) throws SQLException {
    PreparedStatement prepStmt = null;
    try {
        prepStmt = dbConnection.prepareStatement(DELETE_SP_METADATA);
        prepStmt.setInt(1, spId);
        prepStmt.executeUpdate();
        addServiceProviderProperties(dbConnection, spId, properties, tenantId);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)

Example 4 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method buildJwksProperty.

private ServiceProviderProperty buildJwksProperty(ServiceProvider sp) {
    ServiceProviderProperty jwksUri = new ServiceProviderProperty();
    jwksUri.setName(JWKS_URI_SP_PROPERTY_NAME);
    jwksUri.setDisplayName(JWKS_URI_SP_PROPERTY_NAME);
    jwksUri.setValue(StringUtils.isNotBlank(sp.getJwksUri()) ? sp.getJwksUri() : StringUtils.EMPTY);
    return jwksUri;
}
Also used : ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 5 with ServiceProviderProperty

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method buildSkipLogoutConsentProperty.

private ServiceProviderProperty buildSkipLogoutConsentProperty(ServiceProvider sp) {
    ServiceProviderProperty skipLogoutConsentProperty = new ServiceProviderProperty();
    skipLogoutConsentProperty.setName(SKIP_LOGOUT_CONSENT);
    skipLogoutConsentProperty.setDisplayName(SKIP_LOGOUT_CONSENT_DISPLAY_NAME);
    skipLogoutConsentProperty.setValue(String.valueOf(sp.getLocalAndOutBoundAuthenticationConfig().isSkipLogoutConsent()));
    return skipLogoutConsentProperty;
}
Also used : ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Aggregations

ServiceProviderProperty (org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)24 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)8 PreparedStatement (java.sql.PreparedStatement)7 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)7 ArrayList (java.util.ArrayList)6 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)3 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)3 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)3 IOException (java.io.IOException)2 List (java.util.List)2 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)2 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)2 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)2 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)2 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)2 Property (org.wso2.carbon.identity.application.common.model.Property)2 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)2