Search in sources :

Example 81 with Claim

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);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 82 with Claim

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);
        }
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) SQLException(java.sql.SQLException) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) PreparedStatement(java.sql.PreparedStatement)

Example 83 with Claim

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());
    }
}
Also used : UserRealm(org.wso2.carbon.user.api.UserRealm)

Example 84 with Claim

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;
}
Also used : UserStoreInfo(org.wso2.carbon.user.mgt.common.UserStoreInfo) ArrayList(java.util.ArrayList) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) JDBCUserStoreManager(org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) RegistryException(org.wso2.carbon.registry.api.RegistryException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) UserRealmInfo(org.wso2.carbon.user.mgt.common.UserRealmInfo) Claim(org.wso2.carbon.user.api.Claim)

Example 85 with Claim

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 };
}
Also used : ClaimValue(org.wso2.carbon.user.mgt.common.ClaimValue) Claim(org.wso2.carbon.user.api.Claim)

Aggregations

HashMap (java.util.HashMap)112 ArrayList (java.util.ArrayList)89 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)66 UserStoreException (org.wso2.carbon.user.api.UserStoreException)65 Test (org.testng.annotations.Test)63 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)55 Map (java.util.Map)49 PreparedStatement (java.sql.PreparedStatement)48 SQLException (java.sql.SQLException)43 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)34 RealmService (org.wso2.carbon.user.core.service.RealmService)30 UserRealm (org.wso2.carbon.user.core.UserRealm)29 Claim (org.wso2.carbon.user.api.Claim)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)28 ResultSet (java.sql.ResultSet)27 Connection (java.sql.Connection)25 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)24