Example usage for javax.naming Name addAll

List of usage examples for javax.naming Name addAll

Introduction

In this page you can find the example usage for javax.naming Name addAll.

Prototype

public Name addAll(Name suffix) throws InvalidNameException;

Source Link

Document

Adds the components of a name -- in order -- to the end of this name.

Usage

From source file:com.dattack.naming.AbstractContext.java

@Override
public Name composeName(final Name name, final Name prefix) throws NamingException {

    if (name == null || prefix == null) {
        throw new InvalidNameException(
                String.format("Unable to compose name with null values (prefix: %s, name: %s)", prefix, name));
    }// w w w  .j  av a  2 s .com

    final Name composeName = (Name) prefix.clone();
    composeName.addAll(name);
    return composeName;
}

From source file:naming.resources.ProxyDirContext.java

/**
 * Composes the name of this context with a name relative to this context.
 * <p>/*from  w  ww . j a  v  a2  s . c  om*/
 * Given a name (name) relative to this context, and the name (prefix) 
 * of this context relative to one of its ancestors, this method returns 
 * the composition of the two names using the syntax appropriate for the 
 * naming system(s) involved. That is, if name names an object relative 
 * to this context, the result is the name of the same object, but 
 * relative to the ancestor context. None of the names may be null.
 * 
 * @param name a name relative to this context
 * @param prefix the name of this context relative to one of its ancestors
 * @return the composition of prefix and name
 * @exception NamingException if a naming exception is encountered
 */
public Name composeName(Name name, Name prefix) throws NamingException {
    prefix = (Name) name.clone();
    return prefix.addAll(name);
}

From source file:org.apache.geronimo.security.realm.providers.GenericHttpHeaderLdapLoginModule.java

protected boolean authenticate(String username) throws Exception {
    DirContext context = open();//from www  . j a  v  a 2s .c  o  m
    try {

        String filter = userSearchMatchingFormat.format(new String[] { username });
        SearchControls constraints = new SearchControls();
        if (userSearchSubtreeBool) {
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else {
            constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }

        // setup attributes
        String[] attribs;
        if (userRoleName == null) {
            attribs = new String[] {};
        } else {
            attribs = new String[] { userRoleName };
        }
        constraints.setReturningAttributes(attribs);

        NamingEnumeration results = context.search(userBase, filter, constraints);

        if (results == null || !results.hasMore()) {
            log.error("No roles associated with user " + username);
            loginSucceeded = false;
            throw new FailedLoginException();
        }

        SearchResult result = (SearchResult) results.next();

        if (results.hasMore()) {
            // ignore for now
        }
        NameParser parser = context.getNameParser("");
        Name contextName = parser.parse(context.getNameInNamespace());
        Name baseName = parser.parse(userBase);
        Name entryName = parser.parse(result.getName());
        Name name = contextName.addAll(baseName);
        name = name.addAll(entryName);
        String dn = name.toString();

        Attributes attrs = result.getAttributes();
        if (attrs == null) {
            return false;
        }
        ArrayList<String> roles = null;
        if (userRoleName != null) {
            roles = addAttributeValues(userRoleName, attrs, roles);
        }
        // check the credentials by binding to server
        // bindUser(context, dn);
        // if authenticated add more roles
        roles = getRoles(context, dn, username, roles);
        for (String role : roles) {
            groups.add(role);
        }
        if (groups.isEmpty()) {
            log.error("No roles associated with user " + username);
            loginSucceeded = false;
            throw new FailedLoginException();
        } else
            loginSucceeded = true;

    } catch (CommunicationException e) {
        close(context);
        throw (LoginException) new FailedLoginException().initCause(e);
    } catch (NamingException e) {
        close(context);
        throw (LoginException) new FailedLoginException().initCause(e);
    }
    return true;
}