Java Code Examples for org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig#getInboundAuthType()

The following examples show how to use org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig#getInboundAuthType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerApplicationManagementService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
private void doRollback(String applicationId, InboundAuthenticationRequestConfig updatedInbound) {

        ServiceProvider serviceProvider = getServiceProvider(applicationId);
        // Current inbound key. This will give us an idea whether updatedInbound was newly added or not.
        String previousInboundKey = getInboundAuthKey(serviceProvider, updatedInbound.getInboundAuthType());
        String attemptedInboundKeyForUpdate = updatedInbound.getInboundAuthKey();
        if (!StringUtils.equals(previousInboundKey, attemptedInboundKeyForUpdate)) {
            // This means the application was updated with a newly created inbound. So the updated inbound details
            // could have been created before the update. Attempt to rollback by deleting any inbound configs created.
            if (log.isDebugEnabled()) {
                String inboundType = updatedInbound.getInboundAuthType();
                log.debug("Removing inbound data related to inbound type: " + inboundType + " of application: "
                        + applicationId + " as part of rollback.");
            }
            rollbackInbound(updatedInbound);
        }
    }
 
Example 2
Source File: InboundFunctions.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
public static void rollbackInbound(InboundAuthenticationRequestConfig inbound) {

        switch (inbound.getInboundAuthType()) {
            case FrameworkConstants.StandardInboundProtocols.SAML2:
                SAMLInboundFunctions.deleteSAMLServiceProvider(inbound);
                break;
            case FrameworkConstants.StandardInboundProtocols.OAUTH2:
                OAuthInboundFunctions.deleteOAuthInbound(inbound);
                break;
            case FrameworkConstants.StandardInboundProtocols.WS_TRUST:
                WSTrustInboundFunctions.deleteWSTrustConfiguration(inbound);
                break;
            default:
                // No rollbacks required for other inbounds.
                break;
        }
    }
 
Example 3
Source File: ApplicationMgtValidator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Validate whether the configured inbound authentication key is already being used by another application.
 *
 * @param inboundConfig Inbound authentication request configuration.
 * @param appId         Application ID.
 * @param tenantDomain  Application tenant domain.
 * @throws IdentityApplicationManagementException IdentityApplicationManagementException.
 */
private void validateInboundAuthKey(InboundAuthenticationRequestConfig inboundConfig, int appId, String
        tenantDomain) throws IdentityApplicationManagementException {

    if (inboundConfig == null) {
        return;
    }

    /*
     * We need to directly retrieve the application from DB since {@link ServiceProviderByInboundAuthCache} cache
     * can have inconsistent applications stored against the <inbound-auth-key, inbound-auth-type, tenant-domain>
     * cache key which is not unique.
     */
    ApplicationDAO applicationDAO = new ApplicationDAOImpl();
    String existingAppName = applicationDAO.getServiceProviderNameByClientId
            (inboundConfig.getInboundAuthKey(), inboundConfig.getInboundAuthType(), CarbonContext
                    .getThreadLocalCarbonContext().getTenantDomain());

    if (StringUtils.isBlank(existingAppName)) {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find application name for the inbound auth key: " + inboundConfig
                    .getInboundAuthKey() + " of inbound auth type: " + inboundConfig.getInboundAuthType());
        }
        return;
    }
    ServiceProvider existingApp = applicationDAO.getApplication(existingAppName, tenantDomain);
    if (existingApp != null && existingApp.getApplicationID() != appId) {
        String msg = "Inbound key: '" + inboundConfig.getInboundAuthKey() + "' of inbound auth type: '" +
                inboundConfig.getInboundAuthType() + "' is already configured for the application :'" +
                existingApp.getApplicationName() + "'";
        /*
         * Since this is a conflict scenario, we need to use a different error code. Hence throwing an
         * 'IdentityApplicationManagementClientException' here with the correct error code.
         */
        throw buildClientException(IdentityApplicationConstants.Error.INBOUND_KEY_ALREADY_EXISTS, msg);
    }
}
 
Example 4
Source File: CacheBackedApplicationDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void clearAppCacheByInboundKey(ServiceProvider serviceProvider, String tenantDomain) {

        if (serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider
                .getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
            InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig()
                    .getInboundAuthenticationRequestConfigs();
            for (InboundAuthenticationRequestConfig config : configs) {
                if (config.getInboundAuthKey() != null) {
                    ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(
                            config.getInboundAuthKey(), config.getInboundAuthType(), tenantDomain);
                    appCacheByInboundAuth.clearCacheEntry(clientKey);
                }
            }
        }
    }
 
Example 5
Source File: CacheBackedApplicationDAO.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
private void addToCache(ServiceProvider serviceProvider, String tenantDomain) throws
        IdentityApplicationManagementException {

    if (log.isDebugEnabled()) {
        log.debug("Add cache for the application " + serviceProvider.getApplicationName() + "@" + tenantDomain);
    }
    try {
        ApplicationMgtUtil.startTenantFlow(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        IdentityServiceProviderCacheKey nameKey = new IdentityServiceProviderCacheKey(serviceProvider
                .getApplicationName(), tenantDomain);
        IdentityServiceProviderCacheEntry nameEntry = new IdentityServiceProviderCacheEntry(serviceProvider);
        appCacheByName.addToCache(nameKey, nameEntry);

        ServiceProviderIDCacheKey idKey = new ServiceProviderIDCacheKey(serviceProvider.getApplicationID());
        ServiceProviderIDCacheEntry idEntry = new ServiceProviderIDCacheEntry(serviceProvider);
        appCacheByID.addToCache(idKey, idEntry);

        ServiceProviderResourceIdCacheKey resourceIdCacheKey =
                new ServiceProviderResourceIdCacheKey(serviceProvider.getApplicationResourceId());
        ServiceProviderResourceIdCacheEntry entry = new ServiceProviderResourceIdCacheEntry(serviceProvider);
        appCacheByResourceId.addToCache(resourceIdCacheKey, entry);

        if (serviceProvider.getInboundAuthenticationConfig() != null && serviceProvider
                .getInboundAuthenticationConfig().getInboundAuthenticationRequestConfigs() != null) {
            InboundAuthenticationRequestConfig[] configs = serviceProvider.getInboundAuthenticationConfig()
                    .getInboundAuthenticationRequestConfigs();
            for (InboundAuthenticationRequestConfig config : configs) {
                if (config.getInboundAuthKey() != null) {
                    ServiceProviderCacheInboundAuthKey clientKey = new ServiceProviderCacheInboundAuthKey(
                            config.getInboundAuthKey(), config.getInboundAuthType(), tenantDomain);
                    ServiceProviderCacheInboundAuthEntry clientEntry = new ServiceProviderCacheInboundAuthEntry(
                            serviceProvider.getApplicationName(), tenantDomain);
                    appCacheByInboundAuth.addToCache(clientKey, clientEntry);
                }
            }
        }
    } finally {
        ApplicationMgtUtil.endTenantFlow();
    }
}
 
Example 6
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param applicationId
 * @param inBoundAuthenticationConfig
 * @param connection
 * @throws SQLException
 */
private void updateInboundAuthRequestConfiguration(int applicationId,
                                                   InboundAuthenticationConfig inBoundAuthenticationConfig, Connection connection)
        throws SQLException {
    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    PreparedStatement inboundAuthReqConfigPrepStmt = null;

    try {
        if (inBoundAuthenticationConfig == null
                || inBoundAuthenticationConfig.getInboundAuthenticationRequestConfigs() == null
                || inBoundAuthenticationConfig.getInboundAuthenticationRequestConfigs().length == 0) {
            // no in-bound authentication requests defined.
            return;
        }

        inboundAuthReqConfigPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.STORE_CLIENT_INFO);
        InboundAuthenticationRequestConfig[] authRequests = inBoundAuthenticationConfig
                .getInboundAuthenticationRequestConfigs();

        for (InboundAuthenticationRequestConfig authRequest : authRequests) {
            if (authRequest == null || authRequest.getInboundAuthKey() == null
                    || authRequest.getInboundAuthType() == null) {
                log.warn("Invalid in-bound authentication request");
                // not a valid authentication request. Must have client and a type.
                continue;
            }
            // TENANT_ID, INBOUND_AUTH_KEY,INBOUND_AUTH_TYPE,PROP_NAME, PROP_VALUE, APP_ID

            Property[] properties = authRequest.getProperties();

            if (properties != null && properties.length > 0) {
                for (Property prop : properties) {
                    inboundAuthReqConfigPrepStmt.setInt(1, tenantID);
                    inboundAuthReqConfigPrepStmt.setString(2,authRequest.getInboundAuthKey());
                    inboundAuthReqConfigPrepStmt.setString(3,authRequest.getInboundAuthType());
                    inboundAuthReqConfigPrepStmt.setString(4,prop.getName());
                    inboundAuthReqConfigPrepStmt.setString(5,prop.getValue());
                    inboundAuthReqConfigPrepStmt.setInt(6, applicationId);
                    inboundAuthReqConfigPrepStmt.addBatch();
                }
            } else {
                inboundAuthReqConfigPrepStmt.setInt(1, tenantID);
                inboundAuthReqConfigPrepStmt.setString(2,authRequest.getInboundAuthKey());
                inboundAuthReqConfigPrepStmt.setString(3,authRequest.getInboundAuthType());
                inboundAuthReqConfigPrepStmt.setString(4, null);
                inboundAuthReqConfigPrepStmt.setString(5, null);
                inboundAuthReqConfigPrepStmt.setInt(6, applicationId);
                inboundAuthReqConfigPrepStmt.addBatch();
            }

            if (log.isDebugEnabled()) {
                log.debug("Updating inbound authentication request configuration of the application "
                        + applicationId
                        + "inbound auth key: "
                        + authRequest.getInboundAuthKey()
                        + " inbound auth type: "
                        + authRequest.getInboundAuthType());
            }
        }

        inboundAuthReqConfigPrepStmt.executeBatch();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(inboundAuthReqConfigPrepStmt);
    }
}