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);
}
}
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
}
}
}
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);
}
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;
}
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;
}
}
Aggregations