Java源码示例:org.wso2.carbon.user.api.ClaimMapping

示例1
@Override
@Deprecated
public ClaimMapping[] getAllSupportClaimMappingsByDefault() throws UserStoreException {

    try {
        List<LocalClaim> localClaims = localClaimDAO.getLocalClaims(this.tenantId);

        List<ClaimMapping> claimMappings = new ArrayList<>();

        for (LocalClaim localClaim : localClaims) {
            ClaimMapping claimMapping = ClaimMetadataUtils.convertLocalClaimToClaimMapping(localClaim, this
                    .tenantId);

            if (claimMapping.getClaim().isSupportedByDefault()) {
                claimMappings.add(claimMapping);
            }
        }

        return claimMappings.toArray(new ClaimMapping[0]);
    } catch (ClaimMetadataException e) {
        throw new UserStoreException(e.getMessage(), e);
    }
}
 
示例2
@Override
@Deprecated
public ClaimMapping[] getAllRequiredClaimMappings() throws UserStoreException {

    try {
        List<LocalClaim> localClaims = localClaimDAO.getLocalClaims(this.tenantId);

        List<ClaimMapping> claimMappings = new ArrayList<>();

        for (LocalClaim localClaim : localClaims) {
            ClaimMapping claimMapping = ClaimMetadataUtils.convertLocalClaimToClaimMapping(localClaim, this
                    .tenantId);

            if (claimMapping.getClaim().isRequired()) {
                claimMappings.add(claimMapping);
            }
        }

        return claimMappings.toArray(new ClaimMapping[0]);
    } catch (ClaimMetadataException e) {
        throw new UserStoreException(e.getMessage(), e);
    }
}
 
示例3
private ClaimMappingDTO convertClaimMappingToClaimMappingDTO(ClaimMapping claimMapping) {
    ClaimMappingDTO claimMappingDTO = new ClaimMappingDTO();
    claimMappingDTO.setClaim(convertClaimToClaimDTO(claimMapping.getClaim()));
    claimMappingDTO.setMappedAttribute(claimMapping.getMappedAttribute());

    Map<String, String> attributes = claimMapping.getMappedAttributes();

    if (attributes != null) {
        ClaimAttributeDTO[] attrDto = new ClaimAttributeDTO[attributes.size()];
        int i = 0;
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            ClaimAttributeDTO dto = new ClaimAttributeDTO();
            dto.setAttributeName(entry.getValue());
            dto.setDomainName(entry.getKey());
            attrDto[i++] = dto;
        }
        claimMappingDTO.setMappedAttributes(attrDto);
    }

    return claimMappingDTO;
}
 
示例4
private ClaimMapping convertClaimMappingDTOToClaimMapping(ClaimMappingDTO claimMappingDTO) {
    ClaimMapping claimMapping = new ClaimMapping(
            convertClaimDTOToClaim(claimMappingDTO.getClaim()),
            claimMappingDTO.getMappedAttribute());

    ClaimAttributeDTO[] attributes = claimMappingDTO.getMappedAttributes();

    if (attributes != null) {
        for (ClaimAttributeDTO attribute : attributes) {
            if (attribute.getDomainName() != null) {
                claimMapping.setMappedAttribute(attribute.getDomainName(),
                                                attribute.getAttributeName());
            }
        }
    }

    return claimMapping;
}
 
示例5
@Override
public String[] getAllLocalClaimUris(String tenantDomain) throws IdentityApplicationManagementException {

    try {
        startTenantFlow(tenantDomain);
        String claimDialect = ApplicationMgtSystemConfig.getInstance().getClaimDialect();
        ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager()
                .getAllClaimMappings(claimDialect);
        List<String> claimUris = new ArrayList<>();
        for (ClaimMapping claimMap : claimMappings) {
            claimUris.add(claimMap.getClaim().getClaimUri());
        }
        String[] allLocalClaimUris = (claimUris.toArray(new String[claimUris.size()]));
        if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
            Arrays.sort(allLocalClaimUris);
        }
        return allLocalClaimUris;
    } catch (Exception e) {
        String error = "Error while reading system claims" + ". " + e.getMessage();
        throw new IdentityApplicationManagementException(error, e);
    } finally {
        endTenantFlow();
    }
}
 
示例6
/**
 * Returns all supported claims.
 *
 * @param realm user realm
 * @return array of all supported claims
 * @throws IdentityException if error occurs while building supported claims
 */
public Claim[] getAllSupportedClaims(UserRealm realm) throws IdentityException {
    try {
        ClaimManager claimAdmin = realm.getClaimManager();
        ClaimMapping[] mappings = claimAdmin.getAllSupportClaimMappingsByDefault();
        Claim[] claims = new Claim[0];
        if (mappings != null) {
            claims = new Claim[mappings.length];
            for (int i = 0; i < mappings.length; i++) {
                claims[i] = (Claim) mappings[i].getClaim();
            }
        }
        return claims;
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        log.error("Error occurred while loading supported claims", e);
        getException("Error occurred while loading supported claima", e);
    }

    return new Claim[0];
}
 
示例7
@Test
public void testGetUserRealmInfo() throws Exception {
    Mockito.when(realm.getAuthorizationManager()).thenReturn(authorizationManager);
    Mockito.when(realm.getClaimManager()).thenReturn(claimManager);
    Mockito.when(authorizationManager.isUserAuthorized("admin",
            "/permission/admin/manage/identity", CarbonConstants.UI_PERMISSION_ACTION)).thenReturn(true);
    Mockito.when(realm.getRealmConfiguration()).thenReturn(this.getSampleRelaimConfiguration());
    Mockito.when(realm.getUserStoreManager()).thenReturn(userStoreManagerWithAb);
    ClaimMapping claimMapping = new ClaimMapping();
    claimMapping.setMappedAttribute("test1");
    claimMapping.setMappedAttribute("test2");
    claimMapping.setMappedAttribute("test3");
    Claim claim = new Claim();
    claim.setClaimUri("testURI");
    claim.setValue("testClaim");
    claimMapping.setClaim(claim);

    Mockito.when(claimManager.getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT))
            .thenReturn(new ClaimMapping[]{claimMapping});
    Mockito.when(userStoreManagerWithAb.getRealmConfiguration()).thenReturn(this.getSampleRelaimConfiguration());
    Mockito.when(userStoreManagerWithAb.isBulkImportSupported()).thenReturn(false);
    UserRealmInfo realmInfo = userRealmProxy.getUserRealmInfo();
    Assert.assertEquals(realmInfo.getEveryOneRole(), "everyone");
    Assert.assertEquals(realmInfo.getAdminRole(), "admin");
}
 
示例8
/**
 * @return
 * @throws UserStoreException
 */
private Claim[] getAllSupportedClaims(UserRealm realm, String dialectUri)
        throws org.wso2.carbon.user.api.UserStoreException {
    ClaimMapping[] claims = null;
    List<Claim> reqClaims = null;

    claims = realm.getClaimManager().getAllSupportClaimMappingsByDefault();
    reqClaims = new ArrayList<Claim>();
    for (int i = 0; i < claims.length; i++) {
        if (dialectUri.equals(claims[i].getClaim().getDialectURI()) && (claims[i] != null && claims[i].getClaim().getDisplayTag() != null
                && !claims[i].getClaim().getClaimUri().equals(IdentityConstants.CLAIM_PPID))) {

            reqClaims.add((Claim) claims[i].getClaim());
        }
    }

    return reqClaims.toArray(new Claim[reqClaims.size()]);
}
 
示例9
/**
 * @return
 * @throws IdentityProviderManagementException
 */
public String[] getAllLocalClaimUris() throws IdentityProviderManagementException {

    try {
        String claimDialect = LOCAL_DEFAULT_CLAIM_DIALECT;
        ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext()
                .getUserRealm().getClaimManager().getAllClaimMappings(claimDialect);
        List<String> claimUris = new ArrayList<String>();
        for (ClaimMapping claimMap : claimMappings) {
            claimUris.add(claimMap.getClaim().getClaimUri());
        }
        String[] allLocalClaimUris = claimUris.toArray(new String[0]);
        if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
            Arrays.sort(allLocalClaimUris);
        }
        return allLocalClaimUris;
    } catch (UserStoreException e) {
        String message = "Error while reading system claims";
        log.error(message, e);
        throw new IdentityProviderManagementException(message, e);
    }
}
 
示例10
private ClaimMappingDTO convertClaimMappingToClaimMappingDTO(ClaimMapping claimMapping) {
    ClaimMappingDTO claimMappingDTO = new ClaimMappingDTO();
    claimMappingDTO.setClaim(convertClaimToClaimDTO(claimMapping.getClaim()));
    claimMappingDTO.setMappedAttribute(claimMapping.getMappedAttribute());

    Map<String, String> attributes = claimMapping.getMappedAttributes();

    if (attributes != null) {
        ClaimAttributeDTO[] attrDto = new ClaimAttributeDTO[attributes.size()];
        int i = 0;
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            ClaimAttributeDTO dto = new ClaimAttributeDTO();
            dto.setAttributeName(entry.getValue());
            dto.setDomainName(entry.getKey());
            attrDto[i++] = dto;
        }
        claimMappingDTO.setMappedAttributes(attrDto);
    }

    return claimMappingDTO;
}
 
示例11
private ClaimMapping convertClaimMappingDTOToClaimMapping(ClaimMappingDTO claimMappingDTO) {
    ClaimMapping claimMapping = new ClaimMapping(
            convertClaimDTOToClaim(claimMappingDTO.getClaim()),
            claimMappingDTO.getMappedAttribute());

    ClaimAttributeDTO[] attributes = claimMappingDTO.getMappedAttributes();

    if (attributes != null) {
        for (ClaimAttributeDTO attribute : attributes) {
            if (attribute.getDomainName() != null) {
                claimMapping.setMappedAttribute(attribute.getDomainName(),
                                                attribute.getAttributeName());
            }
        }
    }

    return claimMapping;
}
 
示例12
@Override
public String[] getAllLocalClaimUris(String tenantDomain) throws IdentityApplicationManagementException {
    try {
        startTenantFlow(tenantDomain);
        String claimDialect = ApplicationMgtSystemConfig.getInstance().getClaimDialect();
        ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager()
                .getAllClaimMappings(claimDialect);
        List<String> claimUris = new ArrayList<>();
        for (ClaimMapping claimMap : claimMappings) {
            claimUris.add(claimMap.getClaim().getClaimUri());
        }
        String[] allLocalClaimUris = (claimUris.toArray(new String[claimUris.size()]));
        if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
            Arrays.sort(allLocalClaimUris);
        }
        return allLocalClaimUris;
    } catch (Exception e) {
        String error = "Error while reading system claims";
        throw new IdentityApplicationManagementException(error, e);
    } finally {
        endTenantFlow();
    }
}
 
示例13
/**
 * Returns all supported claims.
 *
 * @return
 * @throws IdentityException
 */
public Claim[] getAllSupportedClaims(UserRealm realm) throws IdentityException {
    try {
        ClaimManager claimAdmin = realm.getClaimManager();
        ClaimMapping[] mappings = claimAdmin.getAllSupportClaimMappingsByDefault();
        Claim[] claims = new Claim[0];
        if (mappings != null) {
            claims = new Claim[mappings.length];
            for (int i = 0; i < mappings.length; i++) {
                claims[i] = (Claim) mappings[i].getClaim();
            }
        }
        return claims;
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        log.error("Error occurred while loading supported claims", e);
        getException("Error occurred while loading supported claima", e);
    }

    return new Claim[0];
}
 
示例14
@Override
public String[] getDefaultClaims(String endUserName) throws IdentityOAuth2Exception {

    int tenantId = MultitenantConstants.SUPER_TENANT_ID;
    try {
        tenantId = OAuth2Util.getTenantIdFromUserName(endUserName);
        // if no claims were requested, return all
        if(log.isDebugEnabled()){
            log.debug("No claims set requested. Returning all claims in the dialect");
        }
        ClaimManager claimManager =
                OAuthComponentServiceHolder.getRealmService().getTenantUserRealm(tenantId).getClaimManager();
        ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI);
        return claimToString(claims);
    } catch (UserStoreException e) {
        throw new IdentityOAuth2Exception("Error while reading default claims for user : " + endUserName, e);
    }
}
 
示例15
public static org.wso2.carbon.um.ws.api.stub.ClaimMapping[] convertToADBClaimMappings(
        org.wso2.carbon.user.core.claim.ClaimMapping[] claimMappings) {
    if (claimMappings == null) {
        return new org.wso2.carbon.um.ws.api.stub.ClaimMapping[0];
    }
    org.wso2.carbon.um.ws.api.stub.ClaimMapping[] cms = new org.wso2.carbon.um.ws.api.stub.ClaimMapping[claimMappings.length];
    int i = 0;
    for (org.wso2.carbon.user.core.claim.ClaimMapping claimMapping : claimMappings) {
        org.wso2.carbon.um.ws.api.stub.ClaimMapping cm = new org.wso2.carbon.um.ws.api.stub.ClaimMapping();
        cm.setClaim(convertToADBClaim(claimMapping.getClaim()));
        cm.setMappedAttribute(claimMapping.getMappedAttribute());
        cms[i] = cm;
        i++;
    }
    return cms;
}
 
示例16
/**
 * @return
 * @throws UserStoreException
 */
private Claim[] getAllSupportedClaims(UserRealm realm, String dialectUri)
        throws org.wso2.carbon.user.api.UserStoreException {
    ClaimMapping[] claims = null;
    List<Claim> reqClaims = null;

    claims = realm.getClaimManager().getAllSupportClaimMappingsByDefault();
    reqClaims = new ArrayList<Claim>();
    for (int i = 0; i < claims.length; i++) {
        if (dialectUri.equals(claims[i].getClaim().getDialectURI()) && (claims[i] != null && claims[i].getClaim().getDisplayTag() != null
                && !claims[i].getClaim().getClaimUri().equals(IdentityConstants.CLAIM_PPID))) {

            reqClaims.add((Claim) claims[i].getClaim());
        }
    }

    return reqClaims.toArray(new Claim[reqClaims.size()]);
}
 
示例17
/**
 * @return
 * @throws IdentityProviderManagementException
 */
public String[] getAllLocalClaimUris() throws IdentityProviderManagementException {

    try {
        String claimDialect = LOCAL_DEFAULT_CLAIM_DIALECT;
        ClaimMapping[] claimMappings = CarbonContext.getThreadLocalCarbonContext()
                .getUserRealm().getClaimManager().getAllClaimMappings(claimDialect);
        List<String> claimUris = new ArrayList<String>();
        for (ClaimMapping claimMap : claimMappings) {
            claimUris.add(claimMap.getClaim().getClaimUri());
        }
        String[] allLocalClaimUris = claimUris.toArray(new String[claimUris.size()]);
        if (ArrayUtils.isNotEmpty(allLocalClaimUris)) {
            Arrays.sort(allLocalClaimUris);
        }
        return allLocalClaimUris;
    } catch (UserStoreException e) {
        String message = "Error while reading system claims";
        log.error(message, e);
        throw new IdentityProviderManagementException(message, e);
    }
}
 
示例18
public Set<String> getSupportedAttributes() {
    try {
        ClaimManager claimManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager();
        ClaimMapping[] claims = claimManager
                .getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT);
        for (ClaimMapping claim : claims) {
            supportedAttrs.add(claim.getClaim().getClaimUri());
        }
    } catch (Exception e) {
        //ignore
    }
    return supportedAttrs;
}
 
示例19
/**
 * @param
 * @throws ClaimManagementException
 */
public void upateClaimMapping(ClaimMappingDTO claimMappingDTO) throws ClaimManagementException {
    /*Convert the simple structure of ClaimMapping received, to the complex structure
    of ClaimMapping which is used in the back end. */
    ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
    ClaimManagerHandler.getInstance().updateClaimMapping(claimMapping);
}
 
示例20
/**
 * @param
 * @throws ClaimManagementException
 */
public void addNewClaimMapping(ClaimMappingDTO claimMappingDTO) throws ClaimManagementException {
    /*Convert the simple structure of ClaimMapping received, to the complex structure
    of ClaimMapping which is used in the back end. */
    ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
    ClaimManagerHandler handler = ClaimManagerHandler.getInstance();
    ClaimMapping currentMapping = handler.getClaimMapping(
            claimMapping.getClaim().getClaimUri());
    if (currentMapping != null) {
        throw new ClaimManagementException(
                "Duplicate claim exist in the system. Please pick a different Claim Uri");
    }
    handler.addNewClaimMapping(claimMapping);
}
 
示例21
private ClaimMappingDTO[] convertClaimMappingArrayToClaimMappingDTOArray(
        ClaimMapping[] claimMappings) {
    List<ClaimMappingDTO> claimMappingDTOList = new ArrayList<ClaimMappingDTO>();
    for (ClaimMapping claimMapping : claimMappings) {
        ClaimMappingDTO claimMappingDTO = convertClaimMappingToClaimMappingDTO(claimMapping);
        claimMappingDTOList.add(claimMappingDTO);
    }
    return claimMappingDTOList.toArray(new ClaimMappingDTO[claimMappingDTOList.size()]);
}
 
示例22
private ClaimMapping[] convertClaimMappingDTOArrayToClaimMappingArray(
        ClaimMappingDTO[] claimMappingDTOs) {
    List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>();
    for (ClaimMappingDTO claimMappingDTO : claimMappingDTOs) {
        ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
        claimMappings.add(claimMapping);
    }
    return claimMappings.toArray(new ClaimMapping[claimMappings.size()]);

}
 
示例23
public ClaimMapping[] getClaimMapping() {
    if (claimMapping != null) {
        return claimMapping.clone();
    } else {
        return new ClaimMapping[0];
    }
}
 
示例24
/**
 * Returns all supported claims for the given dialect.
 *
 * @param dialectUri claim dialect URI
 * @param realm user realm
 * @return array of all supported claims
 * @throws IdentityException if error occurs while building supported claims
 */
public Claim[] getAllSupportedClaims(String dialectUri, UserRealm realm)
        throws IdentityException {

    ClaimManager claimAdmin;
    List<Claim> requiredClaims = new ArrayList<>();

    try {

        claimAdmin = realm.getClaimManager();

        ClaimMapping[] mappings = claimAdmin.getAllClaimMappings(dialectUri);

        if (mappings != null) {
            for (int i = 0; i < mappings.length; i++) {
                if (mappings[i].getClaim().isSupportedByDefault()) {
                    requiredClaims.add((Claim) mappings[i].getClaim());
                }
            }
        }
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        log.error("Error occurred while loading supported claims from the dialect "
                + dialectUri, e);
        getException("Error occurred while loading supported claims from the dialect "
                + dialectUri, e);
    }
    return requiredClaims.toArray(new Claim[requiredClaims.size()]);
}
 
示例25
public Set<String> getSupportedAttributes() {
    try {
        ClaimManager claimManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getClaimManager();
        ClaimMapping[] claims = claimManager
                .getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT);
        for (ClaimMapping claim : claims) {
            supportedAttrs.add(claim.getClaim().getClaimUri());
        }
    } catch (Exception e) {
        //ignore
    }
    return supportedAttrs;
}
 
示例26
/**
 * @param
 * @throws ClaimManagementException
 */
public void upateClaimMapping(ClaimMappingDTO claimMappingDTO) throws ClaimManagementException {
    /*Convert the simple structure of ClaimMapping received, to the complex structure
    of ClaimMapping which is used in the back end. */
    ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
    ClaimManagerHandler.getInstance().updateClaimMapping(claimMapping);
}
 
示例27
/**
 * @param
 * @throws ClaimManagementException
 */
public void addNewClaimMapping(ClaimMappingDTO claimMappingDTO) throws ClaimManagementException {
    /*Convert the simple structure of ClaimMapping received, to the complex structure
    of ClaimMapping which is used in the back end. */
    ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
    ClaimManagerHandler handler = ClaimManagerHandler.getInstance();
    ClaimMapping currentMapping = handler.getClaimMapping(
            claimMapping.getClaim().getClaimUri());
    if (currentMapping != null) {
        throw new ClaimManagementException(
                "Duplicate claim exist in the system. Please pick a different Claim Uri");
    }
    handler.addNewClaimMapping(claimMapping);
}
 
示例28
private ClaimMappingDTO[] convertClaimMappingArrayToClaimMappingDTOArray(
        ClaimMapping[] claimMappings) {
    List<ClaimMappingDTO> claimMappingDTOList = new ArrayList<ClaimMappingDTO>();
    for (ClaimMapping claimMapping : claimMappings) {
        ClaimMappingDTO claimMappingDTO = convertClaimMappingToClaimMappingDTO(claimMapping);
        claimMappingDTOList.add(claimMappingDTO);
    }
    return claimMappingDTOList.toArray(new ClaimMappingDTO[claimMappingDTOList.size()]);
}
 
示例29
private ClaimMapping[] convertClaimMappingDTOArrayToClaimMappingArray(
        ClaimMappingDTO[] claimMappingDTOs) {
    List<ClaimMapping> claimMappings = new ArrayList<ClaimMapping>();
    for (ClaimMappingDTO claimMappingDTO : claimMappingDTOs) {
        ClaimMapping claimMapping = convertClaimMappingDTOToClaimMapping(claimMappingDTO);
        claimMappings.add(claimMapping);
    }
    return claimMappings.toArray(new ClaimMapping[claimMappings.size()]);

}
 
示例30
public ClaimMapping[] getClaimMapping() {
    if (claimMapping != null) {
        return claimMapping.clone();
    } else {
        return new ClaimMapping[0];
    }
}