Search in sources :

Example 96 with Name

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;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) Name(javax.naming.Name) JNDIBasedSecurityManagement(org.jboss.as.security.plugins.JNDIBasedSecurityManagement)

Example 97 with Name

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;
    }
}
Also used : NamingContext(org.omg.CosNaming.NamingContext) NameComponent(org.omg.CosNaming.NameComponent) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CannotProceedException(javax.naming.CannotProceedException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) InvalidName(org.omg.CosNaming.NamingContextPackage.InvalidName) Name(javax.naming.Name) RefAddr(javax.naming.RefAddr) CannotProceedException(javax.naming.CannotProceedException) NamingException(javax.naming.NamingException) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound)

Example 98 with Name

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);
        }
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 99 with Name

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);
        }
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 100 with Name

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);
}
Also used : InvalidNameException(javax.naming.InvalidNameException) 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