Example usage for javax.naming Context SECURITY_CREDENTIALS

List of usage examples for javax.naming Context SECURITY_CREDENTIALS

Introduction

In this page you can find the example usage for javax.naming Context SECURITY_CREDENTIALS.

Prototype

String SECURITY_CREDENTIALS

To view the source code for javax.naming Context SECURITY_CREDENTIALS.

Click Source Link

Document

Constant that holds the name of the environment property for specifying the credentials of the principal for authenticating the caller to the service.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    DirContext ctx = new InitialDirContext(env);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    // Create connection controls to use
    Control[] connectCtls = new Control[] { null };

    LdapContext ctx = new InitialLdapContext(env, connectCtls);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    LdapContext ctx = new InitialLdapContext(env, null);

    NamingEnumeration answer = ctx.search("ou=People", "(cn=*)", null);

    System.out.println(ctx.getResponseControls());

    while (answer.hasMore()) {
        SearchResult si = (SearchResult) answer.next();
        if (si instanceof HasControls) {
            System.out.println(((HasControls) si).getControls());
        }//from   w w  w  . j  a  va 2  s. c  o m
    }
    System.out.println(ctx.getResponseControls());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "YourURL");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People"));

    NamingListener listener = new SampleNCListener();

    ctx.addNamingListener("cn=John", EventContext.ONELEVEL_SCOPE, listener);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    Control[] connectCtls = new Control[] { null };
    LdapContext ctx = new InitialLdapContext(env, null);

    Control[] ctxCtls = new Control[] { new SortControl(new String[] { "cn" }, Control.CRITICAL) };

    ctx.setRequestControls(ctxCtls);/*from   www .  j  a  v a2 s . com*/

    NamingEnumeration answer = ctx.list("");

    while (answer.hasMore()) {
        NameClassPair item = (NameClassPair) answer.next();
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);

    env.put(Context.PROVIDER_URL, MY_HOST);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
    env.put(Context.SECURITY_CREDENTIALS, MGR_PW);

    DirContext ctx = new InitialDirContext(env);

    Person p = new Person();
    ctx.bind("uid=mewilcox, ou=People, o=airius.com", p);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String url = "ldap://localhost/o=JNDITutorial";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "userDN");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    EventDirContext ctx = (EventDirContext) (new InitialContext(env).lookup("ou=People"));

    NamingListener listener = new SampleObjListener();

    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    String filter = "(mail=*)";

    ctx.addNamingListener("cn=YourName", filter, ctls, listener);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
    env.put(Context.PROVIDER_URL, MY_HOST);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
    env.put(Context.SECURITY_CREDENTIALS, MGR_PW);
    DirContext ctx = new InitialDirContext(env);
    ctx.destroySubcontext(MY_ENTRY);//from   w  w w . ja v a  2s . c  om
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();

    env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);

    env.put(Context.PROVIDER_URL, MY_HOST);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
    env.put(Context.SECURITY_CREDENTIALS, MGR_PW);

    DirContext ctx = new InitialDirContext(env);

    ModificationItem[] mods = new ModificationItem[2];

    Attribute mod0 = new BasicAttribute("number", "555-555-5555");
    Attribute mod1 = new BasicAttribute("1", "AAA");

    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
    mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod1);

    ctx.modifyAttributes("uid=mewilcox, ou=People, o=airius.com", mods);
}

From source file:org.overlord.sramp.performance.BasicPerformanceTest.java

public static void main(String[] args) {
    try {//from w  w  w  .j a va 2 s.  c o  m
        Properties jndiProps = new Properties();
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
        //            jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "admin");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "artificer1!");
        jndiProps.put("jboss.naming.client.ejb.context", true);
        Context context = new InitialContext(jndiProps);

        final ArtifactService artifactService = (ArtifactService) context
                .lookup("artificer-server/ArtifactService!" + ArtifactService.class.getName());
        artifactService.login("artificer", "artificer1!");

        final BatchService batchService = (BatchService) context
                .lookup("artificer-server/BatchService!" + BatchService.class.getName());
        batchService.login("artificer", "artificer1!");

        final QueryService queryService = (QueryService) context
                .lookup("artificer-server/QueryService!" + QueryService.class.getName());
        queryService.login("artificer", "artificer1!");

        xsdTest(artifactService);
        xsdBatchTest(batchService);
        queryTest(artifactService, queryService);
        fullTextSearchTest(queryService);
    } catch (Exception e) {
        e.printStackTrace();
    }
}