use of org.wso2.carbon.identity.application.common.model.idp.xsd.ClaimConfig in project carbon-apimgt by wso2.
the class APIAdminImpl method updateClaims.
private void updateClaims(IdentityProvider idp, Object claims) {
if (claims != null) {
ClaimConfig claimConfig = new ClaimConfig();
List<ClaimMapping> claimMappings = new ArrayList<>();
List<org.wso2.carbon.identity.application.common.model.Claim> idpClaims = new ArrayList<>();
JsonArray claimArray = (JsonArray) claims;
claimConfig.setLocalClaimDialect(false);
for (JsonElement claimMappingEntry : claimArray) {
if (claimMappingEntry instanceof JsonObject) {
JsonElement idpClaimUri = ((JsonObject) claimMappingEntry).get("remoteClaim");
JsonElement localClaimUri = ((JsonObject) claimMappingEntry).get("localClaim");
ClaimMapping internalMapping = new ClaimMapping();
org.wso2.carbon.identity.application.common.model.Claim remoteClaim = new org.wso2.carbon.identity.application.common.model.Claim();
remoteClaim.setClaimUri(idpClaimUri.getAsString());
org.wso2.carbon.identity.application.common.model.Claim localClaim = new org.wso2.carbon.identity.application.common.model.Claim();
localClaim.setClaimUri(localClaimUri.getAsString());
internalMapping.setRemoteClaim(remoteClaim);
internalMapping.setLocalClaim(localClaim);
claimMappings.add(internalMapping);
idpClaims.add(remoteClaim);
}
}
claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[0]));
claimConfig.setIdpClaims(idpClaims.toArray(new org.wso2.carbon.identity.application.common.model.Claim[0]));
idp.setClaimConfig(claimConfig);
}
}
use of org.wso2.carbon.identity.application.common.model.idp.xsd.ClaimConfig in project carbon-identity-framework by wso2.
the class IdentityProviderManager method getMappedLocalClaims.
/**
* Retrieves Identity provider information about a given tenant
*
* @param idPName Unique Name of the IdP to which the given IdP claim URIs need to be mapped
* @param tenantDomain The tenant domain of whose local claim URIs to be mapped
* @param idPClaimURIs IdP claim URIs which need to be mapped to tenant's local claim URIs
* @throws IdentityProviderManagementException Error when getting claim mappings
*/
@Override
public Set<ClaimMapping> getMappedLocalClaims(String idPName, String tenantDomain, List<String> idPClaimURIs) throws IdentityProviderManagementException {
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
if (StringUtils.isEmpty(idPName)) {
String msg = "Invalid argument: Identity Provider Name value is empty";
throw new IdentityProviderManagementException(msg);
}
IdentityProvider identityProvider = dao.getIdPByName(null, idPName, tenantId, tenantDomain);
if (identityProvider == null) {
identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
}
if (identityProvider == null) {
identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
}
ClaimConfig claimConfiguration = identityProvider.getClaimConfig();
if (claimConfiguration != null) {
ClaimMapping[] claimMappings = claimConfiguration.getClaimMappings();
if (claimMappings != null && claimMappings.length > 0 && idPClaimURIs != null) {
Set<ClaimMapping> returnSet = new HashSet<ClaimMapping>();
for (String idpClaim : idPClaimURIs) {
for (ClaimMapping claimMapping : claimMappings) {
if (claimMapping.getRemoteClaim().getClaimUri().equals(idpClaim)) {
returnSet.add(claimMapping);
break;
}
}
}
return returnSet;
}
}
return new HashSet<ClaimMapping>();
}
use of org.wso2.carbon.identity.application.common.model.idp.xsd.ClaimConfig 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.identity.application.common.model.idp.xsd.ClaimConfig in project carbon-identity-framework by wso2.
the class IdPManagementUIUtil method buildClaimConfiguration.
/**
* @param fedIdp
* @param paramMap
* @throws IdentityApplicationManagementException
*/
private static void buildClaimConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap, List<String> idpClaims, ClaimMapping[] currentClaimMapping) throws IdentityApplicationManagementException {
ClaimConfig claimConfiguration = new ClaimConfig();
if (idpClaims != null && idpClaims.size() > 0) {
List<Claim> idPClaimList = new ArrayList<Claim>();
for (Iterator<String> iterator = idpClaims.iterator(); iterator.hasNext(); ) {
String claimUri = iterator.next();
Claim idpClaim = new Claim();
idpClaim.setClaimUri(claimUri);
idPClaimList.add(idpClaim);
}
claimConfiguration.setIdpClaims(idPClaimList.toArray(new Claim[idPClaimList.size()]));
}
claimConfiguration.setUserClaimURI(paramMap.get("user_id_claim_dropdown"));
claimConfiguration.setRoleClaimURI(paramMap.get("role_claim_dropdown"));
ClaimConfig claimConfigurationUpdated = claimMappingFromUI(claimConfiguration, paramMap);
fedIdp.setClaimConfig(claimConfigurationUpdated);
}
use of org.wso2.carbon.identity.application.common.model.idp.xsd.ClaimConfig in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getLocalIdPDefaultClaimValues.
/**
* @param dbConnection
* @param idPName
* @param userClaimUri
* @param roleClaimUri
* @param idpId
* @param tenantId
* @return
* @throws SQLException
*/
private ClaimConfig getLocalIdPDefaultClaimValues(Connection dbConnection, String idPName, String userClaimUri, String roleClaimUri, int idpId, int tenantId) throws SQLException {
PreparedStatement prepStmt = null;
ResultSet rs = null;
String sqlStmt;
ClaimConfig claimConfig = new ClaimConfig();
try {
claimConfig.setLocalClaimDialect(true);
claimConfig.setRoleClaimURI(roleClaimUri);
claimConfig.setUserClaimURI(userClaimUri);
sqlStmt = IdPManagementConstants.SQLQueries.GET_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setInt(1, idpId);
prepStmt.setInt(2, tenantId);
List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>();
rs = prepStmt.executeQuery();
while (rs.next()) {
ClaimMapping claimMapping = new ClaimMapping();
// empty claim.
Claim remoteClaim = new Claim();
Claim localClaim = new Claim();
localClaim.setClaimUri(rs.getString("CLAIM_URI"));
claimMapping.setLocalClaim(localClaim);
claimMapping.setRemoteClaim(remoteClaim);
claimMapping.setDefaultValue(rs.getString("DEFAULT_VALUE"));
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_REQUESTED"))) {
claimMapping.setRequested(true);
} else if (rs.getString("IS_REQUESTED").equals(IdPManagementConstants.IS_TRUE_VALUE)) {
claimMapping.setRequested(false);
}
claimMappings.add(claimMapping);
}
claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[claimMappings.size()]));
return claimConfig;
} finally {
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
}
}
Aggregations