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);
}
}
}
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();
}
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);
}
}
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");
}
}
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");
}
}
}
Aggregations