Search in sources :

Example 1 with Answer

use of com.novell.ldapchai.cr.Answer 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 2 with Answer

use of com.novell.ldapchai.cr.Answer in project ldapchai by ldapchai.

the class NmasResponseSet method convertAnswerTextMap.

private static Map<Challenge, Answer> convertAnswerTextMap(final Map<Challenge, String> crMap) {
    final Map<Challenge, Answer> returnMap = new LinkedHashMap<>();
    for (final Map.Entry<Challenge, String> entry : crMap.entrySet()) {
        final Challenge challenge = entry.getKey();
        final String answerText = entry.getValue();
        returnMap.put(challenge, new NmasAnswer(answerText));
    }
    return returnMap;
}
Also used : Answer(com.novell.ldapchai.cr.Answer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Answer (com.novell.ldapchai.cr.Answer)2 ChaiChallenge (com.novell.ldapchai.cr.ChaiChallenge)2 Challenge (com.novell.ldapchai.cr.Challenge)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)1 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)1 PutLoginConfigRequest (com.novell.security.nmas.jndi.ldap.ext.PutLoginConfigRequest)1 PutLoginConfigResponse (com.novell.security.nmas.jndi.ldap.ext.PutLoginConfigResponse)1 PutLoginSecretRequest (com.novell.security.nmas.jndi.ldap.ext.PutLoginSecretRequest)1 PutLoginSecretResponse (com.novell.security.nmas.jndi.ldap.ext.PutLoginSecretResponse)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ExtendedResponse (javax.naming.ldap.ExtendedResponse)1 JDOMException (org.jdom2.JDOMException)1