Search in sources :

Example 1 with IdentityProviderManagementServerException

use of org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException in project carbon-identity-framework by wso2.

the class IdPManagementDAO method populateRequiredAttributesForIdentityProviderList.

/**
 * @param resultSet          ResultSet.
 * @param dbConnection       Database Connection.
 * @param requiredAttributes Required attributes which needs to be return.
 * @param tenantId           Tenant Id of the identity provider.
 * @param identityProvider   Identity Provider Object.
 * @throws SQLException
 * @throws IdentityProviderManagementServerException
 */
private void populateRequiredAttributesForIdentityProviderList(ResultSet resultSet, Connection dbConnection, List<String> requiredAttributes, int tenantId, IdentityProvider identityProvider) throws SQLException, IdentityProviderManagementServerException {
    int idpId = Integer.parseInt(identityProvider.getId());
    String idPName = identityProvider.getIdentityProviderName();
    try {
        if (CollectionUtils.isNotEmpty(requiredAttributes)) {
            for (String attribute : requiredAttributes) {
                switch(attribute) {
                    case IdPManagementConstants.IDP_IS_PRIMARY:
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_PRIMARY"))) {
                            identityProvider.setPrimary(true);
                        } else {
                            identityProvider.setPrimary(false);
                        }
                        break;
                    case IdPManagementConstants.IDP_HOME_REALM_ID:
                        identityProvider.setHomeRealmId(resultSet.getString("HOME_REALM_ID"));
                        break;
                    case IdPManagementConstants.IDP_IS_FEDERATION_HUB:
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_FEDERATION_HUB"))) {
                            identityProvider.setFederationHub(false);
                        }
                        break;
                    case IdPManagementConstants.IDP_CERTIFICATE:
                        identityProvider.setCertificate(getBlobValue(resultSet.getBinaryStream("CERTIFICATE")));
                        break;
                    case IdPManagementConstants.IDP_ALIAS:
                        identityProvider.setAlias(resultSet.getString("ALIAS"));
                        break;
                    case IdPManagementConstants.IDP_CLAIMS:
                        if (identityProvider.getClaimConfig() == null) {
                            identityProvider.setClaimConfig(new ClaimConfig());
                        }
                        if (IdPManagementConstants.IS_TRUE_VALUE.equals(resultSet.getString("IS_LOCAL_CLAIM_DIALECT"))) {
                            identityProvider.getClaimConfig().setLocalClaimDialect(true);
                        } else {
                            identityProvider.getClaimConfig().setLocalClaimDialect(false);
                        }
                        String userClaimUri = resultSet.getString("USER_CLAIM_URI");
                        String roleClaimUri = resultSet.getString("ROLE_CLAIM_URI");
                        if (identityProvider.getClaimConfig().isLocalClaimDialect()) {
                            identityProvider.setClaimConfig(getLocalIdPDefaultClaimValues(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
                        } else {
                            // Get claim configuration.
                            identityProvider.setClaimConfig(getIdPClaimConfiguration(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
                        }
                        break;
                    case IdPManagementConstants.IDP_ROLES:
                        identityProvider.setProvisioningRole(resultSet.getString("PROVISIONING_ROLE"));
                        // Get permission and role configuration.
                        identityProvider.setPermissionAndRoleConfig(getPermissionsAndRoleConfiguration(dbConnection, idPName, idpId, tenantId));
                        break;
                    case IdPManagementConstants.IDP_FEDERATED_AUTHENTICATORS:
                        String defaultAuthenticatorName = resultSet.getString("DEFAULT_AUTHENTICATOR_NAME");
                        // Get federated authenticators.
                        identityProvider.setFederatedAuthenticatorConfigs(getFederatedAuthenticatorConfigs(dbConnection, idPName, identityProvider, tenantId));
                        if (defaultAuthenticatorName != null && identityProvider.getFederatedAuthenticatorConfigs() != null) {
                            identityProvider.setDefaultAuthenticatorConfig(IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), defaultAuthenticatorName));
                        }
                        break;
                    case IdPManagementConstants.IDP_PROVISIONING:
                        JustInTimeProvisioningConfig jitProConfig = new JustInTimeProvisioningConfig();
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("INBOUND_PROV_ENABLED"))) {
                            jitProConfig.setProvisioningEnabled(true);
                        } else {
                            jitProConfig.setProvisioningEnabled(false);
                        }
                        jitProConfig.setProvisioningUserStore(resultSet.getString("INBOUND_PROV_USER_STORE_ID"));
                        identityProvider.setJustInTimeProvisioningConfig(jitProConfig);
                        String defaultProvisioningConnectorConfigName = resultSet.getString("DEFAULT_PRO_CONNECTOR_NAME");
                        if (defaultProvisioningConnectorConfigName != null) {
                            ProvisioningConnectorConfig defaultProConnector = new ProvisioningConnectorConfig();
                            defaultProConnector.setName(defaultProvisioningConnectorConfigName);
                            identityProvider.setDefaultProvisioningConnectorConfig(defaultProConnector);
                        }
                        // Get provisioning connectors.
                        identityProvider.setProvisioningConnectorConfigs(getProvisioningConnectorConfigs(dbConnection, idPName, idpId, tenantId));
                        break;
                }
            }
        }
    } catch (IdentityProviderManagementException e) {
        throw new IdentityProviderManagementServerException("Error occurred while performing required " + "attribute filter", e);
    }
}
Also used : ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.JustInTimeProvisioningConfig) IdentityProviderManagementServerException(org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 2 with IdentityProviderManagementServerException

use of org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getCountOfFilteredIdPs.

/**
 * Get number of IdP count for a matching filter.
 *
 * @param tenantId       Tenant Id of the identity provider.
 * @param expressionNode filter value list for IdP search.
 * @return number of IdP count for a given filter
 * @throws IdentityProviderManagementServerException Error when getting count of Identity Providers.
 * @throws IdentityProviderManagementClientException Error when append the filer string.
 */
int getCountOfFilteredIdPs(int tenantId, List<ExpressionNode> expressionNode) throws IdentityProviderManagementServerException, IdentityProviderManagementClientException {
    String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_COUNT_SQL;
    int countOfFilteredIdp = 0;
    FilterQueryBuilder filterQueryBuilder = new FilterQueryBuilder();
    appendFilterQuery(expressionNode, filterQueryBuilder);
    Map<Integer, String> filterAttributeValue = filterQueryBuilder.getFilterAttributeValue();
    sqlStmt = sqlStmt + filterQueryBuilder.getFilterQuery() + IdPManagementConstants.SQLQueries.GET_IDP_COUNT_SQL_TAIL;
    try (Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
        PreparedStatement prepStmt = dbConnection.prepareStatement(sqlStmt)) {
        for (Map.Entry<Integer, String> prepareStatement : filterAttributeValue.entrySet()) {
            prepStmt.setString(prepareStatement.getKey(), prepareStatement.getValue());
        }
        prepStmt.setInt(filterAttributeValue.entrySet().size() + 1, tenantId);
        try (ResultSet rs = prepStmt.executeQuery()) {
            if (rs.next()) {
                countOfFilteredIdp = Integer.parseInt(rs.getString(1));
            }
        }
    } catch (SQLException e) {
        String message = "Error occurred while retrieving Identity Provider count for a tenant : " + IdentityTenantUtil.getTenantDomain(tenantId);
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_CONNECTING_DATABASE, message, e);
    }
    return countOfFilteredIdp;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) FilterQueryBuilder(org.wso2.carbon.idp.mgt.model.FilterQueryBuilder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with IdentityProviderManagementServerException

use of org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getIdPsSearch.

/**
 * Get all identity provider's Basic information along with additionally requested information depends on the
 * requiredAttributes for a given matching filter.
 *
 * @param tenantId           Tenant Id of the identity provider.
 * @param expressionNode     List of filter value for IdP search.
 * @param limit              Limit per page.
 * @param offset             Offset value.
 * @param sortOrder          Order of IdP ASC/DESC.
 * @param sortBy             The attribute need to sort.
 * @param requiredAttributes Required attributes which needs to be return.
 * @return Identity Provider's Basic Information array along with requested attribute information.
 * @throws IdentityProviderManagementServerException Error when getting list of Identity Providers.
 * @throws IdentityProviderManagementClientException Error when append the filer string.
 */
List<IdentityProvider> getIdPsSearch(int tenantId, List<ExpressionNode> expressionNode, int limit, int offset, String sortOrder, String sortBy, List<String> requiredAttributes) throws IdentityProviderManagementServerException, IdentityProviderManagementClientException {
    FilterQueryBuilder filterQueryBuilder = new FilterQueryBuilder();
    appendFilterQuery(expressionNode, filterQueryBuilder);
    String sortedOrder = sortBy + " " + sortOrder;
    try (Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
        ResultSet resultSet = getIdpQueryResultSet(dbConnection, sortedOrder, tenantId, offset, limit, filterQueryBuilder, requiredAttributes)) {
        return populateIdentityProviderList(resultSet, dbConnection, requiredAttributes, tenantId);
    } catch (SQLException e) {
        String message = "Error occurred while retrieving Identity Provider for tenant: " + IdentityTenantUtil.getTenantDomain(tenantId);
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_CONNECTING_DATABASE, message, e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) FilterQueryBuilder(org.wso2.carbon.idp.mgt.model.FilterQueryBuilder)

Example 4 with IdentityProviderManagementServerException

use of org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException in project carbon-identity-framework by wso2.

the class IdPManagementDAO method populateIdentityProviderList.

/**
 * Populate the result set.
 *
 * @param resultSet          ResultSet.
 * @param dbConnection       Database Connection.
 * @param requiredAttributes Required attributes which needs to be return.
 * @param tenantId           Tenant Id of the identity provider.
 * @return List of Identity Provider.
 * @throws SQLException Database Exception.
 */
private List<IdentityProvider> populateIdentityProviderList(ResultSet resultSet, Connection dbConnection, List<String> requiredAttributes, int tenantId) throws SQLException, IdentityProviderManagementServerException {
    List<IdentityProvider> identityProviderList = new ArrayList<>();
    while (resultSet.next()) {
        IdentityProvider identityProvider = new IdentityProvider();
        // First set the basic attributes such as id, name, description, isEnabled, image url, uuid.
        identityProvider.setId(resultSet.getString("ID"));
        identityProvider.setIdentityProviderName(resultSet.getString("NAME"));
        identityProvider.setIdentityProviderDescription(resultSet.getString("DESCRIPTION"));
        // IS_ENABLE
        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_ENABLED"))) {
            identityProvider.setEnable(true);
        } else {
            identityProvider.setEnable(false);
        }
        identityProvider.setImageUrl(resultSet.getString("IMAGE_URL"));
        identityProvider.setResourceId(resultSet.getString("UUID"));
        populateRequiredAttributesForIdentityProviderList(resultSet, dbConnection, requiredAttributes, tenantId, identityProvider);
        if (!IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(identityProvider.getIdentityProviderName())) {
            identityProviderList.add(identityProvider);
        }
        List<IdentityProviderProperty> propertyList = getIdentityPropertiesByIdpId(dbConnection, Integer.parseInt(resultSet.getString("ID")));
        identityProvider.setIdpProperties(propertyList.toArray(new IdentityProviderProperty[0]));
    }
    return identityProviderList;
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 5 with IdentityProviderManagementServerException

use of org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException in project carbon-identity-framework by wso2.

the class IdPManagementUtilTest method testHandleServerException.

@Test
public void testHandleServerException() {
    IdentityProviderManagementServerException exception1 = IdPManagementUtil.handleServerException(ErrorMessage.ERROR_CODE_ADD_IDP, "test1");
    assertEquals(exception1.getErrorCode(), "IDP-65002");
    assertEquals(exception1.getMessage(), "Error while adding the Identity Provider: test1.");
    Throwable t = new Throwable();
    IdentityProviderManagementServerException exception2 = IdPManagementUtil.handleServerException(ErrorMessage.ERROR_CODE_ADD_IDP, "test2", t);
    assertEquals(exception2.getErrorCode(), "IDP-65002");
    assertEquals(exception2.getMessage(), "Error while adding the Identity Provider: test2.");
}
Also used : IdentityProviderManagementServerException(org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

IdentityProviderManagementServerException (org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException)5 Response (javax.ws.rs.core.Response)3 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)3 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)3 IdentityProviderManagementClientException (org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 FilterQueryBuilder (org.wso2.carbon.idp.mgt.model.FilterQueryBuilder)2 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 FederatedAuthenticatorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse)1 IdentityProviderListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse)1 IdentityProviderResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse)1 IdentityProviderTemplateListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse)1 OutboundConnectorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse)1