Search in sources :

Example 1 with AttributeMapping

use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project siddhi by wso2.

the class InputEventHandler method sendEvents.

public void sendEvents(Event[] events) throws InterruptedException {
    try {
        if (latencyTracker != null && siddhiAppContext.isStatsEnabled()) {
            latencyTracker.markOut();
        }
        String[] transportProperties = trpProperties.get();
        trpProperties.remove();
        long currentTimestamp = timestampGenerator.currentTime();
        for (Event event : events) {
            if (event.getTimestamp() == -1) {
                event.setTimestamp(currentTimestamp);
            }
            for (int i = 0; i < transportMapping.size(); i++) {
                AttributeMapping attributeMapping = transportMapping.get(i);
                event.getData()[attributeMapping.getPosition()] = transportProperties[i];
            }
        }
        inputEventHandlerCallback.sendEvents(events);
    } catch (RuntimeException e) {
        LOG.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) + " Error in applying transport property mapping for '" + sourceType + "' source at '" + inputHandler.getStreamId() + "' stream.", e);
    } finally {
        trpProperties.remove();
    }
}
Also used : Event(org.wso2.siddhi.core.event.Event)

Example 2 with AttributeMapping

use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.

the class LocalClaimDAO method getClaimAttributeMappingsOfDialect.

private Map<Integer, List<AttributeMapping>> getClaimAttributeMappingsOfDialect(Connection connection, String claimDialectURI, int tenantId) throws ClaimMetadataException {
    Map<Integer, List<AttributeMapping>> attributeMappings = new HashMap<>();
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        preparedStatement = connection.prepareStatement(SQLConstants.GET_MAPPED_ATTRIBUTES);
        preparedStatement.setString(1, claimDialectURI);
        preparedStatement.setInt(2, tenantId);
        preparedStatement.setInt(3, tenantId);
        preparedStatement.setInt(4, tenantId);
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            String userStoreDomainName = resultSet.getString(SQLConstants.USER_STORE_DOMAIN_NAME_COLUMN);
            String attributeName = resultSet.getString(SQLConstants.ATTRIBUTE_NAME_COLUMN);
            int localClaimId = resultSet.getInt(SQLConstants.LOCAL_CLAIM_ID_COLUMN);
            AttributeMapping attributeMapping = new AttributeMapping(userStoreDomainName, attributeName);
            List<AttributeMapping> existingAttributeMapping = attributeMappings.get(localClaimId);
            if (existingAttributeMapping == null) {
                existingAttributeMapping = new ArrayList<>();
            }
            existingAttributeMapping.add(attributeMapping);
            attributeMappings.put(localClaimId, existingAttributeMapping);
        }
    } catch (SQLException e) {
        throw new ClaimMetadataException("Error occurred while retrieving attribute mappings.", e);
    } finally {
        IdentityDatabaseUtil.closeResultSet(resultSet);
        IdentityDatabaseUtil.closeStatement(preparedStatement);
    }
    return attributeMappings;
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AttributeMapping

use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping 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 4 with AttributeMapping

use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.

the class ClaimMetadataUtils method convertLocalClaimToLocalClaimDTO.

public static LocalClaimDTO convertLocalClaimToLocalClaimDTO(LocalClaim localClaim) {
    LocalClaimDTO localClaimDTO = new LocalClaimDTO();
    localClaimDTO.setLocalClaimURI(localClaim.getClaimURI());
    // Convert List<AttributeMapping> to AttributeMappingDTO[]
    List<AttributeMapping> attributeMappings = localClaim.getMappedAttributes();
    AttributeMappingDTO[] attributeMappingDTOs = new AttributeMappingDTO[attributeMappings.size()];
    int i = 0;
    for (AttributeMapping attributeMapping : attributeMappings) {
        AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
        attributeMappingDTO.setUserStoreDomain(attributeMapping.getUserStoreDomain());
        attributeMappingDTO.setAttributeName(attributeMapping.getAttributeName());
        attributeMappingDTOs[i] = attributeMappingDTO;
        i++;
    }
    localClaimDTO.setAttributeMappings(attributeMappingDTOs);
    // Convert Map<String, String> to ClaimPropertyDTO[]
    Map<String, String> claimProperties = localClaim.getClaimProperties();
    ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[claimProperties.size()];
    int j = 0;
    for (Map.Entry<String, String> claimPropertyEntry : claimProperties.entrySet()) {
        ClaimPropertyDTO claimProperty = new ClaimPropertyDTO();
        claimProperty.setPropertyName(claimPropertyEntry.getKey());
        claimProperty.setPropertyValue(claimPropertyEntry.getValue());
        claimPropertyDTOs[j] = claimProperty;
        j++;
    }
    localClaimDTO.setClaimProperties(claimPropertyDTOs);
    return localClaimDTO;
}
Also used : ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) AttributeMappingDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) HashMap(java.util.HashMap) Map(java.util.Map) LocalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)

Example 5 with AttributeMapping

use of org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping in project carbon-identity-framework by wso2.

the class ClaimMetadataUtils method convertLocalClaimDTOToLocalClaim.

public static LocalClaim convertLocalClaimDTOToLocalClaim(LocalClaimDTO localClaimDTO) {
    // TODO : Validate if localClaimDTO null???
    LocalClaim localClaim = new LocalClaim(localClaimDTO.getLocalClaimURI());
    // Convert AttributeMappingDTO[] to List<AttributeMapping>
    if (localClaimDTO.getAttributeMappings() != null) {
        List<AttributeMapping> attributeMappings = new ArrayList<>();
        for (AttributeMappingDTO attributeMappingDTO : localClaimDTO.getAttributeMappings()) {
            attributeMappings.add(new AttributeMapping(attributeMappingDTO.getUserStoreDomain(), attributeMappingDTO.getAttributeName()));
        }
        localClaim.setMappedAttributes(attributeMappings);
    }
    // Convert ClaimPropertyDTO[] to Map<String, String>
    if (localClaimDTO.getClaimProperties() != null) {
        Map<String, String> claimProperties = new HashMap<>();
        for (ClaimPropertyDTO claimPropertyDTO : localClaimDTO.getClaimProperties()) {
            claimProperties.put(claimPropertyDTO.getPropertyName(), claimPropertyDTO.getPropertyValue());
        }
        localClaim.setClaimProperties(claimProperties);
    }
    return localClaim;
}
Also used : ClaimPropertyDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO) AttributeMappingDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO) HashMap(java.util.HashMap) AttributeMapping(org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Aggregations

AttributeMapping (org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping)20 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11 List (java.util.List)5 Map (java.util.Map)5 Test (org.testng.annotations.Test)5 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)4 ClaimMapping (org.wso2.carbon.user.core.claim.ClaimMapping)4 SQLException (java.sql.SQLException)3 AttributeMappingDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO)3 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO)3 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 BeforeClass (org.testng.annotations.BeforeClass)2 LocalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.LocalClaimDTO)2 ClaimDialect (org.wso2.carbon.identity.claim.metadata.mgt.model.ClaimDialect)2 AttributeMappingDTO (org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO)2 Method (java.lang.reflect.Method)1