Search in sources :

Example 51 with Name

use of javax.naming.Name in project gerrit by GerritCodeReview.

the class Helper method recursivelyExpandGroups.

private void recursivelyExpandGroups(final Set<String> groupDNs, final LdapSchema schema, final DirContext ctx, final String groupDN) {
    if (groupDNs.add(groupDN) && schema.accountMemberField != null && schema.accountMemberExpandGroups) {
        ImmutableSet<String> cachedParentsDNs = parentGroups.getIfPresent(groupDN);
        if (cachedParentsDNs == null) {
            // Recursively identify the groups it is a member of.
            ImmutableSet.Builder<String> dns = ImmutableSet.builder();
            try {
                final Name compositeGroupName = new CompositeName().add(groupDN);
                final Attribute in = ctx.getAttributes(compositeGroupName, schema.accountMemberFieldArray).get(schema.accountMemberField);
                if (in != null) {
                    final NamingEnumeration<?> groups = in.getAll();
                    try {
                        while (groups.hasMore()) {
                            dns.add((String) groups.next());
                        }
                    } catch (PartialResultException e) {
                    // Ignored
                    }
                }
            } catch (NamingException e) {
                LdapRealm.log.warn("Could not find group " + groupDN, e);
            }
            cachedParentsDNs = dns.build();
            parentGroups.put(groupDN, cachedParentsDNs);
        }
        for (String dn : cachedParentsDNs) {
            recursivelyExpandGroups(groupDNs, schema, ctx, dn);
        }
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Attribute(javax.naming.directory.Attribute) CompositeName(javax.naming.CompositeName) PartialResultException(javax.naming.PartialResultException) NamingException(javax.naming.NamingException) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 52 with Name

use of javax.naming.Name in project jdk8u_jdk by JetBrains.

the class DirContextStringPair method getTargetContext.

protected DirContextStringPair getTargetContext(String name) throws NamingException {
    if (cpe.getResolvedObj() == null)
        throw (NamingException) cpe.fillInStackTrace();
    Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env);
    if (ctx instanceof DirContext)
        return new DirContextStringPair((DirContext) ctx, name);
    if (ctx instanceof Resolver) {
        Resolver res = (Resolver) ctx;
        ResolveResult rr = res.resolveToClass(name, DirContext.class);
        // Reached a DirContext; return result.
        DirContext dctx = (DirContext) rr.getResolvedObj();
        Name tmp = rr.getRemainingName();
        String remains = (tmp != null) ? tmp.toString() : "";
        return (new DirContextStringPair(dctx, remains));
    }
    // Resolve all the way using lookup().  This may allow the operation
    // to succeed if it doesn't require the penultimate context.
    Object ultimate = ctx.lookup(name);
    if (ultimate instanceof DirContext) {
        return (new DirContextStringPair((DirContext) ultimate, ""));
    }
    throw (NamingException) cpe.fillInStackTrace();
}
Also used : DirContext(javax.naming.directory.DirContext) Context(javax.naming.Context) NamingException(javax.naming.NamingException) DirContext(javax.naming.directory.DirContext) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 53 with Name

use of javax.naming.Name in project uPortal by Jasig.

the class ReferenceCompositeGroupService method initializeComponentServices.

/**
     * Assembles the group services composite. Once the leaf services have been retrieved, they are
     * held in a (one-dimensional) Map. The composite identity of a service is preserved in its Map
     * key, a javax.naming.Name. Each node of the Name is the name of a component service, starting
     * with the service closest to the composite service and ending with the name of the leaf
     * service. The key is built up layer by layer.
     *
     * @exception GroupsException
     */
protected void initializeComponentServices() throws GroupsException {
    Name leafServiceName = null;
    try {
        GroupServiceConfiguration cfg = GroupServiceConfiguration.getConfiguration();
        List services = cfg.getServiceDescriptors();
        for (Iterator it = services.iterator(); it.hasNext(); ) {
            ComponentGroupServiceDescriptor descriptor = (ComponentGroupServiceDescriptor) it.next();
            String factoryName = descriptor.getServiceFactoryName();
            IComponentGroupServiceFactory factory = (IComponentGroupServiceFactory) Class.forName(factoryName).newInstance();
            IComponentGroupService service = factory.newGroupService(descriptor);
            // If it's a leaf service, add it to the Map.
            if (service.isLeafService()) {
                leafServiceName = GroupService.parseServiceName(descriptor.getName());
                service.setServiceName(leafServiceName);
                getComponentServices().put(leafServiceName, service);
            } else // Otherwise, get its leaf services and for each, push our node onto the service Name
            // and add the service to the Map.
            {
                Map componentMap = service.getComponentServices();
                for (Iterator components = componentMap.values().iterator(); components.hasNext(); ) {
                    IIndividualGroupService leafService = (IIndividualGroupService) components.next();
                    leafServiceName = leafService.getServiceName();
                    leafServiceName.add(0, descriptor.getName());
                    getComponentServices().put(leafServiceName, leafService);
                }
            }
        }
        Name defaultServiceName = GroupService.parseServiceName(cfg.getDefaultService());
        defaultService = (IIndividualGroupService) getComponentService(defaultServiceName);
    } catch (Exception ex) {
        throw new GroupsException("Problem initializing component services", ex);
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) CachingException(org.apereo.portal.concurrency.CachingException) InvalidNameException(javax.naming.InvalidNameException) Name(javax.naming.Name)

Example 54 with Name

use of javax.naming.Name in project jetty.project by eclipse.

the class localContextRoot method createSubcontext.

/**
     *
     *
     * @see javax.naming.Context#createSubcontext(javax.naming.Name)
     */
public Context createSubcontext(Name name) throws NamingException {
    synchronized (__root) {
        if (__root.isLocked()) {
            NamingException ne = new NamingException("This context is immutable");
            ne.setRemainingName(name);
            throw ne;
        }
        Name cname = __root.toCanonicalName(name);
        if (cname == null)
            throw new NamingException("Name is null");
        if (cname.size() == 0)
            throw new NamingException("Name is empty");
        if (cname.size() == 1) {
            //not permitted to bind if something already bound at that name
            Binding binding = __root.getBinding(cname);
            if (binding != null)
                throw new NameAlreadyBoundException(cname.toString());
            //make a new naming context with the root as the parent
            Context ctx = new NamingContext((Hashtable) _env.clone(), cname.get(0), __root, __root.getNameParser(""));
            __root.addBinding(cname, ctx);
            return ctx;
        }
        //If the name has multiple subcontexts, walk the hierarchy by
        //fetching the first one. All intermediate subcontexts in the
        //name must already exist.
        String firstComponent = cname.get(0);
        Object ctx = null;
        if (firstComponent.equals(""))
            ctx = this;
        else {
            Binding binding = __root.getBinding(firstComponent);
            if (binding == null)
                throw new NameNotFoundException(firstComponent + " is not bound");
            ctx = binding.getObject();
            if (ctx instanceof Reference) {
                //deference the object
                if (__log.isDebugEnabled())
                    __log.debug("Object bound at " + firstComponent + " is a Reference");
                try {
                    ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env);
                } catch (NamingException e) {
                    throw e;
                } catch (Exception e) {
                    __log.warn("", e);
                    throw new NamingException(e.getMessage());
                }
            }
        }
        if (ctx instanceof Context) {
            return ((Context) ctx).createSubcontext(cname.getSuffix(1));
        } else
            throw new NotContextException(firstComponent + " is not a Context");
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) NotContextException(javax.naming.NotContextException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) NamingContext(org.eclipse.jetty.jndi.NamingContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Example 55 with Name

use of javax.naming.Name in project jetty.project by eclipse.

the class localContextRoot method rebind.

/**
     *
     *
     * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
     */
public void rebind(Name name, Object obj) throws NamingException {
    synchronized (__root) {
        if (__root.isLocked())
            throw new NamingException("This context is immutable");
        Name cname = __root.toCanonicalName(name);
        if (cname == null)
            throw new NamingException("Name is null");
        if (cname.size() == 0)
            throw new NamingException("Name is empty");
        //if no subcontexts, just bind it
        if (cname.size() == 1) {
            //check if it is a Referenceable
            Object objToBind = NamingManager.getStateToBind(obj, name, __root, _env);
            if (objToBind instanceof Referenceable) {
                objToBind = ((Referenceable) objToBind).getReference();
            }
            __root.removeBinding(cname);
            __root.addBinding(cname, objToBind);
        } else {
            //walk down the subcontext hierarchy
            if (__log.isDebugEnabled())
                __log.debug("Checking for existing binding for name=" + cname + " for first element of name=" + cname.get(0));
            String firstComponent = cname.get(0);
            Object ctx = null;
            if (firstComponent.equals(""))
                ctx = this;
            else {
                Binding binding = __root.getBinding(name.get(0));
                if (binding == null)
                    throw new NameNotFoundException(name.get(0) + " is not bound");
                ctx = binding.getObject();
                if (ctx instanceof Reference) {
                    //deference the object
                    try {
                        ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), __root, _env);
                    } catch (NamingException e) {
                        throw e;
                    } catch (Exception e) {
                        __log.warn("", e);
                        throw new NamingException(e.getMessage());
                    }
                }
            }
            if (ctx instanceof Context) {
                ((Context) ctx).rebind(cname.getSuffix(1), obj);
            } else
                throw new NotContextException("Object bound at " + firstComponent + " is not a Context");
        }
    }
}
Also used : Binding(javax.naming.Binding) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingContext(org.eclipse.jetty.jndi.NamingContext) NotContextException(javax.naming.NotContextException) Referenceable(javax.naming.Referenceable) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompoundName(javax.naming.CompoundName) Name(javax.naming.Name)

Aggregations

Name (javax.naming.Name)107 CompositeName (javax.naming.CompositeName)48 NamingException (javax.naming.NamingException)38 Context (javax.naming.Context)37 InitialContext (javax.naming.InitialContext)36 NameNotFoundException (javax.naming.NameNotFoundException)34 Test (org.junit.Test)32 Reference (javax.naming.Reference)24 NotContextException (javax.naming.NotContextException)22 Binding (javax.naming.Binding)19 CompoundName (javax.naming.CompoundName)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NameParser (javax.naming.NameParser)17 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 InvalidNameException (javax.naming.InvalidNameException)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)10 IOException (java.io.IOException)8 LinkRef (javax.naming.LinkRef)7 ServiceName (org.jboss.msc.service.ServiceName)7 Referenceable (javax.naming.Referenceable)6