use of com.novell.ldapchai.exception.ChaiOperationException 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;
}
use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.
the class AbstractProvider method cacheExtendedOperationException.
protected void cacheExtendedOperationException(final ExtendedRequest request, final Exception e) throws ChaiOperationException {
final boolean cacheFailures = this.getChaiConfiguration().getBooleanSetting(ChaiSetting.EXTENDED_OPERATION_FAILURE_CACHE);
if (cacheFailures) {
final ChaiOperationException opExcep = ChaiOperationException.forErrorMessage(e.getMessage());
if (opExcep.getErrorCode() == ChaiError.UNSUPPORTED_OPERATION) {
final Map<String, Object> providerProps = this.getProviderProperties();
final Map<String, Exception> cacheFailureMap = (Map<String, Exception>) providerProps.get(EXTENDED_FAILURE_CACHE_KEY);
final String requestID = request.getID();
cacheFailureMap.put(requestID, opExcep);
LOGGER.trace("caching extended operation for " + requestID);
throw opExcep;
}
}
}
use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.
the class JNDIProviderImpl method compareStringAttribute.
@LdapOperation
public final boolean compareStringAttribute(final String entryDN, final String attributeName, final String value) throws ChaiUnavailableException, ChaiOperationException {
activityPreCheck();
getInputValidator().compareStringAttribute(entryDN, attributeName, value);
final byte[] ba;
try {
ba = value.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException(e);
}
// Set up the search controls
final SearchControls ctls = new SearchControls();
// Return no attrs
ctls.setReturningAttributes(new String[0]);
// Search object only
ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
final LdapContext ldapConnection = getLdapConnection();
NamingEnumeration<SearchResult> answer = null;
boolean result = false;
try {
answer = ldapConnection.search(addJndiEscape(entryDN), "(" + attributeName + "={0})", new Object[] { ba }, ctls);
result = answer.hasMore();
} catch (NamingException e) {
convertNamingException(e);
} finally {
if (answer != null) {
try {
answer.close();
} catch (Exception e) {
/* action not required */
}
}
}
return result;
}
use of com.novell.ldapchai.exception.ChaiOperationException in project ldapchai by ldapchai.
the class JNDIProviderImpl method replaceBinaryAttribute.
@LdapOperation
@ModifyOperation
public final void replaceBinaryAttribute(final String entryDN, final String attributeName, final byte[] oldValue, final byte[] newValue) throws ChaiUnavailableException, ChaiOperationException {
activityPreCheck();
getInputValidator().replaceBinaryAttribute(entryDN, attributeName, oldValue, newValue);
final String jndiBinarySetting = "java.naming.ldap.attributes.binary";
// Create the ModificationItem
final ModificationItem[] modificationItem = new ModificationItem[2];
{
// Create a BasicAttribute for the old value.
final BasicAttribute oldValueOperation = new BasicAttribute(attributeName, oldValue);
// Populate the ModificationItem array with the removal of the old value.
modificationItem[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, oldValueOperation);
// Create a BasicAttribute for the new value.
final BasicAttribute newValueOperation = new BasicAttribute(attributeName, newValue);
// Populate the ModificationItem array with the removal of the old value.
modificationItem[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, newValueOperation);
}
// get ldap connection
final LdapContext ldapConnection = getLdapConnection();
// Modify the Attributes.
try {
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 NmasCrFactory method clearResponseSet.
public static void clearResponseSet(final ChaiUser theUser) throws ChaiUnavailableException, ChaiOperationException {
final ChaiProvider provider = theUser.getChaiProvider();
final DeleteLoginConfigRequest request = new DeleteLoginConfigRequest();
request.setObjectDN(theUser.getEntryDN());
request.setTag("ChallengeResponseQuestions");
request.setMethodID(NMASChallengeResponse.METHOD_ID);
request.setMethodIDLen(NMASChallengeResponse.METHOD_ID.length * 4);
final DeleteLoginConfigResponse response = (DeleteLoginConfigResponse) provider.extendedOperation(request);
if (response != null && response.getNmasRetCode() != 0) {
final String errorMsg = "nmas error clearing loginResponseConfig: " + response.getNmasRetCode();
LOGGER.debug(errorMsg);
throw new ChaiOperationException(errorMsg, ChaiError.UNKNOWN);
}
}
Aggregations