Search in sources :

Example 1 with PairwiseIdType

use of io.jans.as.model.common.PairwiseIdType in project jans by JanssenProject.

the class PairwiseIdentifierService method findPairWiseIdentifier.

public PairwiseIdentifier findPairWiseIdentifier(String userInum, String sectorIdentifier, String clientId) throws Exception {
    PairwiseIdType pairwiseIdType = PairwiseIdType.fromString(appConfiguration.getPairwiseIdType());
    if (PairwiseIdType.PERSISTENT == pairwiseIdType) {
        prepareBranch(userInum);
        String baseDnForPairwiseIdentifiers = getBaseDnForPairwiseIdentifiers(userInum);
        final Filter filter;
        if (appConfiguration.isShareSubjectIdBetweenClientsWithSameSectorId()) {
            Filter sectorIdentifierFilter = Filter.createEqualityFilter("jansSectorIdentifier", sectorIdentifier);
            Filter userInumFilter = Filter.createEqualityFilter("jansUsrId", userInum);
            filter = Filter.createANDFilter(sectorIdentifierFilter, userInumFilter);
        } else {
            Filter sectorIdentifierFilter = Filter.createEqualityFilter("jansSectorIdentifier", sectorIdentifier);
            Filter clientIdFilter = Filter.createEqualityFilter("jansClntId", clientId);
            Filter userInumFilter = Filter.createEqualityFilter("jansUsrId", userInum);
            filter = Filter.createANDFilter(sectorIdentifierFilter, clientIdFilter, userInumFilter);
        }
        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 localAccountId = appConfiguration.isShareSubjectIdBetweenClientsWithSameSectorId() ? userInum : userInum + clientId;
        String calculatedSub = SubjectIdentifierGenerator.generatePairwiseSubjectIdentifier(sectorIdentifier, localAccountId, key, salt, appConfiguration);
        PairwiseIdentifier pairwiseIdentifier = new PairwiseIdentifier(sectorIdentifier, clientId, userInum);
        pairwiseIdentifier.setId(calculatedSub);
        return pairwiseIdentifier;
    }
    return null;
}
Also used : PairwiseIdentifier(io.jans.as.persistence.model.PairwiseIdentifier) Filter(io.jans.orm.search.filter.Filter) PairwiseIdType(io.jans.as.model.common.PairwiseIdType)

Aggregations

PairwiseIdType (io.jans.as.model.common.PairwiseIdType)1 PairwiseIdentifier (io.jans.as.persistence.model.PairwiseIdentifier)1 Filter (io.jans.orm.search.filter.Filter)1