use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getAllLocalClaimUris.
@Override
public String[] getAllLocalClaimUris(String tenantDomain) throws IdentityApplicationManagementException {
try {
startTenantFlow(tenantDomain);
String claimDialect = ApplicationMgtSystemConfig.getInstance().getClaimDialect();
List<String> claimUris = new ArrayList<>();
if (UserCoreConstants.DEFAULT_CARBON_DIALECT.equalsIgnoreCase(claimDialect)) {
// Local claims are retrieved via ClaimMetadataManagement service for consistency.
List<LocalClaim> localClaims = ApplicationManagementServiceComponentHolder.getInstance().getClaimMetadataManagementService().getLocalClaims(tenantDomain);
claimUris = getLocalClaimURIs(localClaims);
} else {
ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager().getAllClaimMappings(claimDialect);
for (ClaimMapping claimMap : claimMappings) {
claimUris.add(claimMap.getClaim().getClaimUri());
}
}
String[] allLocalClaimUris = (claimUris.toArray(new String[claimUris.size()]));
if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
Arrays.sort(allLocalClaimUris);
}
return allLocalClaimUris;
} catch (Exception e) {
String error = "Error while reading system claims" + ". " + e.getMessage();
throw new IdentityApplicationManagementException(error, e);
} finally {
endTenantFlow();
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getClaimMapping.
/**
* @param serviceProviderName
* @param tenantDomain
* @param localIdpAsKey
* @return
* @throws SQLException
* @throws IdentityApplicationManagementException
*/
private Map<String, String> getClaimMapping(String serviceProviderName, String tenantDomain, boolean localIdpAsKey) throws SQLException, IdentityApplicationManagementException {
int tenantID = -123;
if (tenantDomain != null) {
try {
tenantID = ApplicationManagementServiceComponentHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e1) {
throw new IdentityApplicationManagementException("Error while reading application");
}
}
Map<String, String> claimMapping = new HashMap<String, String>();
if (log.isDebugEnabled()) {
log.debug("Reading Claim Mappings of Application " + serviceProviderName);
}
PreparedStatement getClaimPreStmt = null;
ResultSet resultSet = null;
Connection connection = IdentityDatabaseUtil.getDBConnection(false);
try {
getClaimPreStmt = connection.prepareStatement(LOAD_CLAIM_MAPPING_BY_APP_NAME);
// IDP_CLAIM, SP_CLAIM, IS_REQUESTED
getClaimPreStmt.setString(1, serviceProviderName);
getClaimPreStmt.setInt(2, tenantID);
resultSet = getClaimPreStmt.executeQuery();
while (resultSet.next()) {
if (localIdpAsKey) {
claimMapping.put(resultSet.getString(1), resultSet.getString(2));
} else {
claimMapping.put(resultSet.getString(2), resultSet.getString(1));
}
}
} finally {
IdentityApplicationManagementUtil.closeStatement(getClaimPreStmt);
IdentityApplicationManagementUtil.closeResultSet(resultSet);
IdentityApplicationManagementUtil.closeConnection(connection);
}
return claimMapping;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.
the class CacheBackedApplicationDAO method getAllRequestedClaimsByServiceProvider.
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
ServiceProvider applicationFromCache = getApplicationFromCache(serviceProviderName, tenantDomain);
if (applicationFromCache != null) {
List<String> requestedLocalClaims = new ArrayList<>();
ClaimConfig claimConfig = applicationFromCache.getClaimConfig();
ClaimMapping[] claimMappings = claimConfig.getClaimMappings();
for (ClaimMapping claimMapping : claimMappings) {
if (claimMapping.isRequested()) {
requestedLocalClaims.add(claimMapping.getLocalClaim().getClaimUri());
}
}
return requestedLocalClaims;
}
return appDAO.getAllRequestedClaimsByServiceProvider(serviceProviderName, tenantDomain);
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.
the class FileBasedApplicationDAO method getAllRequestedClaimsByServiceProvider.
@Override
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
List<String> requestedClaimList = new ArrayList<String>();
if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
return requestedClaimList;
}
ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();
if (claimMappings != null && claimMappings.length > 0) {
for (ClaimMapping mapping : claimMappings) {
if (mapping.isRequested()) {
if (mapping.getRemoteClaim() != null && mapping.getRemoteClaim().getClaimUri() != null) {
requestedClaimList.add(mapping.getRemoteClaim().getClaimUri());
} else if (mapping.getLocalClaim() != null && mapping.getLocalClaim().getClaimUri() != null) {
requestedClaimList.add(mapping.getLocalClaim().getClaimUri());
}
}
}
}
return requestedClaimList;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.
the class ClaimMetadataHandler method getMappingsFromOtherDialectToCarbon.
/**
* @param otherDialectURI
* @param otherClaimURIs
* @param tenantDomain
* @return
* @throws ClaimMetadataException
*/
public Set<ExternalClaim> getMappingsFromOtherDialectToCarbon(String otherDialectURI, Set<String> otherClaimURIs, String tenantDomain) throws ClaimMetadataException {
Set<ExternalClaim> returnSet = new HashSet<ExternalClaim>();
if (otherDialectURI == null) {
String message = "Invalid argument: \'otherDialectURI\' is \'NULL\'";
log.error(message);
throw new ClaimMetadataException(message);
}
try {
ClaimMetadataManagementServiceImpl claimMetadataService = new ClaimMetadataManagementServiceImpl();
if (otherDialectURI.equals(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
List<LocalClaim> localClaims = claimMetadataService.getLocalClaims(tenantDomain);
if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
for (LocalClaim localClaim : localClaims) {
ExternalClaim claimMapping = new ExternalClaim(localClaim.getClaimDialectURI(), localClaim.getClaimURI(), localClaim.getClaimURI());
returnSet.add(claimMapping);
}
return returnSet;
} else {
for (LocalClaim localClaim : localClaims) {
if (otherClaimURIs.contains(localClaim.getClaimURI())) {
ExternalClaim claimMapping = new ExternalClaim(otherDialectURI, localClaim.getClaimURI(), localClaim.getClaimURI());
returnSet.add(claimMapping);
}
}
return returnSet;
}
} else {
List<ExternalClaim> externalClaims = claimMetadataService.getExternalClaims(otherDialectURI, tenantDomain);
if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
returnSet = new HashSet<ExternalClaim>(externalClaims);
} else {
for (ExternalClaim externalClaim : externalClaims) {
if (otherClaimURIs.contains(externalClaim.getClaimURI())) {
returnSet.add(externalClaim);
}
}
}
return returnSet;
}
} catch (ClaimMetadataException e) {
throw new ClaimMetadataException(e.getMessage(), e);
}
}
Aggregations