List of usage examples for javax.naming Context SECURITY_CREDENTIALS
String SECURITY_CREDENTIALS
To view the source code for javax.naming Context SECURITY_CREDENTIALS.
Click Source Link
From source file:com.mirth.connect.connectors.jms.JmsDispatcherTests.java
private static ConnectionFactory lookupConnectionFactoryWithJndi(JmsConnectorProperties connectorProperties) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.PROVIDER_URL, connectorProperties.getJndiProviderUrl()); env.put(Context.INITIAL_CONTEXT_FACTORY, connectorProperties.getJndiInitialContextFactory()); env.put(Context.SECURITY_PRINCIPAL, connectorProperties.getUsername()); env.put(Context.SECURITY_CREDENTIALS, connectorProperties.getPassword()); initialContext = new InitialContext(env); String connectionFactoryName = connectorProperties.getJndiConnectionFactoryName(); return (ConnectionFactory) initialContext.lookup(connectionFactoryName); }
From source file:org.apache.directory.server.core.jndi.LdapJndiPropertiesTest.java
License:asdf
@Test public void testAuthWithCredsStrong() throws Exception { Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.SECURITY_PRINCIPAL, ""); env.put(Context.SECURITY_CREDENTIALS, "asdf"); env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5 CRAM-MD5"); env.put(Context.PROVIDER_URL, ""); LdapJndiProperties props = LdapJndiProperties.getLdapJndiProperties(env); assertEquals(AuthenticationLevel.STRONG, props.getAuthenticationLevel()); assertTrue(ArrayUtils.isEquals(Strings.getBytesUtf8("asdf"), props.getCredentials())); }
From source file:org.exist.security.realm.ldap.LdapContextFactory.java
public LdapContext getLdapContext(String username, final String password, final Map<String, Object> additionalEnv) throws NamingException { if (url == null) { throw new IllegalStateException("An LDAP URL must be specified of the form ldap://<hostname>:<port>"); }//from ww w .ja v a 2 s. c om if (StringUtils.isBlank(password)) { throw new IllegalStateException("Password for LDAP authentication may not be empty."); } if (username != null && principalPattern != null) { username = principalPatternFormat.format(new String[] { username }); } final Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.SECURITY_AUTHENTICATION, authentication); if (ssl) { env.put(Context.SECURITY_PROTOCOL, "ssl"); } if (username != null) { env.put(Context.SECURITY_PRINCIPAL, username); } if (password != null) { env.put(Context.SECURITY_CREDENTIALS, password); } env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClassName); env.put(Context.PROVIDER_URL, url); //Absolutely nessecary for working with Active Directory env.put("java.naming.ldap.attributes.binary", "objectSid"); // the following is helpful in debugging errors //env.put("com.sun.jndi.ldap.trace.ber", System.err); // Only pool connections for system contexts if (usePooling && username != null && username.equals(systemUsername)) { // Enable connection pooling env.put(SUN_CONNECTION_POOLING_PROPERTY, "true"); } if (additionalEnv != null) { env.putAll(additionalEnv); } if (LOG.isDebugEnabled()) { LOG.debug("Initializing LDAP context using URL [" + url + "] and username [" + username + "] " + "with pooling [" + (usePooling ? "enabled" : "disabled") + "]"); } return new InitialLdapContext(env, null); }
From source file:org.apache.synapse.message.store.impl.jdbc.util.JDBCConfiguration.java
/** * Reading lookup information for existing datasource * * @param parameters - parameters given in configuration *//* ww w . j av a 2 s . c om*/ private void readLookupConfig(Map<String, Object> parameters) { String dataSourceName = (String) parameters.get(JDBCMessageStoreConstants.JDBC_DSNAME); this.setDataSourceName(dataSourceName); if (parameters.get(JDBCMessageStoreConstants.JDBC_ICCLASS) != null) { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, parameters.get(JDBCMessageStoreConstants.JDBC_ICCLASS)); props.put(Context.PROVIDER_URL, parameters.get(JDBCMessageStoreConstants.JDBC_CONNECTION_URL)); props.put(Context.SECURITY_PRINCIPAL, parameters.get(JDBCMessageStoreConstants.JDBC_USERNAME)); props.put(Context.SECURITY_CREDENTIALS, parameters.get(JDBCMessageStoreConstants.JDBC_PASSWORD)); this.setJndiProperties(props); } }
From source file:org.easy.ldap.LdapContextFactory.java
public DirContext createSecureContext(LdapName rootDn, LdapName principal, String password, String securityMethod) throws NamingException { Hashtable<String, String> environment = getEnviroment(); environment.put(Context.PROVIDER_URL, createProviderUrl(rootDn.toString())); environment.put(Context.SECURITY_AUTHENTICATION, securityMethod); environment.put(Context.SECURITY_PRINCIPAL, principal.toString()); environment.put(Context.SECURITY_CREDENTIALS, password); return createContext(environment); }
From source file:org.apache.lens.server.user.LDAPBackedDatabaseUserConfigLoader.java
/** * Instantiates a new LDAP backed database user config loader. * * @param conf the conf/* w w w. ja va 2 s. c o m*/ * @throws UserConfigLoaderException the user config loader exception */ public LDAPBackedDatabaseUserConfigLoader(final HiveConf conf) throws UserConfigLoaderException { super(conf); expiryHours = conf.getInt(LensConfConstants.USER_RESOLVER_CACHE_EXPIRY, 2); intermediateQuerySql = conf.get(LensConfConstants.USER_RESOLVER_LDAP_INTERMEDIATE_DB_QUERY); intermediateDeleteSql = conf.get(LensConfConstants.USER_RESOLVER_LDAP_INTERMEDIATE_DB_DELETE_SQL); intermediateInsertSql = conf.get(LensConfConstants.USER_RESOLVER_LDAP_INTERMEDIATE_DB_INSERT_SQL); ldapFields = conf.get(LensConfConstants.USER_RESOLVER_LDAP_FIELDS).split("\\s*,\\s*"); searchBase = conf.get(LensConfConstants.USER_RESOLVER_LDAP_SEARCH_BASE); searchFilterPattern = conf.get(LensConfConstants.USER_RESOLVER_LDAP_SEARCH_FILTER); intermediateCache = CacheBuilder.newBuilder().expireAfterWrite(expiryHours, TimeUnit.HOURS) .maximumSize(conf.getInt(LensConfConstants.USER_RESOLVER_CACHE_MAX_SIZE, 100)).build(); cache = CacheBuilder.newBuilder().expireAfterWrite(expiryHours, TimeUnit.HOURS) .maximumSize(conf.getInt(LensConfConstants.USER_RESOLVER_CACHE_MAX_SIZE, 100)).build(); env = new Hashtable<String, Object>() { { put(Context.SECURITY_AUTHENTICATION, "simple"); put(Context.SECURITY_PRINCIPAL, conf.get(LensConfConstants.USER_RESOLVER_LDAP_BIND_DN)); put(Context.SECURITY_CREDENTIALS, conf.get(LensConfConstants.USER_RESOLVER_LDAP_BIND_PASSWORD)); put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); put(Context.PROVIDER_URL, conf.get(LensConfConstants.USER_RESOLVER_LDAP_URL)); put("java.naming.ldap.attributes.binary", "objectSID"); } }; }
From source file:org.jboss.test.security.test.SubjectContextUnitTestCase.java
public void testAllAuthMethod() throws Exception { log.debug("+++ testAllAuthMethod()"); 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.allAuthMethod(info);// w w w . j a v a2s. co m bean.remove(); }
From source file:com.zabbix.gateway.JMXItemChecker.java
public JMXItemChecker(JSONObject request) throws ZabbixException { super(request); try {//from ww w. j a va2 s . co m String conn = request.getString(JSON_TAG_CONN); int port = request.getInt(JSON_TAG_PORT); jmxc = null; mbsc = null; String jmx_url = "service:jmx:rmi:///jndi/rmi://[" + conn + "]:" + port + "/jmxrmi"; // default String jboss_url = "service:jmx:remoting-jmx://" + conn + ":" + port; // jboss String t3_url = "service:jmx:t3://" + conn + ":" + port + "/jndi/weblogic.management.mbeanservers.runtime"; // T3 String t3s_url = "service:jmx:t3s://" + conn + ":" + port + "/jndi/weblogic.management.mbeanservers.runtime"; // T3S protocol = "jmx"; String tested_url = jmx_url; username = request.optString(JSON_TAG_USERNAME, null); password = request.optString(JSON_TAG_PASSWORD, null); //if (null != username && null == password || null == username && null != password) // throw new IllegalArgumentException("invalid username and password nullness combination"); if (null != username) { // Testing if username is like "<user>:<protocol>" int protocol_in_username = username.indexOf(':'); if (protocol_in_username != -1) { String result[] = username.split(":"); username = result[0]; protocol = result[1]; } } switch (protocol) { case "jmx": case "jmxs": tested_url = jmx_url; break; case "jboss": tested_url = jboss_url; break; case "t3": tested_url = t3_url; break; case "t3s": tested_url = t3s_url; break; default: tested_url = jmx_url; break; } logger.info("Using url '{}' with user '{}'", tested_url, username); HashMap<String, Object> env = new HashMap<String, Object>(); env.put(JMXConnector.CREDENTIALS, new String[] { username, password }); if (protocol.equals("t3") || protocol.equals("t3s")) { env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); env.put(javax.naming.Context.SECURITY_PRINCIPAL, ((String[]) env.get(JMXConnector.CREDENTIALS))[0]); env.put(javax.naming.Context.SECURITY_CREDENTIALS, ((String[]) env.get(JMXConnector.CREDENTIALS))[1]); } // Required by SSL if (protocol.equals("jmxs")) { env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory()); } url = new JMXServiceURL(tested_url); jmxc = ZabbixJMXConnectorFactory.connect(url, env); mbsc = jmxc.getMBeanServerConnection(); } catch (Exception e) { throw new ZabbixException(e); } finally { try { if (null != jmxc) jmxc.close(); } catch (java.io.IOException exception) { } jmxc = null; mbsc = null; } }
From source file:org.openiam.idm.srvc.synch.service.generic.LdapAdapterForGenericObject.java
private boolean connect(SynchConfig config) throws NamingException { Hashtable<String, String> envDC = new Hashtable(); System.setProperty("javax.net.ssl.trustStore", keystore); String hostUrl = config.getSrcHost(); // managedSys.getHostUrl(); log.debug("Directory host url:" + hostUrl); envDC.put(Context.PROVIDER_URL, hostUrl); envDC.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); envDC.put(Context.SECURITY_AUTHENTICATION, "simple"); // simple envDC.put(Context.SECURITY_PRINCIPAL, config.getSrcLoginId()); // "administrator@diamelle.local" envDC.put(Context.SECURITY_CREDENTIALS, config.getSrcPassword()); if (hostUrl.contains("ldaps")) { envDC.put(Context.SECURITY_PROTOCOL, "SSL"); }/*from w w w . j ava 2 s .co m*/ ctx = new InitialLdapContext(envDC, null); if (ctx != null) { return true; } return false; }
From source file:org.apache.cloudstack.ldap.LdapContextFactory.java
private Hashtable<String, String> getEnvironment(final String principal, final String password, final String providerUrl, final boolean isSystemContext, Long domainId) { final String factory = _ldapConfiguration.getFactory(); String url = providerUrl == null ? _ldapConfiguration.getProviderUrl(domainId) : providerUrl; if (StringUtils.isEmpty(url) && domainId != null) { //try a default ldap implementation url = _ldapConfiguration.getProviderUrl(null); }// w w w.java 2 s . c o m final Hashtable<String, String> environment = new Hashtable<>(); environment.put(Context.INITIAL_CONTEXT_FACTORY, factory); environment.put(Context.PROVIDER_URL, url); environment.put("com.sun.jndi.ldap.read.timeout", _ldapConfiguration.getReadTimeout(domainId).toString()); environment.put("com.sun.jndi.ldap.connect.pool", "true"); enableSSL(environment); setAuthentication(environment, isSystemContext, domainId); if (principal != null) { environment.put(Context.SECURITY_PRINCIPAL, principal); } if (password != null) { environment.put(Context.SECURITY_CREDENTIALS, password); } return environment; }