Search in sources :

Example 1 with AbstractInboundAuthenticatorConfig

use of org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method updateInboundAuthRequestConfiguration.

/**
 * @param applicationId
 * @param inBoundAuthenticationConfig
 * @param connection
 * @throws SQLException
 */
private void updateInboundAuthRequestConfiguration(int applicationId, InboundAuthenticationConfig inBoundAuthenticationConfig, Connection connection) throws IdentityApplicationManagementException {
    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(STORE_CLIENT_INFO);
        InboundAuthenticationRequestConfig[] authRequests = inBoundAuthenticationConfig.getInboundAuthenticationRequestConfigs();
        for (InboundAuthenticationRequestConfig authRequest : authRequests) {
            if (authRequest == null || authRequest.getInboundAuthType() == null) {
                log.warn("Invalid in-bound authentication request");
                // not a valid authentication request. Must have client and a type.
                continue;
            }
            Property[] propertiesArray = authRequest.getProperties();
            List<Property> propertyArrayList = new ArrayList<>();
            String authKey = null;
            String inboundConfigType = ApplicationConstants.STANDARD_APPLICATION;
            if (standardInboundAuthTypes.contains(authRequest.getInboundAuthType())) {
                authKey = authRequest.getInboundAuthKey();
                propertyArrayList = filterEmptyProperties(propertiesArray);
            } else {
                AbstractInboundAuthenticatorConfig inboundAuthenticatorConfig = ApplicationManagementServiceComponentHolder.getInboundAuthenticatorConfig(authRequest.getInboundAuthType() + ":" + authRequest.getInboundConfigType());
                if (inboundAuthenticatorConfig != null && StringUtils.isNotBlank(inboundAuthenticatorConfig.getRelyingPartyKey())) {
                    if (propertiesArray != null && propertiesArray.length > 0) {
                        for (Property prop : propertiesArray) {
                            if (inboundAuthenticatorConfig.getRelyingPartyKey().equals(prop.getName())) {
                                if (StringUtils.isNotBlank(prop.getValue())) {
                                    authKey = prop.getValue();
                                }
                            } else {
                                if (StringUtils.isNotBlank(prop.getValue())) {
                                    propertyArrayList.add(prop);
                                }
                            }
                        }
                    }
                } else {
                    propertyArrayList = filterEmptyProperties(propertiesArray);
                }
            }
            if (StringUtils.isBlank(authKey)) {
                String applicationName = getApplicationName(applicationId, connection);
                if (StringUtils.isNotBlank(applicationName)) {
                    authKey = applicationName;
                }
            }
            if (StringUtils.isNotBlank(authRequest.getInboundConfigType())) {
                inboundConfigType = authRequest.getInboundConfigType();
            }
            if (!propertyArrayList.isEmpty()) {
                for (Property prop : propertyArrayList) {
                    inboundAuthReqConfigPrepStmt.setInt(1, tenantID);
                    inboundAuthReqConfigPrepStmt.setString(2, authKey);
                    inboundAuthReqConfigPrepStmt.setString(3, authRequest.getInboundAuthType());
                    inboundAuthReqConfigPrepStmt.setString(4, prop.getName());
                    inboundAuthReqConfigPrepStmt.setString(5, prop.getValue());
                    inboundAuthReqConfigPrepStmt.setInt(6, applicationId);
                    inboundAuthReqConfigPrepStmt.setString(7, inboundConfigType);
                    inboundAuthReqConfigPrepStmt.addBatch();
                }
            } else {
                inboundAuthReqConfigPrepStmt.setInt(1, tenantID);
                inboundAuthReqConfigPrepStmt.setString(2, authKey);
                inboundAuthReqConfigPrepStmt.setString(3, authRequest.getInboundAuthType());
                inboundAuthReqConfigPrepStmt.setString(4, null);
                inboundAuthReqConfigPrepStmt.setString(5, null);
                inboundAuthReqConfigPrepStmt.setInt(6, applicationId);
                inboundAuthReqConfigPrepStmt.setString(7, inboundConfigType);
                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();
    } catch (SQLException e) {
        log.error("Error occurred while updating the Inbound Authentication Request Configuration.", e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(inboundAuthReqConfigPrepStmt);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) AbstractInboundAuthenticatorConfig(org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 2 with AbstractInboundAuthenticatorConfig

use of org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig in project identity-api-server by wso2.

the class ServerApplicationMetadataService method getCustomProtocolMetadata.

/**
 * Pull property metadata of the custom inbound protocol that matches to the protocol name.
 *
 * @param inboundProtocolName URL encoded protocol name.
 * @return Populated CustomInboundProtocolMetaData object.
 */
public CustomInboundProtocolMetaData getCustomProtocolMetadata(String inboundProtocolName) {
    String protocolName = URLDecoder.decode(inboundProtocolName);
    Map<String, AbstractInboundAuthenticatorConfig> allCustomAuthenticators = ApplicationManagementServiceHolder.getApplicationManagementService().getAllInboundAuthenticatorConfig();
    // Loop through all custom inbound protocols and match the name.
    for (Map.Entry<String, AbstractInboundAuthenticatorConfig> entry : allCustomAuthenticators.entrySet()) {
        if (entry.getValue().getName().equals(protocolName)) {
            return new CustomInboundProtocolMetaData().displayName(entry.getValue().getFriendlyName()).configName(entry.getValue().getConfigName()).properties(getCustomInboundProtocolProperties(entry.getValue().getConfigurationProperties()));
        }
    }
    // Throw 404 error if the protocol not found
    throw handleInvalidInboundProtocol(inboundProtocolName);
}
Also used : CustomInboundProtocolMetaData(org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolMetaData) AbstractInboundAuthenticatorConfig(org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig) Map(java.util.Map)

Example 3 with AbstractInboundAuthenticatorConfig

use of org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getInboundAuthenticationConfig.

/**
 * @param applicationId
 * @param connection
 * @return
 * @throws SQLException
 */
private InboundAuthenticationConfig getInboundAuthenticationConfig(int applicationId, Connection connection, int tenantID) throws SQLException {
    if (log.isDebugEnabled()) {
        log.debug("Reading Clients of Application " + applicationId);
    }
    Map<String, InboundAuthenticationRequestConfig> inboundAuthenticationRequestConfigMap = new HashMap<String, InboundAuthenticationRequestConfig>();
    PreparedStatement getClientInfo = null;
    ResultSet resultSet = null;
    try {
        getClientInfo = connection.prepareStatement(LOAD_CLIENTS_INFO_BY_APP_ID);
        getClientInfo.setInt(1, applicationId);
        getClientInfo.setInt(2, tenantID);
        resultSet = getClientInfo.executeQuery();
        while (resultSet.next()) {
            String authKey = resultSet.getString(1);
            // this is done to handle empty string added to oracle database as null.
            if (authKey == null) {
                authKey = new String();
            }
            String authType = resultSet.getString(2);
            String propName = resultSet.getString(3);
            String propValue = resultSet.getString(4);
            String configType = resultSet.getString(5);
            String mapKey = authType + ":" + authKey;
            InboundAuthenticationRequestConfig inboundAuthRequest = null;
            if ((inboundAuthRequest = inboundAuthenticationRequestConfigMap.get(mapKey)) == null) {
                inboundAuthRequest = new InboundAuthenticationRequestConfig();
            }
            inboundAuthRequest.setInboundAuthKey(authKey);
            inboundAuthRequest.setInboundAuthType(authType);
            inboundAuthRequest.setInboundConfigType(configType);
            boolean isCustomAuthenticator = isCustomInboundAuthType(authType);
            AbstractInboundAuthenticatorConfig customAuthenticator = ApplicationManagementServiceComponentHolder.getInboundAuthenticatorConfig(authType + ":" + configType);
            if (isCustomAuthenticator && customAuthenticator != null) {
                inboundAuthRequest.setFriendlyName(customAuthenticator.getFriendlyName());
            }
            if (propName != null) {
                Property prop = new Property();
                prop.setName(propName);
                prop.setValue(propValue);
                if (isCustomAuthenticator && customAuthenticator != null) {
                    Property mappedProperty = getMappedProperty(customAuthenticator, propName);
                    if (mappedProperty != null) {
                        prop.setDisplayName(mappedProperty.getDisplayName());
                    }
                }
                inboundAuthRequest.setProperties((ApplicationMgtUtil.concatArrays(new Property[] { prop }, inboundAuthRequest.getProperties())));
            }
            inboundAuthenticationRequestConfigMap.put(mapKey, inboundAuthRequest);
        }
    } finally {
        IdentityApplicationManagementUtil.closeStatement(getClientInfo);
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
    }
    Map<String, AbstractInboundAuthenticatorConfig> allCustomAuthenticators = new HashMap<>(ApplicationManagementServiceComponentHolder.getAllInboundAuthenticatorConfig());
    for (Map.Entry<String, InboundAuthenticationRequestConfig> entry : inboundAuthenticationRequestConfigMap.entrySet()) {
        InboundAuthenticationRequestConfig inboundAuthenticationRequestConfig = entry.getValue();
        AbstractInboundAuthenticatorConfig inboundAuthenticatorConfig = allCustomAuthenticators.remove(inboundAuthenticationRequestConfig.getInboundAuthType() + ":" + inboundAuthenticationRequestConfig.getInboundConfigType());
        if (inboundAuthenticatorConfig != null && inboundAuthenticationRequestConfig != null) {
            Property[] sources = inboundAuthenticatorConfig.getConfigurationProperties();
            Property[] destinations = inboundAuthenticationRequestConfig.getProperties();
            Map<String, Property> destinationMap = new HashMap<>();
            for (Property destination : destinations) {
                destinationMap.put(destination.getName(), destination);
            }
            for (Property source : sources) {
                Property property = destinationMap.get(source.getName());
                if (property == null) {
                    if (isCustomInboundAuthType(inboundAuthenticationRequestConfig.getInboundAuthType())) {
                        if (inboundAuthenticatorConfig.isRelyingPartyKeyConfigured()) {
                            if (StringUtils.equals(inboundAuthenticatorConfig.getRelyingPartyKey(), source.getName())) {
                                source.setValue(inboundAuthenticationRequestConfig.getInboundAuthKey());
                            }
                        }
                    }
                    destinationMap.put(source.getName(), source);
                } else {
                    property.setConfidential(source.isConfidential());
                    property.setDefaultValue(source.getDefaultValue());
                    property.setAdvanced(source.isAdvanced());
                    property.setDescription(source.getDescription());
                    property.setDisplayOrder(source.getDisplayOrder());
                    property.setRequired(source.isRequired());
                    property.setType(source.getType());
                }
            }
            inboundAuthenticationRequestConfig.setProperties(destinationMap.values().toArray(new Property[destinationMap.size()]));
        }
    }
    List<InboundAuthenticationRequestConfig> returnList = new ArrayList<>(inboundAuthenticationRequestConfigMap.values());
    InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
    inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(returnList.toArray(new InboundAuthenticationRequestConfig[returnList.size()]));
    return inboundAuthenticationConfig;
}
Also used : HashMap(java.util.HashMap) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) ArrayList(java.util.ArrayList) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) ResultSet(java.sql.ResultSet) AbstractInboundAuthenticatorConfig(org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with AbstractInboundAuthenticatorConfig

use of org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig in project carbon-identity-framework by wso2.

the class ApplicationManagementAdminService method generateCustomInboundAuthenticatorConfigs.

private void generateCustomInboundAuthenticatorConfigs() {
    List<InboundAuthenticationRequestConfig> customAuthenticatorConfigs = new ArrayList<>();
    Map<String, AbstractInboundAuthenticatorConfig> customInboundAuthenticators = ApplicationManagementServiceComponentHolder.getAllInboundAuthenticatorConfig();
    if (customInboundAuthenticators != null && customInboundAuthenticators.size() > 0) {
        for (Map.Entry<String, AbstractInboundAuthenticatorConfig> entry : customInboundAuthenticators.entrySet()) {
            AbstractInboundAuthenticatorConfig inboundAuthenticatorConfig = entry.getValue();
            InboundAuthenticationRequestConfig inboundAuthenticationRequestConfig = new InboundAuthenticationRequestConfig();
            inboundAuthenticationRequestConfig.setInboundAuthType(inboundAuthenticatorConfig.getName());
            inboundAuthenticationRequestConfig.setInboundConfigType(inboundAuthenticatorConfig.getConfigName());
            inboundAuthenticationRequestConfig.setFriendlyName(inboundAuthenticatorConfig.getFriendlyName());
            inboundAuthenticationRequestConfig.setProperties(inboundAuthenticatorConfig.getConfigurationProperties());
            customAuthenticatorConfigs.add(inboundAuthenticationRequestConfig);
        }
    }
    this.customInboundAuthenticatorConfigs = customAuthenticatorConfigs;
}
Also used : ArrayList(java.util.ArrayList) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) Map(java.util.Map)

Example 5 with AbstractInboundAuthenticatorConfig

use of org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig in project identity-api-server by wso2.

the class ServerApplicationMetadataService method getInboundProtocols.

/**
 * Return a list of all available inbound protocols. If the customOnly parameter set to True, will return only the
 * custom protocols.
 *
 * @param customOnly Set to True to get only custom protocols. Default value: False.
 * @return The list of inbound protocols.
 */
public List<AuthProtocolMetadata> getInboundProtocols(Boolean customOnly) {
    List<AuthProtocolMetadata> authProtocolMetadataList = new ArrayList<>();
    // Add custom inbound protocols
    Map<String, AbstractInboundAuthenticatorConfig> allCustomAuthenticators = ApplicationManagementServiceHolder.getApplicationManagementService().getAllInboundAuthenticatorConfig();
    for (Map.Entry<String, AbstractInboundAuthenticatorConfig> entry : allCustomAuthenticators.entrySet()) {
        AuthProtocolMetadata protocol = new AuthProtocolMetadata().name(entry.getValue().getName()).displayName(entry.getValue().getFriendlyName());
        authProtocolMetadataList.add(protocol);
    }
    if (customOnly == null || !customOnly) {
        // Add default inbound protocols. WS-Federation (Passive) is not added because it doesn't have metadata,
        authProtocolMetadataList.add(new AuthProtocolMetadata().name("saml").displayName("SAML2 Web SSO Configuration"));
        authProtocolMetadataList.add(new AuthProtocolMetadata().name("oidc").displayName("OAuth/OpenID Connect Configuration"));
        authProtocolMetadataList.add(new AuthProtocolMetadata().name("ws-trust").displayName("WS-Trust Security Token Service Configuration"));
    }
    return authProtocolMetadataList;
}
Also used : AuthProtocolMetadata(org.wso2.carbon.identity.api.server.application.management.v1.AuthProtocolMetadata) ArrayList(java.util.ArrayList) AbstractInboundAuthenticatorConfig(org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AbstractInboundAuthenticatorConfig (org.wso2.carbon.identity.application.mgt.AbstractInboundAuthenticatorConfig)4 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)3 PreparedStatement (java.sql.PreparedStatement)2 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)2 Property (org.wso2.carbon.identity.application.common.model.Property)2 ServiceProviderProperty (org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 AuthProtocolMetadata (org.wso2.carbon.identity.api.server.application.management.v1.AuthProtocolMetadata)1 CustomInboundProtocolMetaData (org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolMetaData)1 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig)1