org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig Java Examples

The following examples show how to use org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig. 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 deleteInbound(String applicationId, String inboundType) {

        ServiceProvider appToUpdate;
        try {
            appToUpdate = cloneApplication(applicationId);
        } catch (APIError e) {
            if (ErrorMessage.APPLICATION_NOT_FOUND.getCode().equals(e.getCode())) {
                // Ignoring the delete operation and return 204 response code, since the resource does not exist.
                return;
            }
            throw e;
        }
        InboundAuthenticationConfig inboundAuthConfig = appToUpdate.getInboundAuthenticationConfig();

        if (ArrayUtils.isNotEmpty(inboundAuthConfig.getInboundAuthenticationRequestConfigs())) {
            // Remove the deleted inbound type by filtering it out of the available inbounds and doing an update.
            InboundAuthenticationRequestConfig[] filteredInbounds =
                    Arrays.stream(inboundAuthConfig.getInboundAuthenticationRequestConfigs())
                            .filter(inbound -> !StringUtils.equals(inboundType, inbound.getInboundAuthType()))
                            .toArray(InboundAuthenticationRequestConfig[]::new);

            appToUpdate.getInboundAuthenticationConfig().setInboundAuthenticationRequestConfigs(filteredInbounds);
            updateServiceProvider(applicationId, appToUpdate);
        }
    }
 
Example #2
Source File: InboundAuthConfigToApiModel.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
@Override
public List<InboundProtocolListItem> apply(ServiceProvider application) {

    String applicationId = application.getApplicationResourceId();
    InboundAuthenticationConfig inboundAuthConfig = application.getInboundAuthenticationConfig();

    if (inboundAuthConfig != null) {
        if (ArrayUtils.isNotEmpty(inboundAuthConfig.getInboundAuthenticationRequestConfigs())) {

            List<InboundProtocolListItem> inboundProtocolListItems = new ArrayList<>();
            Arrays.stream(inboundAuthConfig.getInboundAuthenticationRequestConfigs()).forEach(
                    inbound -> inboundProtocolListItems.add(buildInboundProtocolListItem(applicationId, inbound)));

            return inboundProtocolListItems;
        }
    }

    return Collections.emptyList();
}
 
Example #3
Source File: InboundFunctions.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * Extract the inbound configuration of a particular type from an application and converts it to the API model.
 *
 * @param application
 * @param inboundType Inbound Type
 * @return
 */
public static InboundAuthenticationRequestConfig getInboundAuthenticationRequestConfig(ServiceProvider application,
                                                                                       String inboundType) {

    InboundAuthenticationConfig inboundAuthConfig = application.getInboundAuthenticationConfig();
    if (inboundAuthConfig != null) {
        InboundAuthenticationRequestConfig[] inbounds = inboundAuthConfig.getInboundAuthenticationRequestConfigs();
        if (inbounds != null) {
            return Arrays.stream(inbounds)
                    .filter(inbound -> inboundType.equals(inbound.getInboundAuthType()))
                    .findAny()
                    .orElse(null);
        }
    }

    return null;
}
 
Example #4
Source File: InboundFunctions.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
public static String getInboundAuthKey(ServiceProvider application,
                                       String inboundType) {

    InboundAuthenticationConfig inboundAuthConfig = application.getInboundAuthenticationConfig();
    if (inboundAuthConfig != null) {
        InboundAuthenticationRequestConfig[] inbounds = inboundAuthConfig.getInboundAuthenticationRequestConfigs();
        if (inbounds != null) {
            return Arrays.stream(inbounds)
                    .filter(inbound -> inboundType.equals(inbound.getInboundAuthType()))
                    .findAny()
                    .map(InboundAuthenticationRequestConfig::getInboundAuthKey)
                    .orElse(null);
        }
    }

    return null;
}
 
Example #5
Source File: InboundFunctions.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
public static void updateOrInsertInbound(ServiceProvider application,
                                         InboundAuthenticationRequestConfig newInbound) {

    InboundAuthenticationConfig inboundAuthConfig = application.getInboundAuthenticationConfig();
    if (inboundAuthConfig != null) {

        InboundAuthenticationRequestConfig[] inbounds = inboundAuthConfig.getInboundAuthenticationRequestConfigs();
        if (inbounds != null) {
            Map<String, InboundAuthenticationRequestConfig> inboundAuthConfigs =
                    Arrays.stream(inbounds).collect(
                            Collectors.toMap(InboundAuthenticationRequestConfig::getInboundAuthType,
                                    Function.identity()));

            inboundAuthConfigs.put(newInbound.getInboundAuthType(), newInbound);
            inboundAuthConfig.setInboundAuthenticationRequestConfigs(
                    inboundAuthConfigs.values().toArray(new InboundAuthenticationRequestConfig[0]));
        } else {
            addNewInboundToSp(application, newInbound);
        }
    } else {
        // Create new inbound auth config.
        addNewInboundToSp(application, newInbound);
    }
}
 
Example #6
Source File: DirectoryServerApplicationMgtListener.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void doExportServiceProvider(ServiceProvider serviceProvider, Boolean exportSecrets)
        throws IdentityApplicationManagementException {

    InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
    if (inboundAuthenticationConfig != null &&
            inboundAuthenticationConfig.getInboundAuthenticationRequestConfigs() != null) {
        for (InboundAuthenticationRequestConfig authConfig
                : inboundAuthenticationConfig.getInboundAuthenticationRequestConfigs()) {
            if (KERBEROS.equals(authConfig.getInboundAuthType())) {
                inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(
                        (InboundAuthenticationRequestConfig[]) ArrayUtils.removeElement
                                (inboundAuthenticationConfig.getInboundAuthenticationRequestConfigs(), authConfig));
                return;
            }
        }
    }
}
 
Example #7
Source File: ApplicationMgtValidator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param inboundAuthenticationConfig Inbound authentication configuration.
 * @param tenantDomain                Tenant domain of application.
 * @param appId                       Application ID.
 * @throws IdentityApplicationManagementException IdentityApplicationManagementException.
 */
private void validateInboundAuthenticationConfig(InboundAuthenticationConfig inboundAuthenticationConfig, String
        tenantDomain, int appId) throws IdentityApplicationManagementException {

    if (inboundAuthenticationConfig == null) {
        return;
    }
    InboundAuthenticationRequestConfig[] inboundAuthRequestConfigs = inboundAuthenticationConfig
            .getInboundAuthenticationRequestConfigs();
    if (ArrayUtils.isNotEmpty(inboundAuthRequestConfigs)) {
        for (InboundAuthenticationRequestConfig inboundAuthRequestConfig : inboundAuthRequestConfigs) {
            validateInboundAuthKey(inboundAuthRequestConfig, appId, tenantDomain);
        }
    }
}
 
Example #8
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the application from IDN_APPMGT_APP table. Cascade deletes with foreign key
 * constraints should delete the corresponding entries from the tables
 *
 * @param appName
 * @throws IdentityApplicationManagementException
 */
public void deleteApplication(String appName) throws IdentityApplicationManagementException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    Connection connection = IdentityDatabaseUtil.getDBConnection();

    if (log.isDebugEnabled()) {
        log.debug("Deleting Application " + appName);
    }

    // Now, delete the application
    PreparedStatement deleteClientPrepStmt = null;
    try {
        // First, delete all the clients of the application
        int applicationID = getApplicationIDByName(appName, tenantID, connection);
        InboundAuthenticationConfig clients = getInboundAuthenticationConfig(applicationID,
                connection, tenantID);
        for (InboundAuthenticationRequestConfig client : clients
                .getInboundAuthenticationRequestConfigs()) {
            deleteClient(client.getInboundAuthKey(), client.getInboundAuthType());
        }

        deleteClientPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_APP_FROM_APPMGT_APP);
        deleteClientPrepStmt.setString(1, appName);
        deleteClientPrepStmt.setInt(2, tenantID);
        deleteClientPrepStmt.execute();

        if (!connection.getAutoCommit()) {
            connection.commit();
        }

    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error deleting application", e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteClientPrepStmt);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
}
 
Example #9
Source File: OAuthApplicationMgtListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void removeClientSecret(ServiceProvider serviceProvider) {
    InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
    if (inboundAuthenticationConfig != null) {
        InboundAuthenticationRequestConfig[] inboundRequestConfigs = inboundAuthenticationConfig.
                getInboundAuthenticationRequestConfigs();
        if (inboundRequestConfigs != null) {
            for (InboundAuthenticationRequestConfig inboundRequestConfig : inboundRequestConfigs) {
                if (inboundRequestConfig.getInboundAuthType().equals(OAUTH2)) {
                    Property[] props = inboundRequestConfig.getProperties();
                    for (Property prop : props) {
                        if (prop.getName().equalsIgnoreCase(OAUTH2_CONSUMER_SECRET)) {
                            props = (Property[]) ArrayUtils.removeElement(props, prop);
                            inboundRequestConfig.setProperties(props);
                            continue;   //we are interested only on this property
                        } else {
                            //ignore
                        }
                    }
                    continue;// we are interested only on oauth2 config. Only one will be present.
                } else {
                    //ignore
                }
            }
        } else {
            //ignore
        }
    } else {
        //nothing to do
    }
}
 
Example #10
Source File: OAuthApplicationMgtListener.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void addClientSecret(ServiceProvider serviceProvider) throws IdentityApplicationManagementException {

        if (serviceProvider == null) {
            return ; // if service provider is not present no need to add this information
        }

        try {
            InboundAuthenticationConfig inboundAuthenticationConfig = serviceProvider.getInboundAuthenticationConfig();
            if (inboundAuthenticationConfig != null) {
                InboundAuthenticationRequestConfig[] inboundRequestConfigs = inboundAuthenticationConfig.
                        getInboundAuthenticationRequestConfigs();
                if (inboundRequestConfigs != null) {
                    for (InboundAuthenticationRequestConfig inboundRequestConfig : inboundRequestConfigs) {
                        if (inboundRequestConfig.getInboundAuthType().equals(OAUTH2)) {
                            Property[] props = inboundRequestConfig.getProperties();
                            Property property = new Property();
                            property.setName(OAUTH2_CONSUMER_SECRET);
                            property.setValue(getClientSecret(inboundRequestConfig.getInboundAuthKey()));
                            props = (Property[]) ArrayUtils.add(props, property);
                            inboundRequestConfig.setProperties(props);
                            continue;// we are interested only on oauth2 config. Only one will be present.
                        } else {
                            //ignore
                        }
                    }
                } else {
                    //ignore
                }
            } else {
                //nothing to do
            }
        } catch (IdentityOAuthAdminException e) {
            throw new IdentityApplicationManagementException("Injecting client secret failed.", e);
        }


        return;
    }
 
Example #11
Source File: UpdateInboundProtocols.java    From identity-api-server with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(ServiceProvider application, InboundProtocols inboundProtocols) {

    List<InboundAuthenticationRequestConfig> inbounds = new ArrayList<>();

    try {
        if (inboundProtocols.getOidc() != null) {
            inbounds.add(createOAuthInbound(application.getApplicationName(), inboundProtocols.getOidc()));
        }

        if (inboundProtocols.getSaml() != null) {
            inbounds.add(createSAMLInbound(inboundProtocols.getSaml()));
        }

        if (inboundProtocols.getWsTrust() != null) {
            inbounds.add(createWsTrustInbound(inboundProtocols.getWsTrust()));
        }
    } catch (APIError error) {
        if (log.isDebugEnabled()) {
            log.debug("Error while adding inbound protocols for application id: "
                    + application.getApplicationResourceId() + ". Cleaning up possible partially created inbound " +
                    "configurations.");
        }
        rollbackInbounds(inbounds);
        throw error;
    }

    if (inboundProtocols.getPassiveSts() != null) {
        inbounds.add(createPassiveSTSInboundConfig(inboundProtocols.getPassiveSts()));
    }

    if (inboundProtocols.getCustom() != null) {
        inboundProtocols.getCustom().forEach(inboundConfigModel -> {
            // TODO Add validate at swagger to make sure inbound key and name are not null.
            InboundAuthenticationRequestConfig inboundRequestConfig = createCustomInbound(inboundConfigModel);
            inbounds.add(inboundRequestConfig);
        });
    }

    InboundAuthenticationConfig inboundAuthConfig = new InboundAuthenticationConfig();
    inboundAuthConfig.setInboundAuthenticationRequestConfigs(
            inbounds.toArray(new InboundAuthenticationRequestConfig[0])
    );

    application.setInboundAuthenticationConfig(inboundAuthConfig);
}
 
Example #12
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);
    }
}
 
Example #13
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Deletes the Application with application ID
 *
 * @param applicationID
 * @param connection
 * @throws IdentityApplicationManagementException
 */
public void deleteApplication(int applicationID, Connection connection)
        throws IdentityApplicationManagementException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("Deleting Application " + applicationID);
    }

    // Now, delete the application
    PreparedStatement deleteClientPrepStmt = null;
    try {

        // delete clients
        InboundAuthenticationConfig clients = getInboundAuthenticationConfig(applicationID,
                connection, tenantID);
        for (InboundAuthenticationRequestConfig client : clients
                .getInboundAuthenticationRequestConfigs()) {
            deleteClient(client.getInboundAuthKey(), client.getInboundAuthType());
        }

        String applicationName = getApplicationName(applicationID, connection);
        // delete roles
        ApplicationMgtUtil.deleteAppRole(applicationName);

        deleteClientPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_APP_FROM_APPMGT_APP_WITH_ID);
        deleteClientPrepStmt.setInt(1, applicationID);
        deleteClientPrepStmt.setInt(2, tenantID);
        deleteClientPrepStmt.execute();

        if (!connection.getAutoCommit()) {
            connection.commit();
        }

    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new IdentityApplicationManagementException("Error deleting application");

    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteClientPrepStmt);
    }

}
 
Example #14
Source File: InboundFunctions.java    From identity-api-server with Apache License 2.0 3 votes vote down vote up
private static void addNewInboundToSp(ServiceProvider application, InboundAuthenticationRequestConfig newInbound) {

        InboundAuthenticationConfig inboundAuth = new InboundAuthenticationConfig();
        inboundAuth.setInboundAuthenticationRequestConfigs(new InboundAuthenticationRequestConfig[]{newInbound});

        application.setInboundAuthenticationConfig(inboundAuth);
    }