Search in sources :

Example 11 with NameParser

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

Example 12 with NameParser

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;
    }
}
Also used : NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 13 with NameParser

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;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 14 with NameParser

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

Example 15 with NameParser

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;
}
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)

Aggregations

NameParser (javax.naming.NameParser)18 Name (javax.naming.Name)17 InitialContext (javax.naming.InitialContext)9 Context (javax.naming.Context)7 NamingException (javax.naming.NamingException)7 CoreException (com.cosylab.acs.maci.CoreException)4 HashMap (java.util.HashMap)3 CompositeName (javax.naming.CompositeName)3 NameNotFoundException (javax.naming.NameNotFoundException)3 Test (org.junit.Test)3 NamingEnumeration (javax.naming.NamingEnumeration)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 Session (javax.mail.Session)1 Binding (javax.naming.Binding)1 InvalidNameException (javax.naming.InvalidNameException)1