use of javax.naming.NameParser in project jetty.project by eclipse.
the class NamingEntry method save.
/**
* Save the NamingEntry for later use.
* <p>
* Saving is done by binding the NamingEntry
* itself, and the value it represents into
* JNDI. In this way, we can link to the
* value it represents later, but also
* still retrieve the NamingEntry itself too.
* <p>
* The object is bound at the jndiName passed in.
* This NamingEntry is bound at __/jndiName.
* <p>
* eg
* <pre>
* jdbc/foo : DataSource
* __/jdbc/foo : NamingEntry
* </pre>
*
* @param object the object to save
* @throws NamingException if unable to save
*/
protected void save(Object object) throws NamingException {
__log.debug("SAVE {} in {}", this, _scope);
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name prefix = NamingEntryUtil.getNameForScope(_scope);
//bind the NamingEntry into the context
Name namingEntryName = NamingEntryUtil.makeNamingEntryName(parser, getJndiName());
namingEntryName.addAll(0, prefix);
_namingEntryNameString = namingEntryName.toString();
NamingUtil.bind(ic, _namingEntryNameString, this);
//bind the object as well
Name objectName = parser.parse(getJndiName());
objectName.addAll(0, prefix);
_objectNameString = objectName.toString();
NamingUtil.bind(ic, _objectNameString, object);
}
use of javax.naming.NameParser in project jetty.project by eclipse.
the class NamingEntryUtil method getNameForScope.
public static Name getNameForScope(Object scope) {
try {
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name name = parser.parse("");
if (scope != null) {
name.add(canonicalizeScope(scope));
}
return name;
} catch (NamingException e) {
__log.warn(e);
return null;
}
}
use of javax.naming.NameParser in project jetty.project by eclipse.
the class NamingEntryUtil method lookupNamingEntry.
/**
* Find a NamingEntry in the given scope.
*
* @param scope the object scope
* @param jndiName the jndi name
* @return the naming entry for the given scope
* @throws NamingException if unable to lookup naming entry
*/
public static NamingEntry lookupNamingEntry(Object scope, String jndiName) throws NamingException {
NamingEntry entry = null;
try {
Name scopeName = getNameForScope(scope);
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
Name namingEntryName = makeNamingEntryName(parser, jndiName);
scopeName.addAll(namingEntryName);
entry = (NamingEntry) ic.lookup(scopeName);
} catch (NameNotFoundException ee) {
}
return entry;
}
use of javax.naming.NameParser in project jetty.project by eclipse.
the class NamingEntryUtil method lookup.
public static Object lookup(Object scope, String jndiName) throws NamingException {
Name scopeName = getNameForScope(scope);
InitialContext ic = new InitialContext();
NameParser parser = ic.getNameParser("");
scopeName.addAll(parser.parse(jndiName));
return ic.lookup(scopeName);
}
use of javax.naming.NameParser in project wildfly by wildfly.
the class SecurityDomainJndiInjectable method invoke.
/**
* This is the InvocationHandler callback for the Context interface that was created by our getObjectInstance() method. We
* handle the java:jboss/jaas/domain level operations here.
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Context ctx = new InitialContext();
NameParser parser = ctx.getNameParser("");
String securityDomain = null;
Name name = null;
final JNDIBasedSecurityManagement securityManagement = JNDIBasedSecurityManagement.class.cast(securityManagementValue.getValue());
final ConcurrentHashMap<String, SecurityDomainContext> securityManagerMap = securityManagement.getSecurityManagerMap();
String methodName = method.getName();
if (methodName.equals("toString"))
return SecurityConstants.JAAS_CONTEXT_ROOT + " Context proxy";
if (methodName.equals("list"))
return new DomainEnumeration(securityManagerMap.keys(), securityManagerMap);
if (methodName.equals("bind") || methodName.equals("rebind")) {
if (args[0] instanceof String)
name = parser.parse((String) args[0]);
else
name = (Name) args[0];
securityDomain = name.get(0);
SecurityDomainContext val = (SecurityDomainContext) args[1];
securityManagerMap.put(securityDomain, val);
return proxy;
}
if (!methodName.equals("lookup"))
throw SecurityLogger.ROOT_LOGGER.operationNotSupported(method);
if (args[0] instanceof String)
name = parser.parse((String) args[0]);
else
name = (Name) args[0];
securityDomain = name.get(0);
SecurityDomainContext securityDomainCtx = lookupSecurityDomain(securityManagement, securityManagerMap, securityDomain);
Object binding = securityDomainCtx.getAuthenticationManager();
// Look for requests against the security domain context
if (name.size() == 2) {
String request = name.get(1);
binding = securityDomainCtx.lookup(request);
}
return binding;
}
Aggregations