Search in sources :

Example 1 with PairwiseIdType

use of org.xdi.oxauth.model.common.PairwiseIdType in project oxAuth by GluuFederation.

the class PairwiseIdentifierService method findPairWiseIdentifier.

public PairwiseIdentifier findPairWiseIdentifier(String userInum, String sectorIdentifierUri) throws Exception {
    PairwiseIdType pairwiseIdType = PairwiseIdType.fromString(appConfiguration.getPairwiseIdType());
    String sectorIdentifier = URI.create(sectorIdentifierUri).getHost();
    if (PairwiseIdType.PERSISTENT == pairwiseIdType) {
        prepareBranch(userInum);
        String baseDnForPairwiseIdentifiers = getBaseDnForPairwiseIdentifiers(userInum);
        Filter filter = Filter.createEqualityFilter("oxSectorIdentifier", sectorIdentifier);
        List<PairwiseIdentifier> entries = ldapEntryManager.findEntries(baseDnForPairwiseIdentifiers, PairwiseIdentifier.class, filter);
        if (entries != null && !entries.isEmpty()) {
            // if more then one entry then it's problem, non-deterministic behavior, id must be unique
            if (entries.size() > 1) {
                log.error("Found more then one pairwise identifier by sector identifier: {}" + sectorIdentifier);
                for (PairwiseIdentifier pairwiseIdentifier : entries) {
                    log.error("PairwiseIdentifier: {}", pairwiseIdentifier);
                }
            }
            return entries.get(0);
        }
    } else {
        // PairwiseIdType.ALGORITHMIC
        String key = appConfiguration.getPairwiseCalculationKey();
        String salt = appConfiguration.getPairwiseCalculationSalt();
        String calculatedSub = SubjectIdentifierGenerator.generatePairwiseSubjectIdentifier(sectorIdentifierUri, userInum, key, salt, appConfiguration);
        PairwiseIdentifier pairwiseIdentifier = new PairwiseIdentifier(sectorIdentifierUri);
        pairwiseIdentifier.setId(calculatedSub);
        return pairwiseIdentifier;
    }
    return null;
}
Also used : PairwiseIdentifier(org.xdi.oxauth.model.ldap.PairwiseIdentifier) Filter(com.unboundid.ldap.sdk.Filter) PairwiseIdType(org.xdi.oxauth.model.common.PairwiseIdType)

Aggregations

Filter (com.unboundid.ldap.sdk.Filter)1 PairwiseIdType (org.xdi.oxauth.model.common.PairwiseIdType)1 PairwiseIdentifier (org.xdi.oxauth.model.ldap.PairwiseIdentifier)1