use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class LocalClaimDAO method updateLocalClaim.
public void updateLocalClaim(LocalClaim localClaim, int tenantId) throws ClaimMetadataException {
Connection connection = IdentityDatabaseUtil.getDBConnection();
PreparedStatement prepStmt = null;
String localClaimURI = localClaim.getClaimURI();
try {
// Start transaction
connection.setAutoCommit(false);
int localClaimId = getClaimId(connection, ClaimConstants.LOCAL_CLAIM_DIALECT_URI, localClaimURI, tenantId);
// TODO : Handle invalid local claim URI
deleteClaimAttributeMappings(connection, localClaimId, tenantId);
addClaimAttributeMappings(connection, localClaimId, localClaim.getMappedAttributes(), tenantId);
deleteClaimProperties(connection, localClaimId, tenantId);
addClaimProperties(connection, localClaimId, localClaim.getClaimProperties(), tenantId);
// End transaction
connection.commit();
} catch (SQLException e) {
rollbackTransaction(connection);
throw new ClaimMetadataException("Error while updating local claim " + localClaimURI, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, null, null);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class LocalClaimDAO method addClaimAttributeMappings.
private void addClaimAttributeMappings(Connection connection, int localClaimId, List<AttributeMapping> attributeMappings, int tenantId) throws ClaimMetadataException {
PreparedStatement prepStmt = null;
if (localClaimId > 0 && attributeMappings != null) {
try {
String query = SQLConstants.ADD_CLAIM_MAPPED_ATTRIBUTE;
prepStmt = connection.prepareStatement(query);
for (AttributeMapping attributeMapping : attributeMappings) {
if (StringUtils.isBlank(attributeMapping.getUserStoreDomain())) {
throw new ClaimMetadataException("User store domain of mapped Attribute cannot be empty for " + "the local claim id : " + localClaimId);
} else if (StringUtils.isBlank(attributeMapping.getAttributeName())) {
throw new ClaimMetadataException("Mapped attribute of the local claim id : " + localClaimId + " cannot be empty");
}
prepStmt.setInt(1, localClaimId);
prepStmt.setString(2, attributeMapping.getUserStoreDomain());
prepStmt.setString(3, attributeMapping.getAttributeName());
prepStmt.setInt(4, tenantId);
prepStmt.addBatch();
}
prepStmt.executeBatch();
} catch (SQLException e) {
throw new ClaimMetadataException("Error while adding attribute mappings", e);
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt);
}
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class DefaultClaimMetadataStore method getMappedAttribute.
private String getMappedAttribute(String domainName, LocalClaim localClaim, int tenantId) throws UserStoreException {
String mappedAttribute = localClaim.getMappedAttribute(domainName);
if (StringUtils.isNotBlank(mappedAttribute)) {
if (log.isDebugEnabled()) {
log.debug("Assigned mapped attribute : " + mappedAttribute + " from user store domain : " + domainName + " for claim : " + localClaim.getClaimURI() + " in tenant : " + tenantId);
}
return mappedAttribute;
}
mappedAttribute = localClaim.getClaimProperty(ClaimConstants.DEFAULT_ATTRIBUTE);
if (StringUtils.isNotBlank(mappedAttribute)) {
if (log.isDebugEnabled()) {
log.debug("Assigned mapped attribute : " + mappedAttribute + " from " + ClaimConstants.DEFAULT_ATTRIBUTE + " property for claim : " + localClaim.getClaimURI() + " in tenant : " + tenantId);
}
return mappedAttribute;
}
UserRealm realm = IdentityClaimManagementServiceDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
String primaryDomainName = realm.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
mappedAttribute = localClaim.getMappedAttribute(primaryDomainName);
if (StringUtils.isNotBlank(mappedAttribute)) {
if (log.isDebugEnabled()) {
log.debug("Assigned mapped attribute : " + mappedAttribute + " from primary user store domain : " + primaryDomainName + " for claim : " + localClaim.getClaimURI() + " in tenant : " + tenantId);
}
return mappedAttribute;
} else {
throw new IllegalStateException("Cannot find suitable mapped attribute for local claim " + localClaim.getClaimURI());
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UserRealmProxy method getUserRealmInfo.
public UserRealmInfo getUserRealmInfo() throws UserAdminException {
UserRealmInfo userRealmInfo = new UserRealmInfo();
String userName = CarbonContext.getThreadLocalCarbonContext().getUsername();
try {
RealmConfiguration realmConfig = realm.getRealmConfiguration();
if (realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/usermgt/users", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/usermgt/passwords", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/usermgt/view", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/rolemgt/view", CarbonConstants.UI_PERMISSION_ACTION)) {
userRealmInfo.setAdminRole(realmConfig.getAdminRoleName());
userRealmInfo.setAdminUser(realmConfig.getAdminUserName());
userRealmInfo.setEveryOneRole(realmConfig.getEveryOneRoleName());
ClaimMapping[] defaultClaims = realm.getClaimManager().getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT);
if (ArrayUtils.isNotEmpty(defaultClaims)) {
Arrays.sort(defaultClaims, new ClaimMappingsComparator());
}
List<String> fullClaimList = new ArrayList<String>();
List<String> requiredClaimsList = new ArrayList<String>();
List<String> defaultClaimList = new ArrayList<String>();
for (ClaimMapping claimMapping : defaultClaims) {
Claim claim = claimMapping.getClaim();
fullClaimList.add(claim.getClaimUri());
if (claim.isRequired()) {
requiredClaimsList.add(claim.getClaimUri());
}
if (claim.isSupportedByDefault()) {
defaultClaimList.add(claim.getClaimUri());
}
}
userRealmInfo.setUserClaims(fullClaimList.toArray(new String[fullClaimList.size()]));
userRealmInfo.setRequiredUserClaims(requiredClaimsList.toArray(new String[requiredClaimsList.size()]));
userRealmInfo.setDefaultUserClaims(defaultClaimList.toArray(new String[defaultClaimList.size()]));
}
List<UserStoreInfo> storeInfoList = new ArrayList<UserStoreInfo>();
List<String> domainNames = new ArrayList<String>();
RealmConfiguration secondaryConfig = realmConfig;
UserStoreManager secondaryManager = realm.getUserStoreManager();
while (true) {
secondaryConfig = secondaryManager.getRealmConfiguration();
UserStoreInfo userStoreInfo = getUserStoreInfo(secondaryConfig, secondaryManager);
if (secondaryConfig.isPrimary()) {
userRealmInfo.setPrimaryUserStoreInfo(userStoreInfo);
}
storeInfoList.add(userStoreInfo);
userRealmInfo.setBulkImportSupported(secondaryManager.isBulkImportSupported());
String domainName = secondaryConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
if (domainName != null && domainName.trim().length() > 0) {
domainNames.add(domainName.toUpperCase());
}
secondaryManager = secondaryManager.getSecondaryUserStoreManager();
if (secondaryManager == null) {
break;
}
}
if (storeInfoList.size() > 1) {
userRealmInfo.setMultipleUserStore(true);
}
userRealmInfo.setUserStoresInfo(storeInfoList.toArray(new UserStoreInfo[storeInfoList.size()]));
userRealmInfo.setDomainNames(domainNames.toArray(new String[domainNames.size()]));
String itemsPerPageString = realmConfig.getRealmProperty("MaxItemsPerUserMgtUIPage");
int itemsPerPage = 15;
try {
itemsPerPage = Integer.parseInt(itemsPerPageString);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Error parsing number of items per page, using default value", e);
}
}
userRealmInfo.setMaxItemsPerUIPage(itemsPerPage);
String maxPageInCacheString = realmConfig.getRealmProperty("MaxUserMgtUIPagesInCache");
int maxPagesInCache = 6;
try {
maxPagesInCache = Integer.parseInt(maxPageInCacheString);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Error parsing number of maximum pages in cache, using default value", e);
}
}
userRealmInfo.setMaxUIPagesInCache(maxPagesInCache);
String enableUIPageCacheString = realmConfig.getRealmProperty("EnableUserMgtUIPageCache");
boolean enableUIPageCache = true;
if (FALSE.equals(enableUIPageCacheString)) {
enableUIPageCache = false;
}
userRealmInfo.setEnableUIPageCache(enableUIPageCache);
} catch (Exception e) {
// previously logged so logging not needed
throw new UserAdminException(e.getMessage(), e);
}
return userRealmInfo;
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UserRealmProxyTest method getSampleClaims.
private ClaimValue[] getSampleClaims() {
Claim claim = new Claim();
claim.setClaimUri("testURI");
claim.setValue("testClaim");
ClaimValue claimValue = new ClaimValue();
claimValue.setClaimURI("testURI");
claimValue.setValue("testClaim");
return new ClaimValue[] { claimValue };
}
Aggregations