Search in sources :

Example 61 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim 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;
}
Also used : HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)

Example 62 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method isClaimReferredByAnySp.

@Override
public boolean isClaimReferredByAnySp(Connection dbConnection, String claimUri, int tenantId) throws IdentityApplicationManagementException {
    boolean dbConnInitialized = true;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    boolean isClaimReferred = false;
    if (dbConnection == null) {
        dbConnection = IdentityDatabaseUtil.getDBConnection(false);
    } else {
        dbConnInitialized = false;
    }
    try {
        String sqlStmt = ApplicationMgtDBQueries.GET_TOTAL_SP_CLAIM_USAGES;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, claimUri);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            isClaimReferred = rs.getInt(1) > 0;
        }
        return isClaimReferred;
    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error occurred while retrieving application usages of " + "the claim " + claimUri, e);
    } finally {
        if (dbConnInitialized) {
            IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        } else {
            IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
        }
    }
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)

Example 63 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.

the class ApplicationDAOImpl method getAllRequestedClaimsByServiceProvider.

@Override
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws 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");
        }
    }
    List<String> reqClaimUris = new ArrayList<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 ("1".equalsIgnoreCase(resultSet.getString(3))) {
                reqClaimUris.add(resultSet.getString(1));
            }
        }
    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error while retrieving requested claims", e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(getClaimPreStmt);
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
    return reqClaimUris;
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)

Example 64 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getAllRequestedClaimsByServiceProvider.

/**
 * Returns back the requested set of claims by the provided service provider in local idp claim
 * dialect.
 *
 * @param serviceProviderName
 * @param tenantDomain
 * @return
 * @throws IdentityApplicationManagementException
 */
@Override
public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    List<String> reqClaims = appDAO.getAllRequestedClaimsByServiceProvider(serviceProviderName, tenantDomain);
    if (reqClaims == null || reqClaims.isEmpty() && ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(serviceProviderName)) {
        return new FileBasedApplicationDAO().getAllRequestedClaimsByServiceProvider(serviceProviderName, tenantDomain);
    }
    return reqClaims;
}
Also used : FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 65 with Claim

use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.

the class ClaimMetadataManagementAdminService method updateLocalClaim.

@SuppressWarnings("unused")
public void updateLocalClaim(LocalClaimDTO localClaim) throws ClaimMetadataException {
    try {
        LocalClaim claim = ClaimMetadataUtils.convertLocalClaimDTOToLocalClaim(localClaim);
        String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().updateLocalClaim(claim, tenantDomain);
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Aggregations

HashMap (java.util.HashMap)112 ArrayList (java.util.ArrayList)90 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)67 UserStoreException (org.wso2.carbon.user.api.UserStoreException)66 Test (org.testng.annotations.Test)63 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)55 Map (java.util.Map)50 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 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)29 Claim (org.wso2.carbon.user.api.Claim)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 ResultSet (java.sql.ResultSet)27 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)26 Connection (java.sql.Connection)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)24