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.ibm.soatf.component.jms.JmsComponent.java
private InitialContext getInitialContext(String providerUrl, String userName, String password) throws NamingException { Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, providerUrl); ht.put(Context.SECURITY_PRINCIPAL, userName); ht.put(Context.SECURITY_CREDENTIALS, password); return new InitialContext(ht); }
From source file:org.apache.syncope.fit.AbstractITCase.java
@SuppressWarnings({ "unchecked", "rawtypes", "UseOfObsoleteCollectionType" }) protected InitialDirContext getLdapResourceDirContext(final String bindDn, final String bindPwd) throws NamingException { ResourceTO ldapRes = resourceService.read(RESOURCE_NAME_LDAP); ConnInstanceTO ldapConn = connectorService.read(ldapRes.getConnector(), Locale.ENGLISH.getLanguage()); Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://" + ldapConn.getConf("host").get().getValues().get(0) + ":" + ldapConn.getConf("port").get().getValues().get(0) + "/"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, bindDn == null ? ldapConn.getConf("principal").get().getValues().get(0) : bindDn); env.put(Context.SECURITY_CREDENTIALS, bindPwd == null ? ldapConn.getConf("credentials").get().getValues().get(0) : bindPwd); return new InitialDirContext(env); }
From source file:com.adito.activedirectory.ActiveDirectoryUserDatabaseConfiguration.java
InitialLdapContext getAuthenticatedContext(String url, Map<String, String> properties) throws NamingException { Hashtable<String, String> variables = new Hashtable<String, String>(properties); variables.put(Context.SECURITY_AUTHENTICATION, getServiceAuthenticationType()); if (!isServiceAuthenticationGssApi()) { variables.put(Context.SECURITY_PRINCIPAL, getServiceAccountName()); variables.put(Context.SECURITY_CREDENTIALS, getServiceAccountPassword()); }// w w w . j a v a 2s .c om return getInitialContext(url, variables); }
From source file:com.funambol.LDAP.security.LDAPUserProvisioningOfficer.java
/** * return the user dn of an ldap entry// w w w . j a v a 2 s.com * * search: base, filter, attrs, user, pass * @return */ protected SearchResult ldapSearch(String bindUser, String bindPass, String base, String filter, String[] attributes) { SearchResult ret = null; Hashtable<String, Object> bindEnv = new Hashtable<String, Object>(11); bindEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); bindEnv.put(Context.PROVIDER_URL, getLdapUrl()); // remove null attributes List<String> goodAttributes = new ArrayList<String>(); for (String s : attributes) { if (s != null) { goodAttributes.add(s); } } // get the DN DirContext authenticationContext; try { SearchControls ctls = new SearchControls(); ctls.setCountLimit(1); ctls.setReturningObjFlag(true); ctls.setReturningAttributes(goodAttributes.toArray(new String[0])); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); // Authenticate as User and password if (bindUser != null && bindPass != null) { log.debug("NBinding with credential as user: " + bindUser); bindEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); bindEnv.put(Context.SECURITY_PRINCIPAL, bindUser); bindEnv.put(Context.SECURITY_CREDENTIALS, bindPass); } authenticationContext = new InitialDirContext(bindEnv); // %u, %d in baseDN are still expanded NamingEnumeration<SearchResult> answer; try { answer = authenticationContext.search(base, filter, ctls); if (answer.hasMore()) { ret = (SearchResult) answer.next(); } } catch (NamingException e) { log.warn("Error while searching user with filter [" + filter + "]: " + e.getMessage()); } authenticationContext.close(); return ret; } catch (NamingException e) { log.error("Error while creating context: " + e.getMessage()); if (e.getCause() != null) { log.error("Error is: " + e.getCause().getMessage()); } return null; } }
From source file:org.ligoj.app.plugin.id.ldap.dao.UserLdapRepository.java
@Override public void setPassword(final UserOrg userLdap, final String password, final String newPassword) { log.info("Changing password for {} ...", userLdap.getId()); final ModificationItem[] passwordChange = { new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD_ATTRIBUTE, digest(newPassword))) }; // Unlock account when the user is locked by ppolicy set(userLdap, PWD_ACCOUNT_LOCKED_ATTRIBUTE, null); // Authenticate the user is needed before changing the password. template.executeReadWrite(new ContextExecutor<>() { @Override//from www. ja va2s .co m public Object executeWithContext(final DirContext dirCtx) throws NamingException { LdapContext ctx = (LdapContext) dirCtx; ctx.removeFromEnvironment(LDAP_CONNECT_POOL); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userLdap.getDn()); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password == null ? getTmpPassword(userLdap) : password); try { ctx.reconnect(null); ctx.modifyAttributes(userLdap.getDn(), passwordChange); } catch (final AuthenticationException e) { log.info("Authentication failed for {}: {}", userLdap.getId(), e.getMessage()); throw new ValidationJsonException("password", "login"); } catch (final InvalidAttributeValueException e) { log.info("Password change failed due to: {}", e.getMessage()); throw new ValidationJsonException("password", "password-policy"); } return null; } }); }
From source file:com.dtolabs.rundeck.jetty.jaas.JettyCachingLdapLoginModule.java
private DirContext createBindUserDirContext(final String userDn, final Object password) throws NamingException { if (null != userBindDirContextCreator) { return userBindDirContextCreator.createBindUserDirContext(userDn, password); }// w ww. j a v a 2s . c om Hashtable environment = getEnvironment(); environment.put(Context.SECURITY_PRINCIPAL, userDn); environment.put(Context.SECURITY_CREDENTIALS, password); return new InitialDirContext(environment); }
From source file:org.opentravel.schemacompiler.security.impl.JNDIAuthenticationProvider.java
/** * Creates the directory context configuration. * /* w w w. ja v a 2 s . c om*/ * @param loginId * the user principal ID to use when establishing the connection * @param loginPassword * the password credentials to use when establishing the connection * @param isConnectionRetry * if true, the alternate URL will be employed * @return Hashtable<String,String> */ protected Hashtable<String, String> getDirectoryContextEnvironment(String loginId, String loginPassword, boolean isConnectionRetry) { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory); if (!isConnectionRetry) { env.put(Context.PROVIDER_URL, connectionUrl); } else if (alternateUrl != null) { env.put(Context.PROVIDER_URL, alternateUrl); } if (loginId != null) { env.put(Context.SECURITY_PRINCIPAL, loginId); } if (loginPassword != null) { env.put(Context.SECURITY_CREDENTIALS, loginPassword); } if (securityAuthentication != null) { env.put(Context.SECURITY_AUTHENTICATION, securityAuthentication); } if (connectionProtocol != null) { env.put(Context.SECURITY_PROTOCOL, connectionProtocol); } if (referralStrategy != null) { env.put(Context.REFERRAL, referralStrategy); } if (connectionTimeout > 0) { env.put("com.sun.jndi.ldap.connect.timeout", connectionTimeout + ""); } return env; }
From source file:com.globalsight.everest.usermgr.UserLdapHelper.java
/** * Binds the user to the context./*w w w . j ava2 s. c o m*/ * * * @param context * @param dn * @param password * @throws NamingException */ static void bindUser(DirContext context, String dn, String password) throws NamingException { if (context != null) { context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn); context.addToEnvironment(Context.SECURITY_CREDENTIALS, password); } }
From source file:com.adaptris.core.SharedComponentListTest.java
private JmsConnection createPtpConnection(String uniqueId) throws PasswordException { JmsConnection c = new JmsConnection(); StandardJndiImplementation jndi = new StandardJndiImplementation(); jndi.setJndiName("Connection_Factory_To_Lookup"); KeyValuePairSet kvps = jndi.getJndiParams(); kvps.addKeyValuePair(new KeyValuePair(Context.SECURITY_PRINCIPAL, "Administrator")); kvps.addKeyValuePair(new KeyValuePair(Context.SECURITY_CREDENTIALS, "Administrator")); kvps.addKeyValuePair(new KeyValuePair("com.sonicsw.jndi.mfcontext.domain", "Domain1")); kvps.addKeyValuePair(/*from w w w . j a va 2 s. c o m*/ new KeyValuePair(Context.INITIAL_CONTEXT_FACTORY, "com.sonicsw.jndi.mfcontext.MFContextFactory")); jndi.getJndiParams().addKeyValuePair(new KeyValuePair(Context.PROVIDER_URL, "tcp://localhost:2506")); c.setVendorImplementation(jndi); if (!isEmpty(uniqueId)) { c.setUniqueId(uniqueId); } return c; }