本文整理汇总了Java中org.springframework.ldap.NamingException类的典型用法代码示例。如果您正苦于以下问题:Java NamingException类的具体用法?Java NamingException怎么用?Java NamingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamingException类属于org.springframework.ldap包,在下文中一共展示了NamingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterateAttributeValues
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* Iterate through all the values of the specified Attribute calling back to
* the specified callbackHandler.
* @param attribute the Attribute to work with; not <code>null</code>.
* @param callbackHandler the callbackHandler; not <code>null</code>.
* @since 1.3
*/
public static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler) {
Assert.notNull(attribute, "Attribute must not be null");
Assert.notNull(callbackHandler, "callbackHandler must not be null");
if (attribute instanceof Iterable) {
int i = 0;
for (Object obj : (Iterable) attribute) {
handleAttributeValue(attribute.getID(), obj, i, callbackHandler);
i++;
}
}
else {
for (int i = 0; i < attribute.size(); i++) {
try {
handleAttributeValue(attribute.getID(), attribute.get(i), i, callbackHandler);
} catch (javax.naming.NamingException e) {
throw convertLdapException(e);
}
}
}
}
示例2: getValue
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* Get the value of the Rdn with the requested key in the supplied Name.
*
* @param name the Name in which to search for the key.
* @param key the attribute key to search for.
* @return the value of the rdn corresponding to the <b>first</b> occurrence of the requested key.
* @throws NoSuchElementException if no corresponding entry is found.
* @since 2.0
*/
public static Object getValue(Name name, String key) {
NamingEnumeration<? extends Attribute> allAttributes = getRdn(name, key).toAttributes().getAll();
while (allAttributes.hasMoreElements()) {
Attribute oneAttribute = allAttributes.nextElement();
if(key.equalsIgnoreCase(oneAttribute.getID())) {
try {
return oneAttribute.get();
} catch (javax.naming.NamingException e) {
throw convertLdapException(e);
}
}
}
// This really shouldn't happen
throw new NoSuchElementException("No Rdn with the requested key: '" + key + "'");
}
示例3: search
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void search(final Name base, final String filter, final SearchControls controls,
NameClassPairCallbackHandler handler) {
// Create a SearchExecutor to perform the search.
SearchExecutor se = new SearchExecutor() {
public NamingEnumeration executeSearch(DirContext ctx) throws javax.naming.NamingException {
return ctx.search(base, filter, controls);
}
};
if (handler instanceof ContextMapperCallbackHandler) {
assureReturnObjFlagSet(controls);
}
search(se, handler);
}
示例4: findByDn
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T> T findByDn(Name dn, final Class<T> clazz) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Reading Entry at - %s$1", dn));
}
// Make sure the class is OK before doing the lookup
String[] attributes = odm.manageClass(clazz);
T result = lookup(dn, attributes, new ContextMapper<T>() {
@Override
public T mapFromContext(Object ctx) throws javax.naming.NamingException {
return odm.mapFromLdapDataEntry((DirContextOperations) ctx, clazz);
}
});
if (result == null) {
throw new OdmException(String.format("Entry %1$s does not have the required objectclasses ", dn));
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Found entry - %s$1", result));
}
return result;
}
示例5: loadUserByUsername
import org.springframework.ldap.NamingException; //导入依赖的package包/类
@Override
public User loadUserByUsername(Authentication authentication) {
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
DirContextOperations authenticate;
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// authenticate user
authenticate = authenticator.authenticate(new UsernamePasswordAuthenticationToken(
authentication.getPrincipal(), authentication.getCredentials()));
// fetch user groups
try {
List<String> groups = authoritiesPopulator
.getGrantedAuthorities(authenticate, authenticate.getNameInNamespace()).stream()
.map(a -> a.getAuthority())
.collect(Collectors.toList());
authenticate.setAttributeValue(MEMBEROF_ATTRIBUTE, groups);
} catch (Exception e) {
LOGGER.warn("No group found for user {}", authenticate.getNameInNamespace(), e);
}
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
return createUser(authenticate);
} catch (UsernameNotFoundException notFound) {
throw notFound;
} catch (NamingException ldapAccessFailure) {
throw new InternalAuthenticationServiceException(
ldapAccessFailure.getMessage(), ldapAccessFailure);
}
}
示例6: getFullUserDn
import org.springframework.ldap.NamingException; //导入依赖的package包/类
private String getFullUserDn(LdapTemplate ldapTemplate, String filter) {
String dn;
try {
List<Object> result = ldapTemplate.search("", filter, new AbstractContextMapper<Object>() {
@Override
protected Object doMapFromContext(DirContextOperations ctx) {
return ctx.getNameInNamespace();
}
});
if (result.size() == 1) {
dn = result.get(0).toString();
} else if (result.size() > 1) {
throw new OperationFailureException(errf.instantiateErrorCode(
LdapErrors.UNABLE_TO_GET_SPECIFIED_LDAP_UID, "More than one ldap search result"));
} else {
return "";
}
logger.info(String.format("getDn success filter:%s, dn:%s", filter, dn));
} catch (NamingException e) {
LdapServerVO ldapServerVO = getLdapServer();
String errString = String.format(
"You'd better check the ldap server[url:%s, baseDN:%s, encryption:%s, username:%s, password:******]" +
" configuration and test connection first.getDn error filter:%s",
ldapServerVO.getUrl(), ldapServerVO.getBase(),
ldapServerVO.getEncryption(), ldapServerVO.getUsername(), filter);
throw new OperationFailureException(errf.instantiateErrorCode(
LdapErrors.UNABLE_TO_GET_SPECIFIED_LDAP_UID, errString));
}
return dn;
}
示例7: toggleUserInGroup
import org.springframework.ldap.NamingException; //导入依赖的package包/类
private boolean toggleUserInGroup(String realm, Group group, User user, int op) {
BasicAttribute member = new BasicAttribute("memberUid", user.getUid());
ModificationItem[] modGroups = new ModificationItem[] {
new ModificationItem(op, member) };
Name groupName = buildGroupDN(realm, group.getGroupName());
try {
ldapTemplate.modifyAttributes(groupName, modGroups);
} catch (NamingException e) {
return false;
}
return true;
}
示例8: doCloseConnection
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* Close the supplied context, but only if it is not associated with the
* current transaction.
*
* @param context
* the DirContext to close.
* @param contextSource
* the ContextSource bound to the transaction.
* @throws NamingException
*/
void doCloseConnection(DirContext context, ContextSource contextSource)
throws javax.naming.NamingException {
DirContextHolder transactionContextHolder = (DirContextHolder) TransactionSynchronizationManager
.getResource(contextSource);
if (transactionContextHolder == null
|| transactionContextHolder.getCtx() != context) {
log.debug("Closing context");
// This is not the transactional context or the transaction is
// no longer active - we should close it.
context.close();
} else {
log.debug("Leaving transactional context open");
}
}
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:25,代码来源:TransactionAwareDirContextInvocationHandler.java
示例9: list
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void list(final String base, NameClassPairCallbackHandler handler) {
SearchExecutor searchExecutor = new SearchExecutor() {
public NamingEnumeration executeSearch(DirContext ctx) throws javax.naming.NamingException {
return ctx.list(base);
}
};
search(searchExecutor, handler);
}
示例10: listBindings
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void listBindings(final String base, NameClassPairCallbackHandler handler) {
SearchExecutor searchExecutor = new SearchExecutor() {
public NamingEnumeration executeSearch(DirContext ctx) throws javax.naming.NamingException {
return ctx.listBindings(base);
}
};
search(searchExecutor, handler);
}
示例11: executeWithContext
import org.springframework.ldap.NamingException; //导入依赖的package包/类
private <T> T executeWithContext(ContextExecutor<T> ce, DirContext ctx) {
try {
return ce.executeWithContext(ctx);
}
catch (javax.naming.NamingException e) {
throw LdapUtils.convertLdapException(e);
}
finally {
closeContext(ctx);
}
}
示例12: lookup
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Object lookup(final Name dn) {
return executeReadOnly(new ContextExecutor() {
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException {
return ctx.lookup(dn);
}
});
}
示例13: modifyAttributes
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void modifyAttributes(final Name dn, final ModificationItem[] mods) {
executeReadWrite(new ContextExecutor() {
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException {
ctx.modifyAttributes(dn, mods);
return null;
}
});
}
示例14: bind
import org.springframework.ldap.NamingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void bind(final Name dn, final Object obj, final Attributes attributes) {
executeReadWrite(new ContextExecutor<Object>() {
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException {
ctx.bind(dn, obj, attributes);
return null;
}
});
}
示例15: doUnbind
import org.springframework.ldap.NamingException; //导入依赖的package包/类
private void doUnbind(final Name dn) {
executeReadWrite(new ContextExecutor<Object>() {
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException {
ctx.unbind(dn);
return null;
}
});
}