use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class JDBCUserStoreCountRetriever method countClaim.
@Override
public Long countClaim(String claimURI, String valueFilter) throws UserStoreCounterException {
Connection dbConnection = null;
String sqlStmt = null;
PreparedStatement prepStmt = null;
ResultSet resultSet = null;
String mappedAttribute = null;
try {
String domainName = realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
if (StringUtils.isEmpty(domainName)) {
domainName = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
}
UserRealm userRealm = UserStoreCountDSComponent.getRealmService().getTenantUserRealm(tenantId);
if (StringUtils.isNotEmpty(claimURI)) {
mappedAttribute = userRealm.getClaimManager().getAttributeName(domainName, claimURI);
}
dbConnection = getDBConnection(realmConfiguration);
sqlStmt = JDBCUserStoreMetricsConstants.COUNT_CLAIM_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setString(1, mappedAttribute);
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, "%" + valueFilter + "%");
prepStmt.setString(4, UserCoreConstants.DEFAULT_PROFILE);
prepStmt.setQueryTimeout(searchTime);
resultSet = prepStmt.executeQuery();
dbConnection.commit();
if (resultSet.next()) {
return resultSet.getLong("RESULT");
} else {
log.error("No claim count is retrieved from the user store.");
return Long.valueOf(-1);
}
} catch (SQLException e) {
rollbackTransaction(dbConnection);
if (log.isDebugEnabled()) {
log.debug("Using sql : " + sqlStmt);
}
throw new UserStoreCounterException(e.getMessage(), e);
} catch (Exception e) {
throw new UserStoreCounterException(e.getMessage(), e);
} finally {
DatabaseUtil.closeAllConnections(dbConnection, resultSet, prepStmt);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UserStoreCountService method countClaim.
/**
* Get the count of users having claim values matching the given filter for the given claim URI
*
* @param claimURI the claim URI
* @param valueFilter filter for the claim values
* @return the number of users matching the given claim and filter by each domain
*/
public PairDTO[] countClaim(String claimURI, String valueFilter) throws UserStoreCounterException {
Set<String> userStoreDomains = UserStoreCountUtils.getCountEnabledUserStores();
PairDTO[] claimCounts = new PairDTO[userStoreDomains.size()];
int i = 0;
for (String userStoreDomain : userStoreDomains) {
long count = -1L;
String filterWithDomain = getFilterWithDomain(userStoreDomain, valueFilter);
try {
count = getUserCountWithClaims(claimURI, filterWithDomain);
} catch (UserStoreCounterException e) {
log.error("Error while getting user count with claim : " + claimURI + ", from user store domain : " + userStoreDomain, e);
}
claimCounts[i] = new PairDTO(userStoreDomain, Long.toString(count));
i++;
}
return claimCounts;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method getLocalClaimValuesOfIDPInNonAttributeSelectionStep.
/**
* Uses to get local claim values of an authenticated user from an IDP in non attribute selection steps.
*
* @param context Authentication Context.
* @param stepConfig Current step configuration.
* @param externalIdPConfig Identity providers config.
* @return Mapped federated user values to local claims.
* @throws PostAuthenticationFailedException Post Authentication failed exception.
*/
private Map<String, String> getLocalClaimValuesOfIDPInNonAttributeSelectionStep(AuthenticationContext context, StepConfig stepConfig, ExternalIdPConfig externalIdPConfig) throws PostAuthenticationFailedException {
boolean useDefaultIdpDialect = externalIdPConfig.useDefaultLocalIdpDialect();
ApplicationAuthenticator authenticator = stepConfig.getAuthenticatedAutenticator().getApplicationAuthenticator();
String idPStandardDialect = authenticator.getClaimDialectURI();
Map<ClaimMapping, String> extAttrs = stepConfig.getAuthenticatedUser().getUserAttributes();
Map<String, String> originalExternalAttributeValueMap = FrameworkUtils.getClaimMappings(extAttrs, false);
Map<String, String> claimMapping = new HashMap<>();
Map<String, String> localClaimValues = new HashMap<>();
if (useDefaultIdpDialect && StringUtils.isNotBlank(idPStandardDialect)) {
try {
claimMapping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(idPStandardDialect, originalExternalAttributeValueMap.keySet(), context.getTenantDomain(), true);
} catch (ClaimMetadataException e) {
throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_HANDLING_CLAIM_MAPPINGS.getCode(), ErrorMessages.ERROR_WHILE_HANDLING_CLAIM_MAPPINGS.getMessage(), e);
}
} else {
ClaimMapping[] customClaimMapping = context.getExternalIdP().getClaimMappings();
for (ClaimMapping externalClaim : customClaimMapping) {
if (originalExternalAttributeValueMap.containsKey(externalClaim.getRemoteClaim().getClaimUri())) {
claimMapping.put(externalClaim.getLocalClaim().getClaimUri(), externalClaim.getRemoteClaim().getClaimUri());
}
}
}
if (claimMapping != null && claimMapping.size() > 0) {
for (Map.Entry<String, String> entry : claimMapping.entrySet()) {
if (originalExternalAttributeValueMap.containsKey(entry.getValue()) && originalExternalAttributeValueMap.get(entry.getValue()) != null) {
localClaimValues.put(entry.getKey(), originalExternalAttributeValueMap.get(entry.getValue()));
}
}
}
return localClaimValues;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method getUserIdClaimUriInLocalDialect.
private String getUserIdClaimUriInLocalDialect(ExternalIdPConfig idPConfig) {
// get external identity provider user id claim URI.
String userIdClaimUri = idPConfig.getUserIdClaimUri();
if (StringUtils.isBlank(userIdClaimUri)) {
return null;
}
boolean useDefaultLocalIdpDialect = idPConfig.useDefaultLocalIdpDialect();
if (useDefaultLocalIdpDialect) {
return userIdClaimUri;
} else {
ClaimMapping[] claimMappings = idPConfig.getClaimMappings();
if (!ArrayUtils.isEmpty(claimMappings)) {
for (ClaimMapping claimMapping : claimMappings) {
if (userIdClaimUri.equals(claimMapping.getRemoteClaim().getClaimUri())) {
return claimMapping.getLocalClaim().getClaimUri();
}
}
}
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method isAccountDisabled.
/**
* Uses to check whether associated users account is disabled or not.
*
* @param username Username of the associated user.
* @return Whether user is disabled or not.
* @throws PostAuthenticationFailedException When getting claim value.
*/
private boolean isAccountDisabled(String username, String tenantDomain) throws PostAuthenticationFailedException {
try {
UserRealm realm = (UserRealm) FrameworkServiceDataHolder.getInstance().getRealmService().getTenantUserRealm(IdentityTenantUtil.getTenantId(tenantDomain));
UserStoreManager userStoreManager = realm.getUserStoreManager();
Map<String, String> claimValues = userStoreManager.getUserClaimValues(username, new String[] { AccountConstants.ACCOUNT_DISABLED_CLAIM }, UserCoreConstants.DEFAULT_PROFILE);
if (claimValues != null && claimValues.size() > 0) {
String accountDisabledClaim = claimValues.get(AccountConstants.ACCOUNT_DISABLED_CLAIM);
return Boolean.parseBoolean(accountDisabledClaim);
}
} catch (UserStoreException e) {
throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_CHECKING_ACCOUNT_DISABLE_STATUS.getCode(), String.format(ErrorMessages.ERROR_WHILE_CHECKING_ACCOUNT_DISABLE_STATUS.getMessage(), username), e);
}
return false;
}
Aggregations