List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY
String INITIAL_CONTEXT_FACTORY
To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.
Click Source Link
From source file:org.settings4j.connector.JNDIConnector.java
private InitialContext getJNDIContext() throws NamingException { InitialContext initialContext; if (StringUtils.isEmpty(this.providerUrl) && StringUtils.isEmpty(this.initialContextFactory) && StringUtils.isEmpty(this.urlPkgPrefixes)) { initialContext = new InitialContext(); } else {/*from w w w .j a v a 2 s . com*/ final Properties prop = new Properties(); prop.put(Context.PROVIDER_URL, this.providerUrl); prop.put(Context.INITIAL_CONTEXT_FACTORY, this.initialContextFactory); prop.put(Context.URL_PKG_PREFIXES, this.urlPkgPrefixes); initialContext = new InitialContext(prop); } return initialContext; }
From source file:org.apache.jackrabbit.oak.security.authentication.ldap.AbstractServer.java
/** * Common code to get an initial context via a simple bind to the * server over the wire using the SUN JNDI LDAP provider. Do not use * this method until after the setUp() method is called to start the * server otherwise it will fail.//from w w w. j ava 2s. c om * * @param bindPrincipalDn the DN of the principal to bind as * @param password the password of the bind principal * @return an LDAP context as the the administrator to the rootDSE * @throws NamingException if the server cannot be contacted */ protected LdapContext getWiredContext(String bindPrincipalDn, String password) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, CTX_FACTORY); env.put(Context.PROVIDER_URL, "ldap://localhost:" + port); env.put(Context.SECURITY_PRINCIPAL, bindPrincipalDn); env.put(Context.SECURITY_CREDENTIALS, password); env.put(Context.SECURITY_AUTHENTICATION, "simple"); return new InitialLdapContext(env, null); }
From source file:com.adaptris.core.jms.activemq.EmbeddedActiveMq.java
private StandardJndiImplementation applyCfg(StandardJndiImplementation jndi, boolean useJndiOnly, String queueName, String topicName) { jndi.getJndiParams().addKeyValuePair(new KeyValuePair(Context.PROVIDER_URL, DEF_URL_PREFIX + port)); jndi.getJndiParams().addKeyValuePair( new KeyValuePair(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName())); jndi.getJndiParams().addKeyValuePair(new KeyValuePair("connectionFactoryNames", "connectionFactory, queueConnectionFactory, topicConnectionFactory")); jndi.getJndiParams().addKeyValuePair(new KeyValuePair("queue." + queueName, queueName)); jndi.getJndiParams().addKeyValuePair(new KeyValuePair("topic." + topicName, topicName)); if (useJndiOnly) { jndi.setUseJndiForQueues(true);//from w w w . jav a 2s . c o m jndi.setUseJndiForTopics(true); } return jndi; }
From source file:com.evolveum.midpoint.pwdfilter.opendj.PasswordPusher.java
private void readConfig() throws InitializationException { String configFile = "/opt/midpoint/opendj-pwdpusher.xml"; if (System.getProperty("config") != null) { configFile = System.getProperty("config"); }// ww w. ja va 2s. c o m File f = new File(configFile); if (!f.exists() || !f.canRead()) { throw new IllegalArgumentException("Config file " + configFile + " does not exist or is not readable"); } try { XMLConfiguration config = new XMLConfiguration(f); String notifierDN = "cn=" + config.getString("passwordpusher.statusNotifierName") + ",cn=Account Status Notification Handlers"; String ldapURL = config.getString("passwordpusher.ldapServerURL"); boolean ldapSSL = config.getBoolean("passwordpusher.ldapServerSSL"); String ldapUsername = config.getString("passwordpusher.ldapServerUsername"); String ldapPassword = config.getString("passwordpusher.ldapServerPassword"); Hashtable<Object, Object> env = new Hashtable<Object, Object>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL + "/cn=config"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, ldapUsername); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); if (ldapSSL) { env.put(Context.SECURITY_PROTOCOL, "ssl"); } try { DirContext context = new InitialDirContext(env); Attributes attr = context.getAttributes(notifierDN); this.endPoint = attr.get("ds-cfg-referrals-url").get(0).toString(); this.username = attr.get("ds-cfg-midpoint-username").get(0).toString(); this.password = attr.get("ds-cfg-midpoint-password").get(0).toString(); this.pwdChangeDirectory = attr.get("ds-cfg-midpoint-passwordcachedir").get(0).toString(); } catch (NamingException ne) { throw new InitializationException( ERR_MIDPOINT_PWDSYNC_READING_CONFIG_FROM_LDAP.get(ne.getMessage()), ne); } } catch (ConfigurationException ce) { throw new InitializationException(ERR_MIDPOINT_PWDSYNC_PARSING_XML_CONFIG.get(ce.getMessage()), ce); } }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testGroupMemberMethod() throws Exception { log.debug("+++ testGroupMemberMethod()"); Properties env = new Properties(); env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory"); env.setProperty(Context.SECURITY_PRINCIPAL, "jduke"); env.setProperty(Context.SECURITY_CREDENTIALS, "theduke"); InitialContext ctx = new InitialContext(env); Object obj = ctx.lookup("jacc/Secured"); obj = PortableRemoteObject.narrow(obj, SecuredServiceRemoteHome.class); SecuredServiceRemoteHome home = (SecuredServiceRemoteHome) obj; log.debug("Found SecuredServiceRemoteHome"); SecuredServiceRemote bean = home.create(); log.debug("Created SecuredServiceRemote"); Principal callerIdentity = new SimplePrincipal("jduke"); Principal runAsIdentity = new SimplePrincipal("runAsUser"); HashSet expectedCallerRoles = new HashSet(); expectedCallerRoles.add("groupMemberCaller"); expectedCallerRoles.add("userCaller"); expectedCallerRoles.add("allAuthCaller"); expectedCallerRoles.add("webUser"); HashSet expectedRunAsRoles = new HashSet(); expectedRunAsRoles.add("identitySubstitutionCaller"); expectedRunAsRoles.add("extraRunAsRole"); CallerInfo info = new CallerInfo(callerIdentity, runAsIdentity, expectedCallerRoles, expectedRunAsRoles); bean.groupMemberMethod(info);/*from ww w .j av a 2 s.c o m*/ bean.remove(); }
From source file:org.rhq.enterprise.server.core.CustomJaasDeploymentService.java
private Map<String, String> getLdapOptions(Properties conf) { Map<String, String> configOptions = new HashMap<String, String>(); configOptions.put(Context.INITIAL_CONTEXT_FACTORY, conf.getProperty(RHQConstants.LDAPFactory)); configOptions.put(Context.PROVIDER_URL, conf.getProperty(RHQConstants.LDAPUrl)); String value = conf.getProperty(SystemSetting.USE_SSL_FOR_LDAP.getInternalName()); boolean ldapSsl = "ssl".equalsIgnoreCase(value); configOptions.put(Context.SECURITY_PROTOCOL, (ldapSsl) ? "ssl" : null); configOptions.put("LoginProperty", conf.getProperty(RHQConstants.LDAPLoginProperty)); configOptions.put("Filter", conf.getProperty(RHQConstants.LDAPFilter)); configOptions.put("GroupFilter", conf.getProperty(RHQConstants.LDAPGroupFilter)); configOptions.put("GroupMemberFilter", conf.getProperty(RHQConstants.LDAPGroupMember)); configOptions.put("BaseDN", conf.getProperty(RHQConstants.LDAPBaseDN)); configOptions.put("BindDN", conf.getProperty(RHQConstants.LDAPBindDN)); configOptions.put("BindPW", conf.getProperty(RHQConstants.LDAPBindPW)); return configOptions; }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoContainer.java
/** * set naming context factory to nuxeo implementation, backup original * settings/* ww w .j a va2s. com*/ * * @since 5.6 */ protected static void setAsInitialContext() { // Preserve current set system props String key = Context.INITIAL_CONTEXT_FACTORY; parentEnvironment.put(key, System.getProperty(key)); key = Context.URL_PKG_PREFIXES; parentEnvironment.put(key, System.getProperty(key)); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, NamingContextFactory.class.getName()); System.setProperty(Context.URL_PKG_PREFIXES, "org.eclipse.ecr.runtime.jtajca"); }
From source file:com.stratelia.silverpeas.versioning.jcr.impl.AbstractJcrTestCase.java
@Before public void onSetUp() throws Exception { System.getProperties().put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); calend = Calendar.getInstance(); calend.set(Calendar.MILLISECOND, 0); calend.set(Calendar.SECOND, 0); calend.set(Calendar.MINUTE, 15); calend.set(Calendar.HOUR, 9); calend.set(Calendar.DAY_OF_MONTH, 12); calend.set(Calendar.MONTH, Calendar.MARCH); calend.set(Calendar.YEAR, 2008); IDatabaseConnection connection = null; try {/* w w w . j a v a2 s . co m*/ connection = new DatabaseConnection(datasource.getConnection()); DatabaseOperation.CLEAN_INSERT.execute(connection, getDataSet()); } catch (Exception ex) { throw ex; } finally { if (connection != null) { try { connection.getConnection().close(); } catch (SQLException e) { throw e; } } } }
From source file:org.sonar.plugins.ldap.LdapContextFactory.java
private Properties getEnvironment(@Nullable String principal, @Nullable String credentials, boolean pooling) { Properties env = new Properties(); env.put(Context.SECURITY_AUTHENTICATION, authentication); if (realm != null) { env.put(SASL_REALM_PROPERTY, realm); }//w ww. j a v a 2 s . c om if (pooling) { // Enable connection pooling env.put(SUN_CONNECTION_POOLING_PROPERTY, "true"); } env.put(Context.INITIAL_CONTEXT_FACTORY, factory); env.put(Context.PROVIDER_URL, providerUrl); env.put(Context.REFERRAL, DEFAULT_REFERRAL); if (principal != null) { env.put(Context.SECURITY_PRINCIPAL, principal); } // Note: debug is intentionally was placed here - in order to not expose password in log LOG.debug("Initializing LDAP context {}", env); if (credentials != null) { env.put(Context.SECURITY_CREDENTIALS, credentials); } return env; }
From source file:py.una.pol.karaku.security.KarakuUserService.java
private InitialDirContext getInitialDirContext(String user, String pass) throws NamingException { Map<Object, String> env = new HashMap<Object, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, getServerLocation()); env.put(Context.SECURITY_PRINCIPAL, user); env.put(Context.SECURITY_CREDENTIALS, pass); return new InitialDirContext(new Hashtable<Object, String>(env)); }