Search in sources :

Example 61 with ChaiOperationException

use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.

the class ChaiHelpdeskAnswer method encryptValue.

private static String encryptValue(final String value, final String key) throws ChaiOperationException {
    try {
        if (value == null || value.length() < 1) {
            return "";
        }
        final SecretKey secretKey = makeKey(key);
        final Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey, cipher.getParameters());
        final byte[] encrypted = cipher.doFinal(value.getBytes());
        return Base64.encodeBytes(encrypted, Base64.URL_SAFE | Base64.GZIP);
    } catch (Exception e) {
        final String errorMsg = "unexpected error performing helpdesk answer crypt operation: " + e.getMessage();
        throw new ChaiOperationException(errorMsg, ChaiError.CHAI_INTERNAL_ERROR);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) Cipher(javax.crypto.Cipher) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 62 with ChaiOperationException

use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.

the class JNDIProviderImpl method writeBinaryAttribute.

public final void writeBinaryAttribute(final String entryDN, final String attributeName, final byte[][] values, final boolean overwrite, final ChaiRequestControl[] controls) throws ChaiUnavailableException, ChaiOperationException {
    activityPreCheck();
    getInputValidator().writeBinaryAttribute(entryDN, attributeName, values, overwrite);
    final String jndiBinarySetting = "java.naming.ldap.attributes.binary";
    // Create the ModificationItem
    final ModificationItem[] modificationItem = new ModificationItem[values.length];
    for (int i = 0; i < values.length; i++) {
        // Create a BasicAttribute for the object.
        final BasicAttribute attributeToReplace = new BasicAttribute(attributeName, values[i]);
        // Determine the modification type, if replace, only replace on the first attribute, the rest just get added.
        final int modType = (i == 0 && overwrite) ? DirContext.REPLACE_ATTRIBUTE : DirContext.ADD_ATTRIBUTE;
        // Populate the ModificationItem object with the flag & the attribute to replace.
        modificationItem[i] = new ModificationItem(modType, attributeToReplace);
    }
    // get ldap connection
    final LdapContext ldapConnection = getLdapConnection();
    // Modify the Attributes.
    try {
        if (controls != null && controls.length > 0) {
            ldapConnection.setRequestControls(convertControls(controls));
        }
        ldapConnection.modifyAttributes(addJndiEscape(entryDN), modificationItem);
        // inform jndi the attribute is binary.
        ldapConnection.addToEnvironment(jndiBinarySetting, attributeName);
    } catch (NamingException e) {
        convertNamingException(e);
    } finally {
        // clean up jndi environment
        try {
            ldapConnection.removeFromEnvironment(jndiBinarySetting);
        } catch (Exception e) {
        // doesnt matter
        }
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) NamingException(javax.naming.NamingException) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapContext(javax.naming.ldap.LdapContext) NamingException(javax.naming.NamingException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) CommunicationException(javax.naming.CommunicationException) SizeLimitExceededException(javax.naming.SizeLimitExceededException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 63 with ChaiOperationException

use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.

the class JNDIProviderImpl method init.

public void init(final ChaiConfiguration chaiConfig, final ChaiProviderFactory providerFactory) throws ChaiUnavailableException, IllegalStateException {
    this.chaiConfig = chaiConfig;
    final String connectionURL = chaiConfig.bindURLsAsList().get(0);
    final Hashtable env = generateJndiEnvironment(connectionURL);
    try {
        jndiConnection = generateNewJndiContext(env);
    } catch (ChaiOperationException e) {
        throw new ChaiUnavailableException("bind failed (" + e.getMessage() + ")", e.getErrorCode());
    }
    super.init(chaiConfig, providerFactory);
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Hashtable(java.util.Hashtable) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 64 with ChaiOperationException

use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.

the class NmasResponseSet method write.

boolean write() throws ChaiUnavailableException, ChaiOperationException {
    if (this.state != STATE.NEW) {
        throw new IllegalStateException("RepsonseSet not suitable for writing (not in NEW state)");
    }
    // write challenge set questions to Nmas Login Config
    try {
        final PutLoginConfigRequest request = new PutLoginConfigRequest();
        request.setObjectDN(user.getEntryDN());
        final byte[] data = csToNmasXML(getChallengeSet(), this.csIdentifier).getBytes("UTF8");
        request.setData(data);
        request.setDataLen(data.length);
        request.setTag("ChallengeResponseQuestions");
        request.setMethodID(NMASChallengeResponse.METHOD_ID);
        request.setMethodIDLen(NMASChallengeResponse.METHOD_ID.length * 4);
        final ExtendedResponse response = user.getChaiProvider().extendedOperation(request);
        if (response != null && ((PutLoginConfigResponse) response).getNmasRetCode() != 0) {
            LOGGER.debug("nmas error writing question: " + ((PutLoginConfigResponse) response).getNmasRetCode());
            return false;
        }
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("error while writing nmas questions: " + e.getMessage());
        return false;
    } catch (ChaiOperationException e) {
        LOGGER.error("error while writing nmas questions: " + e.getMessage());
        throw e;
    } catch (ChaiValidationException e) {
        LOGGER.error("error while writing nmas questions: " + e.getMessage());
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
    boolean success = true;
    // write responses
    for (final Map.Entry<Challenge, Answer> entry : crMap.entrySet()) {
        final Challenge loopChallenge = entry.getKey();
        try {
            final byte[] data = ((NmasAnswer) entry.getValue()).getAnswerText().getBytes("UTF8");
            final PutLoginSecretRequest request = new PutLoginSecretRequest();
            request.setObjectDN(user.getEntryDN());
            request.setData(data);
            request.setDataLen(data.length);
            request.setTag(loopChallenge.getChallengeText());
            request.setMethodID(NMASChallengeResponse.METHOD_ID);
            request.setMethodIDLen(NMASChallengeResponse.METHOD_ID.length * 4);
            final ExtendedResponse response = user.getChaiProvider().extendedOperation(request);
            if (response != null && ((PutLoginSecretResponse) response).getNmasRetCode() != 0) {
                LOGGER.debug("nmas error writing answer: " + ((PutLoginSecretResponse) response).getNmasRetCode());
                success = false;
            }
        } catch (Exception e) {
            LOGGER.error("error while writing nmas answer: " + e.getMessage());
        }
    }
    if (success) {
        LOGGER.info("successfully wrote NMAS challenge/response set for user " + user.getEntryDN());
        this.state = STATE.WRITTEN;
    }
    return success;
}
Also used : PutLoginConfigRequest(com.novell.security.nmas.jndi.ldap.ext.PutLoginConfigRequest) PutLoginConfigResponse(com.novell.security.nmas.jndi.ldap.ext.PutLoginConfigResponse) PutLoginSecretResponse(com.novell.security.nmas.jndi.ldap.ext.PutLoginSecretResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JDOMException(org.jdom2.JDOMException) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) Answer(com.novell.ldapchai.cr.Answer) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) PutLoginSecretRequest(com.novell.security.nmas.jndi.ldap.ext.PutLoginSecretRequest) ExtendedResponse(javax.naming.ldap.ExtendedResponse) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 65 with ChaiOperationException

use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.

the class InetOrgPersonImpl method unlockPassword.

public final void unlockPassword() throws ChaiOperationException, ChaiUnavailableException {
    String writeAttribute = "";
    try {
        writeAttribute = ChaiConstant.ATTR_LDAP_LOCKED_BY_INTRUDER;
        this.writeStringAttribute(ChaiConstant.ATTR_LDAP_LOCKED_BY_INTRUDER, "FALSE");
        writeAttribute = ChaiConstant.ATTR_LDAP_LOGIN_INTRUDER_ATTEMPTS;
        this.writeStringAttribute(ChaiConstant.ATTR_LDAP_LOGIN_INTRUDER_ATTEMPTS, "0");
        writeAttribute = ChaiConstant.ATTR_LDAP_LOGIN_INTRUDER_RESET_TIME;
        this.writeStringAttribute(ChaiConstant.ATTR_LDAP_LOGIN_INTRUDER_RESET_TIME, PW_EXPIRATION_ZULU_TIMESTAMP);
        final String limit = this.readStringAttribute(ChaiConstant.ATTR_LDAP_LOGIN_GRACE_LIMIT);
        if (limit != null) {
            writeAttribute = ChaiConstant.ATTR_LDAP_LOGIN_GRACE_REMAINING;
            this.writeStringAttribute(ChaiConstant.ATTR_LDAP_LOGIN_GRACE_REMAINING, limit);
        }
    } catch (ChaiOperationException e) {
        final String errorMsg = "error writing to " + writeAttribute + ": " + e.getMessage();
        final ChaiOperationException newException = new ChaiOperationException(errorMsg, e.getErrorCode());
        newException.initCause(e);
        throw newException;
    }
}
Also used : ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Aggregations

ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)66 ErrorInformation (password.pwm.error.ErrorInformation)31 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)28 ChaiUser (com.novell.ldapchai.ChaiUser)24 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)21 UserIdentity (password.pwm.bean.UserIdentity)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Map (java.util.Map)12 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)11 IOException (java.io.IOException)10 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 PwmApplication (password.pwm.PwmApplication)10 LdapProfile (password.pwm.config.profile.LdapProfile)10 FormConfiguration (password.pwm.config.value.data.FormConfiguration)9 List (java.util.List)8 PwmSession (password.pwm.http.PwmSession)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ChaiPasswordPolicyException (com.novell.ldapchai.exception.ChaiPasswordPolicyException)6 Instant (java.time.Instant)6