本文整理汇总了Java中com.unboundid.ldap.sdk.ResultCode类的典型用法代码示例。如果您正苦于以下问题:Java ResultCode类的具体用法?Java ResultCode怎么用?Java ResultCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResultCode类属于com.unboundid.ldap.sdk包,在下文中一共展示了ResultCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importLdifFileInLdap
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException {
ResultCode result = ResultCode.UNAVAILABLE;
LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
try {
LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
LDIFReader importLdifReader = new LDIFReader(is);
result = ldifDataUtility.importLdifFile(connection, importLdifReader);
importLdifReader.close();
} catch (Exception ex) {
log.error("Failed to import ldif file: ", ex);
} finally {
ldapEntryManager.getOperationService().releaseConnection(connection);
}
return result;
}
示例2: getAttributeResultEntryLDIF
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
public List<SearchResultEntry> getAttributeResultEntryLDIF(LDAPConnection connection, List<String> patterns, String baseDN) {
List<SearchResultEntry> searchResultEntryList = new ArrayList<SearchResultEntry>();
try {
for (String pattern : patterns) {
String[] targetArray = new String[] { pattern };
Filter inumFilter = Filter.createSubstringFilter("inum", null,targetArray, null);
Filter searchFilter = Filter.createORFilter(inumFilter);
SearchResultEntry sr = connection.searchForEntry(baseDN,SearchScope.SUB, searchFilter, null);
searchResultEntryList.add(sr);
}
return searchResultEntryList;
} catch (LDAPException le) {
if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
log.error("Failed to search ldif record", le);
return null;
}
}
return null;
}
示例3: removeSubtreeThroughIteration
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
private void removeSubtreeThroughIteration(String dn) {
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.createPresenceFilter("objectClass")), 0, 0, null, "dn");
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn));
}
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn), ex);
}
List<String> removeEntriesDn = new ArrayList<String>(searchResult.getEntryCount());
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
removeEntriesDn.add(searchResultEntry.getDN());
}
Collections.sort(removeEntriesDn, LINE_LENGHT_COMPARATOR);
for (String removeEntryDn : removeEntriesDn) {
remove(removeEntryDn);
}
}
示例4: getLDIF
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
@Override
public List<String[]> getLDIF(String dn, String[] attributes) {
SearchResult searchResult;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.create("objectclass=*")), toLdapSearchScope(SearchScope.BASE), -1, 0, null, attributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s", dn));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", dn, null), ex);
}
List<String[]> result = new ArrayList<String[]>();
if (searchResult.getEntryCount() == 0) {
return result;
}
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
result.add(searchResultEntry.toLDIF());
}
return result;
}
示例5: getLDIFTree
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
@Override
public List<String[]> getLDIFTree(String baseDN, Filter searchFilter, String... attributes) {
SearchResult searchResult;
try {
searchResult = this.ldapOperationService.search(baseDN, toLdapFilter(searchFilter), -1, 0, null, attributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter),
ex);
}
List<String[]> result = new ArrayList<String[]>();
if (searchResult.getEntryCount() == 0) {
return result;
}
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
result.add(searchResultEntry.toLDIF());
}
return result;
}
示例6: dnFromUsername
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
private String dnFromUsername(String username) throws LDAPException, GeneralSecurityException {
String baseDN = config.getUserBaseDN();
String lookup = String.format("(%s=%s)", config.getUserAttribute(), username);
SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, lookup);
LDAPConnection connection = connectionFactory.getLDAPConnection();
try {
SearchResult sr = connection.search(searchRequest);
if (sr.getEntryCount() == 0) {
throw new LDAPException(ResultCode.INVALID_CREDENTIALS);
}
return sr.getSearchEntries().get(0).getDN();
} finally {
connection.close();
}
}
示例7: modifyCredentials
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
public void modifyCredentials(
String pool,
String user,
String currentPassword,
String newPassword,
Map<String, Object> vars
) throws Exception {
PasswordModifyExtendedResult passwordModifyResult = (PasswordModifyExtendedResult)getConnectionPoolEntry(
pool,
null,
vars
).connectionPool.processExtendedOperation(
new PasswordModifyExtendedRequest(user, currentPassword, newPassword)
);
if (passwordModifyResult.getResultCode() != ResultCode.SUCCESS) {
throw new LDAPException(passwordModifyResult);
}
}
示例8: importAttributes
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
public String importAttributes() throws Exception {
if (!fileDataToImport.isReady()) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "File to import is invalid");
return OxTrustConstants.RESULT_FAILURE;
}
InputStream is = new ByteArrayInputStream(fileDataToImport.getData());
ResultCode result = null;
try {
result = ldifService.importLdifFileInLdap(is);
} catch (LDAPException ex) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to import LDIF file");
} finally {
IOUtils.closeQuietly(is);
}
removeFileToImport();
if ((result != null) && result.equals(ResultCode.SUCCESS)) {
facesMessages.add(FacesMessage.SEVERITY_INFO,"Attributes added successfully");
return OxTrustConstants.RESULT_SUCCESS;
} else {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to import LDIF file");
return OxTrustConstants.RESULT_FAILURE;
}
}
示例9: authenticateConnectionPoolImpl
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
private boolean authenticateConnectionPoolImpl(final String bindDn, final String password) throws LDAPException, ConnectionException {
boolean loggedIn = false;
if (bindDn == null) {
return loggedIn;
}
boolean closeConnection = false;
LDAPConnection connection = connectionProvider.getConnection();
try {
closeConnection = true;
BindResult r = connection.bind(bindDn, password);
if (r.getResultCode() == ResultCode.SUCCESS) {
loggedIn = true;
}
} finally {
connectionProvider.releaseConnection(connection);
// We can't use connection which binded as ordinary user
if (closeConnection) {
connectionProvider.closeDefunctConnection(connection);
}
}
return loggedIn;
}
示例10: addEntry
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
@Override
public boolean addEntry(String dn, Collection<Attribute> atts) throws DuplicateEntryException, ConnectionException {
try {
LDAPResult result = getConnectionPool().add(dn, atts);
if (result.getResultCode().getName().equalsIgnoreCase(LdapOperationsServiceImpl.success))
return true;
} catch (final LDAPException ex) {
int errorCode = ex.getResultCode().intValue();
if (errorCode == ResultCode.ENTRY_ALREADY_EXISTS_INT_VALUE) {
throw new DuplicateEntryException();
}
if (errorCode == ResultCode.INSUFFICIENT_ACCESS_RIGHTS_INT_VALUE) {
throw new ConnectionException("LDAP config error: insufficient access rights.", ex);
}
if (errorCode == ResultCode.TIME_LIMIT_EXCEEDED_INT_VALUE) {
throw new ConnectionException("LDAP Error: time limit exceeded", ex);
}
if (errorCode == ResultCode.OBJECT_CLASS_VIOLATION_INT_VALUE) {
throw new ConnectionException("LDAP config error: schema violation contact LDAP admin.", ex);
}
throw new ConnectionException("Error adding entry to directory. LDAP error number " + errorCode, ex);
}
return false;
}
示例11: modifyEntry
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
/**
* Use this method to add / replace / delete attribute from entry
*
* @param modifyRequest
* @return true if modification is successful
* @throws DuplicateEntryException
* @throws ConnectionException
*/
protected boolean modifyEntry(ModifyRequest modifyRequest) throws DuplicateEntryException, ConnectionException {
LDAPResult modifyResult = null;
try {
modifyResult = getConnectionPool().modify(modifyRequest);
return ResultCode.SUCCESS.equals(modifyResult.getResultCode());
} catch (final LDAPException ex) {
int errorCode = ex.getResultCode().intValue();
if (errorCode == ResultCode.INSUFFICIENT_ACCESS_RIGHTS_INT_VALUE) {
throw new ConnectionException("LDAP config error: insufficient access rights.", ex);
}
if (errorCode == ResultCode.TIME_LIMIT_EXCEEDED_INT_VALUE) {
throw new ConnectionException("LDAP Error: time limit exceeded", ex);
}
if (errorCode == ResultCode.OBJECT_CLASS_VIOLATION_INT_VALUE) {
throw new ConnectionException("LDAP config error: schema violation contact LDAP admin.", ex);
}
throw new ConnectionException("Error updating entry in directory. LDAP error number " + errorCode, ex);
}
}
示例12: mergeWithRetry
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
private SessionId mergeWithRetry(final SessionId sessionId, int maxAttempts) {
EntryPersistenceException lastException = null;
for (int i = 1; i <= maxAttempts; i++) {
try {
putInCache(sessionId);
return sessionId;
} catch (EntryPersistenceException ex) {
lastException = ex;
if (ex.getCause() instanceof LDAPException) {
LDAPException parentEx = ((LDAPException) ex.getCause());
log.debug("LDAP exception resultCode: '{}'", parentEx.getResultCode().intValue());
if ((parentEx.getResultCode().intValue() == ResultCode.NO_SUCH_ATTRIBUTE_INT_VALUE) ||
(parentEx.getResultCode().intValue() == ResultCode.ATTRIBUTE_OR_VALUE_EXISTS_INT_VALUE)) {
log.warn("Session entry update attempt '{}' was unsuccessfull", i);
continue;
}
}
throw ex;
}
}
log.error("Session entry update attempt was unsuccessfull after '{}' attempts", maxAttempts);
throw lastException;
}
示例13: sendResult
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
protected void sendResult ( InMemoryInterceptedSearchResult result, String base, Entry e ) throws LDAPException, MalformedURLException {
URL turl = new URL(this.codebase, this.codebase.getRef().replace('.', '/').concat(".class"));
System.out.println("Send LDAP reference result for " + base + " redirecting to " + turl);
e.addAttribute("javaClassName", "foo");
String cbstring = this.codebase.toString();
int refPos = cbstring.indexOf('#');
if ( refPos > 0 ) {
cbstring = cbstring.substring(0, refPos);
}
e.addAttribute("javaCodeBase", cbstring);
e.addAttribute("objectClass", "javaNamingReference"); //$NON-NLS-1$
e.addAttribute("javaFactory", this.codebase.getRef());
result.sendSearchEntry(e);
result.setResult(new LDAPResult(0, ResultCode.SUCCESS));
}
示例14: main
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length == 0) {
args = new String[] { "-H" };
}
final ResultCode resultCode = main(args, System.out, System.err);
if (resultCode != ResultCode.SUCCESS) {
System.exit(resultCode.intValue());
}
}
示例15: testFallBackRolesCache
import com.unboundid.ldap.sdk.ResultCode; //导入依赖的package包/类
@Test
public void testFallBackRolesCache() throws Exception {
// ldap failure
Mockito.when(rolesProvider.getUserRoles("user")).thenThrow(new LDAPException(ResultCode.SERVER_DOWN));
rolesCache.put("user", roles);
Thread.sleep(1000); // wait till it expires
Assert.assertNull("rolesCache should have expired", rolesCache.get("user"));
Set<String> returnedRoles = cachedRolesProvider.getUserRoles("user");
Assert.assertEquals(roles, returnedRoles);
Mockito.verify(rolesCache, Mockito.times(1)).getFromFallback("user");
}