Search in sources :

Example 16 with Context

use of javax.naming.Context in project camel by apache.

the class DataFormatDataSetTest method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    PurchaseOrder bean = new PurchaseOrder();
    bean.setName("Beer");
    bean.setAmount(23);
    bean.setPrice(2.5);
    SimpleDataSet ds = new SimpleDataSet();
    ds.setDefaultBody(bean);
    ds.setSize(200);
    Context context = super.createJndiContext();
    context.bind("beer", ds);
    return context;
}
Also used : Context(javax.naming.Context) SimpleDataSet(org.apache.camel.component.dataset.SimpleDataSet)

Example 17 with Context

use of javax.naming.Context in project camel by apache.

the class JcrAuthTestBase method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    Context context = super.createJndiContext();
    repository = new TransientRepository(new File(REPO_PATH));
    // set up a user to authenticate
    SessionImpl session = (SessionImpl) repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    UserManager userManager = session.getUserManager();
    User user = (User) userManager.getAuthorizable("test");
    if (user == null) {
        user = userManager.createUser("test", "quatloos");
    }
    // set up permissions
    String path = session.getRootNode().getPath();
    AccessControlManager accessControlManager = session.getAccessControlManager();
    AccessControlPolicyIterator acls = accessControlManager.getApplicablePolicies(path);
    AccessControlList acl = null;
    if (acls.hasNext()) {
        acl = (AccessControlList) acls.nextAccessControlPolicy();
    } else {
        acl = (AccessControlList) accessControlManager.getPolicies(path)[0];
    }
    acl.addAccessControlEntry(user.getPrincipal(), accessControlManager.getSupportedPrivileges(path));
    accessControlManager.setPolicy(path, acl);
    session.save();
    session.logout();
    context.bind("repository", repository);
    return context;
}
Also used : Context(javax.naming.Context) AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) TransientRepository(org.apache.jackrabbit.core.TransientRepository) UserManager(org.apache.jackrabbit.api.security.user.UserManager) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) SessionImpl(org.apache.jackrabbit.core.SessionImpl) File(java.io.File)

Example 18 with Context

use of javax.naming.Context in project camel by apache.

the class JcrRouteTestSupport method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    File config = new File(CONFIG_FILE);
    if (!config.exists()) {
        throw new FileNotFoundException("Missing config file: " + config.getPath());
    }
    Context context = super.createJndiContext();
    repository = new TransientRepository(CONFIG_FILE, REPO_PATH);
    context.bind("repository", repository);
    return context;
}
Also used : Context(javax.naming.Context) TransientRepository(org.apache.jackrabbit.core.TransientRepository) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 19 with Context

use of javax.naming.Context in project camel by apache.

the class JmsProviderTest method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    Context context = super.createJndiContext();
    context.bind("activemq", ActiveMQComponent.activeMQComponent("vm://localhost"));
    return context;
}
Also used : Context(javax.naming.Context)

Example 20 with Context

use of javax.naming.Context in project hadoop by apache.

the class LdapAuthenticationHandler method authenticateWithoutTlsExtension.

private void authenticateWithoutTlsExtension(String userDN, String password) throws AuthenticationException {
    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, providerUrl);
    env.put(Context.SECURITY_AUTHENTICATION, SECURITY_AUTHENTICATION);
    env.put(Context.SECURITY_PRINCIPAL, userDN);
    env.put(Context.SECURITY_CREDENTIALS, password);
    try {
        // Create initial context
        Context ctx = new InitialDirContext(env);
        ctx.close();
        logger.debug("Authentication successful for {}", userDN);
    } catch (NamingException e) {
        throw new AuthenticationException("Error validating LDAP user", e);
    }
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) InitialDirContext(javax.naming.directory.InitialDirContext) Context(javax.naming.Context) LdapContext(javax.naming.ldap.LdapContext) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) Hashtable(java.util.Hashtable) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext)

Aggregations

Context (javax.naming.Context)507 InitialContext (javax.naming.InitialContext)250 Test (org.junit.Test)173 NamingException (javax.naming.NamingException)156 DataSource (javax.sql.DataSource)72 Properties (java.util.Properties)67 Connection (java.sql.Connection)62 NameNotFoundException (javax.naming.NameNotFoundException)52 UserTransaction (javax.transaction.UserTransaction)48 SQLException (java.sql.SQLException)46 IOException (java.io.IOException)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)44 Statement (java.sql.Statement)42 Name (javax.naming.Name)38 Hashtable (java.util.Hashtable)35 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)27 BeanContext (org.apache.openejb.BeanContext)27 Binding (javax.naming.Binding)25 Reference (javax.naming.Reference)25 NotContextException (javax.naming.NotContextException)23