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);
}
}
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;
}
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);
}
}
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;
}
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.");
}
Aggregations