当前位置: 首页>>代码示例>>Java>>正文


Java DirContext类代码示例

本文整理汇总了Java中javax.naming.directory.DirContext的典型用法代码示例。如果您正苦于以下问题:Java DirContext类的具体用法?Java DirContext怎么用?Java DirContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DirContext类属于javax.naming.directory包,在下文中一共展示了DirContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAttributes

import javax.naming.directory.DirContext; //导入依赖的package包/类
@Override
public void addAttributes(final String dn, final String attribute, final Collection<String> values) {
	if (values.isEmpty()) {
		// Ignore this call
		return;
	}

	// Build the modification operation
	final ModificationItem[] mods = values.stream().map(v -> new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(attribute, v)))
			.toArray(ModificationItem[]::new);
	try {
		// Perform the addition
		template.modifyAttributes(org.springframework.ldap.support.LdapUtils.newLdapName(dn), mods);
	} catch (final org.springframework.ldap.AttributeInUseException aiue) {
		if (!aiue.getMessage().matches(".*(value #0 already exists|error code 20|ATTRIBUTE_OR_VALUE_EXISTS).*")) {
			throw aiue;
		}
		log.info("{} is already member of {}", values, dn);
	}
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:21,代码来源:GroupLdapRepository.java

示例2: setResources

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Set the resources DirContext object with which this Container is
 * associated.
 *
 * @param resources
 *            The newly associated DirContext
 */
@Override
public synchronized void setResources(DirContext resources) {
	// Called from StandardContext.setResources()
	// <- StandardContext.start()
	// <- ContainerBase.addChildInternal()

	// Change components if necessary
	DirContext oldResources = this.resources;
	if (oldResources == resources)
		return;
	Hashtable<String, String> env = new Hashtable<String, String>();
	if (getParent() != null)
		env.put(ProxyDirContext.HOST, getParent().getName());
	env.put(ProxyDirContext.CONTEXT, getName());
	this.resources = new ProxyDirContext(env, resources);
	// Report this property change to interested listeners
	support.firePropertyChange("resources", oldResources, this.resources);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:ContainerBase.java

示例3: getTokenFromUsername

import javax.naming.directory.DirContext; //导入依赖的package包/类
@Override
public String getTokenFromUsername(final LDAP ldap, final String username)
{
	return ldap.doAsAdmin(new InContext<String>()
	{
		@Override
		public String execute(DirContext ctx)
		{

			Name results = ldap.searchFirstResultAllBases(ctx, ldap.getUsernameFilter(username),
				new FullNameHitsCollector(), true);
			if( results != null )
			{
				return results.toString();
			}
			return null;
		}
	});
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:LDAPServiceImpl.java

示例4: getContinuationDirContext

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
  * Creates a context in which to continue a <tt>DirContext</tt> operation.
  * Operates just like <tt>NamingManager.getContinuationContext()</tt>,
  * only the continuation context returned is a <tt>DirContext</tt>.
  *
  * @param cpe
  *         The non-null exception that triggered this continuation.
  * @return A non-null <tt>DirContext</tt> object for continuing the operation.
  * @exception NamingException If a naming exception occurred.
  *
  * @see NamingManager#getContinuationContext(CannotProceedException)
  */
@SuppressWarnings("unchecked")
public static DirContext getContinuationDirContext(
        CannotProceedException cpe) throws NamingException {

    Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
    if (env == null) {
        env = new Hashtable<>(7);
    } else {
        // Make a (shallow) copy of the environment.
        env = (Hashtable<Object,Object>) env.clone();
    }
    env.put(CPE, cpe);

    return (new ContinuationDirContext(cpe, env));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:DirectoryManager.java

示例5: setup

import javax.naming.directory.DirContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
    bean = spy(new LdapAccessServiceBean());
    dcMock = mock(DirContext.class);
    neMock = mock(NamingEnumeration.class);
    srMock = mock(SearchResult.class);
    aMock = mock(Attributes.class);

    doReturn(new Integer(5)).when(bean).getSearchLimit();
    doReturn(dcMock).when(bean).getDirContext(any(Properties.class));

    when(dcMock.search(anyString(), anyString(), any(SearchControls.class)))
            .thenReturn(neMock);

    when(Boolean.valueOf(neMock.hasMore())).thenReturn(Boolean.TRUE,
            Boolean.FALSE);
    when(neMock.next()).thenReturn(srMock);
    when(srMock.getAttributes()).thenReturn(aMock);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:LdapAccessServiceBeanTest.java

示例6: getUser

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Return a User object containing information about the user
 * with the specified username, if found in the directory;
 * otherwise return <code>null</code>.
 *
 * If the <code>userPassword</code> configuration attribute is
 * specified, the value of that attribute is retrieved from the
 * user's directory entry. If the <code>userRoleName</code>
 * configuration attribute is specified, all values of that
 * attribute are retrieved from the directory entry.
 *
 * @param context The directory context
 * @param username Username to be looked up
 * @param credentials User credentials (optional)
 * @param curUserPattern Index into userPatternFormatArray
 *
 * @exception NamingException if a directory server error occurs
 */
protected User getUser(DirContext context, String username,
                       String credentials, int curUserPattern)
    throws NamingException {

    User user = null;

    // Get attributes to retrieve from user entry
    ArrayList<String> list = new ArrayList<String>();
    if (userPassword != null)
        list.add(userPassword);
    if (userRoleName != null)
        list.add(userRoleName);
    String[] attrIds = new String[list.size()];
    list.toArray(attrIds);

    // Use pattern or search for user entry
    if (userPatternFormatArray != null && curUserPattern >= 0) {
        user = getUserByPattern(context, username, credentials, attrIds, curUserPattern);
    } else {
        user = getUserBySearch(context, username, attrIds);
    }

    return user;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:43,代码来源:JNDIRealm.java

示例7: getServerAddress

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Returns a server's address and port for the specified hostname, looking up the SRV record if possible
 */
private static String[] getServerAddress(String p_78863_0_)
{
    try
    {
        String s = "com.sun.jndi.dns.DnsContextFactory";
        Class.forName("com.sun.jndi.dns.DnsContextFactory");
        Hashtable hashtable = new Hashtable();
        hashtable.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
        hashtable.put("java.naming.provider.url", "dns:");
        hashtable.put("com.sun.jndi.dns.timeout.retries", "1");
        DirContext dircontext = new InitialDirContext(hashtable);
        Attributes attributes = dircontext.getAttributes("_minecraft._tcp." + p_78863_0_, new String[] {"SRV"});
        String[] astring = attributes.get("srv").get().toString().split(" ", 4);
        return new String[] {astring[3], astring[2]};
    }
    catch (Throwable var6)
    {
        return new String[] {p_78863_0_, Integer.toString(25565)};
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:24,代码来源:ServerAddress.java

示例8: checkCredentials

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Check whether the given User can be authenticated with the
 * given credentials. If the <code>userPassword</code>
 * configuration attribute is specified, the credentials
 * previously retrieved from the directory are compared explicitly
 * with those presented by the user. Otherwise the presented
 * credentials are checked by binding to the directory as the
 * user.
 *
 * @param context The directory context
 * @param user The User to be authenticated
 * @param credentials The credentials presented by the user
 *
 * @exception NamingException if a directory server error occurs
 */
protected boolean checkCredentials(DirContext context,
                                 User user,
                                 String credentials)
     throws NamingException {

     boolean validated = false;

     if (userPassword == null) {
         validated = bindAsUser(context, user, credentials);
     } else {
         validated = compareCredentials(context, user, credentials);
     }

     if (containerLog.isTraceEnabled()) {
         if (validated) {
             containerLog.trace(sm.getString("jndiRealm.authenticateSuccess",
                              user.username));
         } else {
             containerLog.trace(sm.getString("jndiRealm.authenticateFailure",
                              user.username));
         }
     }
     return (validated);
 }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:JNDIRealm.java

示例9: listCollectionPaths

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * List resource paths (recursively), and store all of them in the given
 * Set.
 */
private static void listCollectionPaths(Set<String> set,
        DirContext resources, String path) throws NamingException {

    Enumeration<Binding> childPaths = resources.listBindings(path);
    while (childPaths.hasMoreElements()) {
        Binding binding = childPaths.nextElement();
        String name = binding.getName();
        StringBuilder childPath = new StringBuilder(path);
        if (!"/".equals(path) && !path.endsWith("/"))
            childPath.append("/");
        childPath.append(name);
        Object object = binding.getObject();
        if (object instanceof DirContext) {
            childPath.append("/");
        }
        set.add(childPath.toString());
    }

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:24,代码来源:ApplicationContext.java

示例10: setResources

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Set the resources DirContext object with which this Container is
 * associated.
 *
 * @param resources The newly associated DirContext
 */
public synchronized void setResources(DirContext resources) {
    // Called from StandardContext.setResources()
    //              <- StandardContext.start() 
    //              <- ContainerBase.addChildInternal() 

    // Change components if necessary
    DirContext oldResources = this.resources;
    if (oldResources == resources)
        return;
    Hashtable env = new Hashtable();
    if (getParent() != null)
        env.put(ProxyDirContext.HOST, getParent().getName());
    env.put(ProxyDirContext.CONTEXT, getName());
    this.resources = new ProxyDirContext(env, resources);
    // Report this property change to interested listeners
    support.firePropertyChange("resources", oldResources, this.resources);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:ContainerBase.java

示例11: setResources

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Set the resources DirContext object with which this Container is
 * associated.
 *
 * @param resources The newly associated DirContext
 */
@Override
public synchronized void setResources(DirContext resources) {
    // Called from StandardContext.setResources()
    //              <- StandardContext.start() 
    //              <- ContainerBase.addChildInternal() 

    // Change components if necessary
    DirContext oldResources = this.resources;
    if (oldResources == resources)
        return;
    Hashtable<String, String> env = new Hashtable<String, String>();
    if (getParent() != null)
        env.put(ProxyDirContext.HOST, getParent().getName());
    env.put(ProxyDirContext.CONTEXT, getName());
    this.resources = new ProxyDirContext(env, resources);
    // Report this property change to interested listeners
    support.firePropertyChange("resources", oldResources, this.resources);

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:ContainerBase.java

示例12: getResourceAsStream

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Return the requested resource as an <code>InputStream</code>.  The
 * path must be specified according to the rules described under
 * <code>getResource</code>.  If no such resource can be identified,
 * return <code>null</code>.
 *
 * @param path The path to the desired resource.
 */
public InputStream getResourceAsStream(String path) {

    if (path == null || (Globals.STRICT_SERVLET_COMPLIANCE && !path.startsWith("/")))
        return (null);

    path = RequestUtil.normalize(path);
    if (path == null)
        return (null);

    DirContext resources = context.getResources();
    if (resources != null) {
        try {
            Object resource = resources.lookup(path);
            if (resource instanceof Resource)
                return (((Resource) resource).streamContent());
        } catch (Exception e) {
        }
    }
    return (null);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:ApplicationContext.java

示例13: getGroupResult

import javax.naming.directory.DirContext; //导入依赖的package包/类
public LDAPResult getGroupResult(DirContext ctx, String groupID, String[] attrs)
{
	if( !Check.isEmpty(groupIdField) )
	{
		SingleFilter nv1 = new SingleFilter(OBJECTCLASS, getGroupObject());
		SingleFilter nv2 = new SingleFilter(groupIdField, groupID);
		return searchFirstResultAllBases(ctx, new AndFilter(nv1, nv2), new LdapResultHitsCollector(attrs), true);
	}

	try
	{
		Name name = LDAP.parse(groupID);
		return new LDAPResult(name, getAttributes(ctx, name, attrs));
	}
	catch( InvalidNameException e )
	{
		LOGGER.debug(e, e);
		return null;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:LDAP.java

示例14: getResourcePaths

import javax.naming.directory.DirContext; //导入依赖的package包/类
/**
 * Return a Set containing the resource paths of resources member of the
 * specified collection. Each path will be a String starting with
 * a "/" character. The returned set is immutable.
 *
 * @param path Collection path
 */
public Set getResourcePaths(String path) {

    DirContext resources = context.getResources();
    if (resources != null) {
        if (System.getSecurityManager() != null) {
            PrivilegedAction dp =
                new PrivilegedGetResourcePaths(resources, path);
            return ((Set) AccessController.doPrivileged(dp));
        } else {
            return (getResourcePathsInternal(resources, path));
        }
    }
    return (null);

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:23,代码来源:ApplicationContext.java

示例15: searchAllBases

import javax.naming.directory.DirContext; //导入依赖的package包/类
public <T> List<T> searchAllBases(DirContext ctx, Filter filter, HitsCollector<T> collector, boolean recurse)
{
	for( Name element : getBases() )
	{
		search(ctx, element, filter, collector, recurse);
	}
	return collector.getResults();
}
 
开发者ID:equella,项目名称:Equella,代码行数:9,代码来源:LDAP.java


注:本文中的javax.naming.directory.DirContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。