Search in sources :

Example 1 with CompositeName

use of javax.naming.CompositeName 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 2 with CompositeName

use of javax.naming.CompositeName in project geode by apache.

the class ContextImpl method destroySubcontext.

/**
   * Destroys subcontext with name name. The subcontext must be empty otherwise
   * ContextNotEmptyException is thrown. Once a context is destroyed, the instance should not be
   * used.
   * 
   * @param name subcontext to destroy
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system.
   * @throws ContextNotEmptyException if Context name is not empty.
   * @throws NameNotFoundException if subcontext with name name can not be found.
   * @throws NotContextException if name is not bound to instance of ContextImpl.
   * 
   */
public void destroySubcontext(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String subContextName = parsedName.get(0);
    Object boundObject = ctxMaps.get(subContextName);
    if (boundObject == null) {
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND_IN_THE_CONTEXT.toLocalizedString(subContextName));
    }
    if (!(boundObject instanceof ContextImpl)) {
        throw new NotContextException();
    }
    ContextImpl contextToDestroy = (ContextImpl) boundObject;
    if (parsedName.size() == 1) {
        // non-empty Context.
        if (contextToDestroy.ctxMaps.size() == 0) {
            ctxMaps.remove(subContextName);
            contextToDestroy.destroyInternal();
        } else {
            throw new ContextNotEmptyException(LocalizedStrings.ContextImpl_CAN_NOT_DESTROY_NONEMPTY_CONTEXT.toLocalizedString());
        }
    } else {
        // Let the subcontext destroy the context
        ((ContextImpl) boundObject).destroySubcontext(parsedName.getSuffix(1));
    }
}
Also used : NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 3 with CompositeName

use of javax.naming.CompositeName in project geode by apache.

the class ContextImpl method unbind.

/**
   * Removes name and its associated object from the context.
   * 
   * @param name name to remove
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system
   * @throws NameNotFoundException if intermediate context can not be found
   * @throws NotContextException if name has more than one atomic name and intermediate context is
   *         not found.
   * @throws NamingException if any other naming exception occurs
   * 
   */
public void unbind(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String nameToRemove = parsedName.get(0);
    // remove a and its associated object
    if (parsedName.size() == 1) {
        ctxMaps.remove(nameToRemove);
    } else {
        // scenerio unbind a/b or a/b/c
        // remove b and its associated object
        Object boundObject = ctxMaps.get(nameToRemove);
        if (boundObject instanceof Context) {
            // remove b and its associated object
            ((Context) boundObject).unbind(parsedName.getSuffix(1));
        } else {
            // if the name is not found then throw exception
            if (!ctxMaps.containsKey(nameToRemove)) {
                throw new NameNotFoundException(LocalizedStrings.ContextImpl_CAN_NOT_FIND_0.toLocalizedString(name));
            }
            throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 4 with CompositeName

use of javax.naming.CompositeName in project geode by apache.

the class ContextImpl method rebind.

/**
   * Rebinds object obj to name name . If there is existing binding it will be overwritten.
   * 
   * @param name name of the object to rebind.
   * @param obj object to add. Can be null.
   * @throws NoPermissionException if this context has been destroyed
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system
   * @throws NotContextException if name has more than one atomic name and intermediate context is
   *         not found
   * @throws NamingException if any other naming error occurs
   * 
   */
public void rebind(Name name, Object obj) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String nameToBind = parsedName.get(0);
    if (parsedName.size() == 1) {
        ctxMaps.put(nameToBind, obj);
    } else {
        Object boundObject = ctxMaps.get(nameToBind);
        if (boundObject instanceof Context) {
            /*
         * Let the subcontext bind the object.
         */
            ((Context) boundObject).bind(parsedName.getSuffix(1), obj);
        } else {
            if (boundObject == null) {
                // Create new subcontext and let it do the binding
                Context sub = createSubcontext(nameToBind);
                sub.bind(parsedName.getSuffix(1), obj);
            } else {
                throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
            }
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 5 with CompositeName

use of javax.naming.CompositeName in project geode by apache.

the class ContextImpl method createSubcontext.

/**
   * Creates subcontext with name, relative to this Context.
   * 
   * @param name subcontext name.
   * @return new subcontext named name relative to this context.
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system.
   * @throws NameAlreadyBoundException if name is already bound in this Context
   * @throws NotContextException if any intermediate name from name is not bound to instance of
   *         javax.naming.Context.
   * 
   */
public Context createSubcontext(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String subContextName = parsedName.get(0);
    Object boundObject = ctxMaps.get(parsedName.get(0));
    if (parsedName.size() == 1) {
        // Check if name is already in use
        if (boundObject == null) {
            Context subContext = new ContextImpl(this, subContextName);
            ctxMaps.put(subContextName, subContext);
            return subContext;
        } else {
            throw new NameAlreadyBoundException(LocalizedStrings.ContextImpl_NAME_0_IS_ALREADY_BOUND.toLocalizedString(subContextName));
        }
    } else {
        if (boundObject instanceof Context) {
            // an exception will be thrown in that case.
            return ((Context) boundObject).createSubcontext(parsedName.getSuffix(1));
        } else {
            throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

CompositeName (javax.naming.CompositeName)124 Test (org.junit.Test)69 Name (javax.naming.Name)43 NameNotFoundException (javax.naming.NameNotFoundException)27 NamingException (javax.naming.NamingException)25 Reference (javax.naming.Reference)19 Context (javax.naming.Context)18 InvalidNameException (javax.naming.InvalidNameException)13 NotContextException (javax.naming.NotContextException)12 ServiceName (org.jboss.msc.service.ServiceName)11 Test (org.junit.jupiter.api.Test)10 JndiPermission (org.wildfly.naming.java.permission.JndiPermission)10 Hashtable (java.util.Hashtable)9 Binding (javax.naming.Binding)8 LinkRef (javax.naming.LinkRef)8 OperationNotSupportedException (javax.naming.OperationNotSupportedException)8 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 StringRefAddr (javax.naming.StringRefAddr)5