use of javax.naming.Name 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;
}
use of javax.naming.Name in project wildfly by wildfly.
the class ExceptionMapper method tryFed.
private static NamingException tryFed(NotFound e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
NameComponent[] rest = ((NotFound) e).rest_of_name;
if (debug) {
}
// If one of those is not found, you get "aa" as 'rest'.
if (rest.length == 1 && inputName != null) {
// Check that we're not talking to 1.2/1.3 Sun tnameserv
NameComponent lastIn = inputName[inputName.length - 1];
if (rest[0].id.equals(lastIn.id) && rest[0].kind != null && rest[0].kind.equals(lastIn.kind)) {
// Might be legit
} else {
// Due to 1.2/1.3 bug that always returns single-item 'rest'
NamingException ne = new NameNotFoundException();
ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
ne.setRootCause(e);
throw ne;
}
}
// Fixed in 1.4; perform calculations based on correct (1.4) behavior
// Calculate the components of the name that has been resolved
NameComponent[] resolvedName = null;
int len = 0;
if (inputName != null && (inputName.length >= rest.length)) {
if (e.why == NotFoundReason.not_context) {
// First component of rest is found but not a context; keep it
// as part of resolved name
len = inputName.length - (rest.length - 1);
// Remove resolved component from rest
if (rest.length == 1) {
// No more remaining
rest = null;
} else {
NameComponent[] tmp = new NameComponent[rest.length - 1];
System.arraycopy(rest, 1, tmp, 0, tmp.length);
rest = tmp;
}
} else {
len = inputName.length - rest.length;
}
if (len > 0) {
resolvedName = new NameComponent[len];
System.arraycopy(inputName, 0, resolvedName, 0, len);
}
}
// Create CPE and set common fields
CannotProceedException cpe = new CannotProceedException();
cpe.setRootCause(e);
if (rest != null && rest.length > 0) {
cpe.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
}
cpe.setEnvironment(ctx._env);
// Lookup resolved name to get resolved object
final java.lang.Object resolvedObj = (resolvedName != null) ? ctx.callResolve(resolvedName) : ctx;
if (resolvedObj instanceof javax.naming.Context) {
// obj is a context and child is not found
// try getting its nns dynamically by constructing
// a Reference containing obj.
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return resolvedObj;
}
private static final long serialVersionUID = 669984699392133792L;
};
Reference ref = new Reference("java.lang.Object", addr);
// Resolved name has trailing slash to indicate nns
CompositeName cname = new CompositeName();
// add trailing slash
cname.add("");
cpe.setResolvedObj(ref);
cpe.setAltName(cname);
cpe.setAltNameCtx((javax.naming.Context) resolvedObj);
return cpe;
} else {
// Not a context, use object factory to transform object.
Name cname = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(resolvedName);
java.lang.Object resolvedObj2;
try {
resolvedObj2 = NamingManager.getObjectInstance(resolvedObj, cname, ctx, ctx._env);
} catch (NamingException ge) {
throw ge;
} catch (Exception ge) {
NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
ne.setRootCause(ge);
throw ne;
}
// If a context, continue operation with context
if (resolvedObj2 instanceof javax.naming.Context) {
cpe.setResolvedObj(resolvedObj2);
} else {
// Add trailing slash
cname.add("");
cpe.setAltName(cname);
// Create nns reference
final java.lang.Object rf2 = resolvedObj2;
RefAddr addr = new RefAddr("nns") {
public java.lang.Object getContent() {
return rf2;
}
private static final long serialVersionUID = -785132553978269772L;
};
Reference ref = new Reference("java.lang.Object", addr);
cpe.setResolvedObj(ref);
cpe.setAltNameCtx(ctx);
}
return cpe;
}
}
use of javax.naming.Name in project ACS by ACS-Community.
the class ManagerImpl method rebind.
/**
* @param remoteDirectory parent context of parentContext.
* @param parent name of context to bind.
* @param parentContext context to bind.
* @throws NamingException
*
private void generateHiearchyContexts(Context remoteDirectory, String parent, Context parentContext) throws NamingException
{
/// @todo CORBA specific
if (remoteDirectory instanceof com.sun.jndi.cosnaming.CNCtx)
{
boolean isParentDomain = remoteDirectory.getNameInNamespace().length() == 0 ||
remoteDirectory.getNameInNamespace().endsWith(".D");
org.omg.CORBA.Object parentRepresentation = ((com.sun.jndi.cosnaming.CNCtx)remoteDirectory)._nc;
if (parent.endsWith(".D"))
{
// domain binding
parentContext.rebind("Parent.D", parentRepresentation);
}
else if (parent.endsWith(".F"))
{
// hierarchical component binding
if (isParentDomain)
parentContext.rebind("Domain.D", parentRepresentation);
else
parentContext.rebind("Domain.D", remoteDirectory.lookup("Domain.D"));
parentContext.rebind("Parent.F", parentRepresentation);
}
}
else if (remoteDirectory instanceof InitialContext)
generateHiearchyContexts((Context)((InitialContext)remoteDirectory).lookup(""), parent, parentContext);
else
new MessageLogEntry(this, "generateHiearchyContexts", "Unsupported remote directory, class '" + remoteDirectory.getClass().getName() + "'.", Level.WARNING).dispatch();
}*/
/**
* Rebind object to the root of remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
* NOTE: Does not support hierarchical names.
*
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
* @param object object to be binded
*
private void rebind(String name, String type, Object object)
{
rebind(remoteDirectory, name, type, object);
}*/
/**
* Rebind object to remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
* NOTE: Does not support hierarchical names.
*
* @param remoteDirectory remote directory context to be used.
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
* @param object object to be binded
*/
private void rebind(Context remoteDirectory, String name, String type, Object object) {
assert (name != null);
// do not bind interdomain names
if (name.startsWith(CURL_URI_SCHEMA))
return;
if (remoteDirectory != null) {
try {
NameParser parser = remoteDirectory.getNameParser("");
Name n;
if (type != null)
n = parser.parse(name + "." + type);
else
n = parser.parse(name);
remoteDirectory.rebind(n, object);
} catch (NamingException ne) {
CoreException ce = new CoreException("Failed to rebind name '" + name + "' to the remote directory.", ne);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
}
use of javax.naming.Name in project ACS by ACS-Community.
the class ManagerImpl method unbind.
/**
* Unbind object to remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
*
* @param remoteDirectory remote directory context to be used.
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
*/
private void unbind(Context remoteDirectory, String name, String type) {
assert (name != null);
// do not unbind interdomain names
if (name.startsWith(CURL_URI_SCHEMA))
return;
if (remoteDirectory != null) {
try {
NameParser parser = remoteDirectory.getNameParser("");
Name n;
if (type != null)
n = parser.parse(name + "." + type);
else
n = parser.parse(name);
remoteDirectory.unbind(n);
// NOTE: cleaning up the empty context nodes is not implemented
// since access NS cannot provide quantum actions (transactions)
// cleanup only empty ".F" contexts - only local manager
// should modify local NS
cleanupEmptyFContext(remoteDirectory, name);
} catch (NamingException ne) {
CoreException ce = new CoreException("Failed to unbind name '" + name + "' from the remote directory.", ne);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
}
use of javax.naming.Name in project uPortal by Jasig.
the class ReferenceCompositeGroupService method getEntity.
/**
* Returns an <code>IEntity</code> representing a portal entity. This does not guarantee that
* the entity actually exists.
*/
public IEntity getEntity(String key, Class type, String svcName) throws GroupsException {
IIndividualGroupService svc = null;
if (svcName == null) {
svc = getDefaultService();
} else {
try {
Name n = GroupService.parseServiceName(svcName);
svc = getComponentService(n);
} catch (InvalidNameException ine) {
throw new GroupsException("Invalid service name.");
}
}
return (svc == null) ? null : svc.getEntity(key, type);
}
Aggregations