當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。