Search in sources :

Example 1 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class AbstractProvider method getDirectoryVendor.

public DirectoryVendor getDirectoryVendor() throws ChaiUnavailableException {
    if (cachedDirectoryVendor == null) {
        {
            final DirectoryVendor centralCachedVendor = getProviderFactory().getCentralService().getVendorCache(this.chaiConfig);
            if (centralCachedVendor != null) {
                return centralCachedVendor;
            }
        }
        final String defaultVendor = this.getChaiConfiguration().getSetting(ChaiSetting.DEFAULT_VENDOR);
        if (defaultVendor != null) {
            for (final DirectoryVendor vendor : DirectoryVendor.values()) {
                if (vendor.toString().equals(defaultVendor)) {
                    cachedDirectoryVendor = vendor;
                    return vendor;
                }
            }
        }
        try {
            final ChaiEntry rootDseEntry = ChaiUtility.getRootDSE(this);
            cachedDirectoryVendor = ChaiUtility.determineDirectoryVendor(rootDseEntry);
            getProviderFactory().getCentralService().addVendorCache(this.chaiConfig, cachedDirectoryVendor);
        } catch (ChaiOperationException e) {
            LOGGER.warn("error while attempting to determine directory vendor: " + e.getMessage());
            cachedDirectoryVendor = DirectoryVendor.GENERIC;
        }
    }
    return cachedDirectoryVendor;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 2 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class NmasCrFactory method readNmasAssignedChallengeSetPolicy.

private static ChallengeSet readNmasAssignedChallengeSetPolicy(final ChaiProvider provider, final String challengeSetDN, final Locale locale, final String identifer) throws ChaiUnavailableException, ChaiOperationException, ChaiValidationException {
    if (challengeSetDN == null || challengeSetDN.length() < 1) {
        LOGGER.trace("challengeSetDN is null, return null for readNmasAssignedChallengeSetPolicy()");
        return null;
    }
    final List<Challenge> challenges = new ArrayList<>();
    final ChaiEntry csSetEntry = provider.getEntryFactory().newChaiEntry(challengeSetDN);
    final Map<String, String> allValues = csSetEntry.readStringAttributes(Collections.emptySet());
    final String requiredQuestions = allValues.get("nsimRequiredQuestions");
    final String randomQuestions = allValues.get("nsimRandomQuestions");
    try {
        if (requiredQuestions != null && requiredQuestions.length() > 0) {
            challenges.addAll(NmasResponseSet.parseNmasPolicyXML(requiredQuestions, locale));
        }
        if (randomQuestions != null && randomQuestions.length() > 0) {
            challenges.addAll(NmasResponseSet.parseNmasPolicyXML(randomQuestions, locale));
        }
    } catch (JDOMException e) {
        LOGGER.debug(e);
    } catch (IOException e) {
        LOGGER.debug(e);
    }
    final int minRandQuestions = StringHelper.convertStrToInt(allValues.get("nsimNumberRandomQuestions"), 0);
    return new ChaiChallengeSet(challenges, minRandQuestions, locale, identifer);
}
Also used : ArrayList(java.util.ArrayList) ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) ChaiEntry(com.novell.ldapchai.ChaiEntry) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) Challenge(com.novell.ldapchai.cr.Challenge)

Example 3 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class EdirEntries method findPartitionRoot.

private static ChaiEntry findPartitionRoot(final ChaiEntry theEntry) throws ChaiUnavailableException, ChaiOperationException {
    ChaiEntry loopEntry = theEntry;
    while (loopEntry != null) {
        final Set<String> objClasses = loopEntry.readMultiStringAttribute(ChaiConstant.ATTR_LDAP_OBJECTCLASS);
        if (objClasses.contains(ChaiConstant.OBJECTCLASS_BASE_LDAP_PARTITION)) {
            return loopEntry;
        }
        loopEntry = loopEntry.getParentEntry();
    }
    return null;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry)

Example 4 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class UserImpl method isPasswordLocked.

public boolean isPasswordLocked() throws ChaiOperationException, ChaiUnavailableException {
    // modern versions of ad have a (somewhat) sane way of checking account lockout; heaven forbid a boolean attribute.
    final String computedBit = readStringAttribute("msDS-User-Account-Control-Computed");
    if (computedBit != null && computedBit.length() > 0) {
        final int intValue = Integer.parseInt(computedBit);
        return ((intValue & COMPUTED_ACCOUNT_CONTROL_UC_LOCKOUT) == COMPUTED_ACCOUNT_CONTROL_UC_LOCKOUT);
    }
    // older ad versions have an insane way of checking account lockout.  what could possibly go wrong?
    // read lockout time of user.
    final Instant lockoutTime = this.readDateAttribute("lockoutTime");
    if (lockoutTime != null) {
        ChaiEntry parentEntry = this.getParentEntry();
        long lockoutDurationMs = 0;
        // should never need this, but provided for sanity
        int recursionCount = 0;
        while (lockoutDurationMs == 0 && parentEntry != null && recursionCount < 50) {
            if (parentEntry.compareStringAttribute("objectClass", "domainDNS")) {
                // find the domain dns parent entry of the user
                // read the duration of lockouts from the domainDNS entry
                lockoutDurationMs = Long.parseLong(parentEntry.readStringAttribute("lockoutDuration"));
                // why is it stored as a negative value?  who knows.
                lockoutDurationMs = Math.abs(lockoutDurationMs);
                // convert from 100 nanosecond intervals to milliseconds.  It's important that intruders don't sneak
                // into the default 30 minute window a few nanoseconds early.  Thanks again MS.
                lockoutDurationMs = lockoutDurationMs / 10000;
            }
            parentEntry = parentEntry.getParentEntry();
            recursionCount++;
        }
        final Instant futureUnlockTime = Instant.ofEpochMilli(lockoutTime.toEpochMilli() + lockoutDurationMs);
        return System.currentTimeMillis() <= futureUnlockTime.toEpochMilli();
    }
    return false;
}
Also used : Instant(java.time.Instant) ChaiEntry(com.novell.ldapchai.ChaiEntry)

Example 5 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class UserImpl method readDomainValue.

private String readDomainValue(final String attribute) throws ChaiUnavailableException, ChaiOperationException {
    ChaiEntry parentEntry = this.getParentEntry();
    // should never need this, but provided for sanity
    int recursionCount = 0;
    while (parentEntry != null && recursionCount < 50) {
        if (parentEntry.compareStringAttribute("objectClass", "domainDNS")) {
            // read the desired attribute.
            return parentEntry.readStringAttribute(attribute);
        }
        parentEntry = parentEntry.getParentEntry();
        recursionCount++;
    }
    return null;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry)

Aggregations

ChaiEntry (com.novell.ldapchai.ChaiEntry)31 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)12 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)8 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)7 ChaiUser (com.novell.ldapchai.ChaiUser)6 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 ChaiException (com.novell.ldapchai.exception.ChaiException)2 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)2 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)2 TcpProxy (com.novell.ldapchai.tests.util.TcpProxy)2 InetSocketAddress (java.net.InetSocketAddress)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2