List of usage examples for javax.naming AuthenticationException getMessage
public String getMessage()
From source file:org.josso.gateway.identity.service.store.ldap.LDAPBindIdentityStore.java
/** * This store performs a bind to the configured LDAP server and closes the connection immediately. * If the connection fails, an exception is thrown, otherwise this method returns silentrly * * @return true if the bind is successful */// w ww. ja va2s.c o m public boolean bind(String username, String password) throws SSOAuthenticationException { try { // first try to retrieve the user using an known user String dn = selectUserDN(username); if (dn == null) { // user not found throw new AuthenticationFailureException("No DN found for user : " + username, "AUTH_FAILED_NO_USER"); } else { logger.debug("user dn = " + dn); } try { // Try to bind to LDAP an check for authentication problems. InitialLdapContext ctx = this.createLdapInitialContext(dn, password); ctx.close(); } catch (AuthenticationException e) { if (logger.isDebugEnabled()) logger.debug("Authentication error : " + e.getMessage(), e); return false; } return true; } catch (Exception e) { if (e instanceof AuthenticationFailureException) { throw new AuthenticationFailureException("Cannot bind as user : " + username + " " + e.getMessage(), ((AuthenticationFailureException) e).getErrorType()); } else { throw new SSOAuthenticationException(e.getMessage(), e); } } }
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// www . j a va 2 s . com 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:org.rifidi.emulator.reader.llrp.airprotocol.c1g2._C1G2Kill.java
public _OpSpecResult performOperation(RifidiTag tag) { C1G2Tag c1g2tag = (C1G2Tag) tag.getTag(); int result = 0; try {//from w w w . j av a 2 s . c o m logger.debug("Attempting to kill tag"); C1G2Operations.C1G2KillTag(c1g2tag, killPassword); } catch (AuthenticationException e) { result = 1; logger.debug("Write error: " + e.getMessage()); } return new _C1G2KillOpSpecResult(this.OpSpecID, result); }
From source file:org.rifidi.emulator.reader.llrp.airprotocol.c1g2._C1G2Lock.java
public _OpSpecResult performOperation(RifidiTag tag) { C1G2Tag c1g2tag = (C1G2Tag) tag.getTag(); int result = 0; for (_C1G2LockPayload p : LockPayloadList) { try {//from www . j a v a2 s .c om logger.debug("Attempting to Lock tag"); C1G2Operations.C1G2LockTag(c1g2tag, p.getData(), this.accessPassword, p.getPrivilege()); } catch (AuthenticationException e) { logger.debug("c1g2lock error: " + e.getMessage()); result = 1; } catch (InvalidMemoryAccessException e) { logger.debug("c1g2lock error: " + e.getError()); result = 1; } } return new _C1G2LockOpSpecResult(this.OpSpecID, result); }
From source file:org.rifidi.emulator.reader.llrp.airprotocol.c1g2._C1G2Write.java
public _OpSpecResult performOperation(RifidiTag tag) { C1G2Tag c1g2tag = (C1G2Tag) tag.getTag(); int result = 0; try {//from w w w . j a v a 2s. c om logger.debug("Attempting to write tag"); C1G2Operations.C1G2WriteTagMem(c1g2tag, tag.getTagEntitiyID(), this.memoryBank, this.wordPtr, writeData, accessPassword, callback, antenna); } catch (AuthenticationException e) { logger.debug("C1G2Write error: " + e.getMessage()); result = 1; } catch (InvalidMemoryAccessException e) { logger.debug("C1G2Write error: " + e.getError()); result = 1; } short wordsWritten; if (result == 0) { wordsWritten = (short) (writeData.length / 2); } else { wordsWritten = 0; } return new _C1G2WriteOpSpecResult(this.OpSpecID, wordsWritten, result); }
From source file:org.wso2.carbon.user.core.ldap.LDAPConnectionContext.java
public LdapContext getContextWithCredentials(String userDN, String password) throws UserStoreException, NamingException, AuthenticationException { LdapContext context = null;// w w w . j ava2s .c o m //create a temp env for this particular authentication session by copying the original env Hashtable<String, String> tempEnv = new Hashtable<String, String>(); for (Object key : environment.keySet()) { tempEnv.put((String) key, (String) environment.get(key)); } //replace connection name and password with the passed credentials to this method tempEnv.put(Context.SECURITY_PRINCIPAL, userDN); tempEnv.put(Context.SECURITY_CREDENTIALS, password); //if dcMap is not populated, it is not DNS case if (dcMap == null) { //replace environment properties with these credentials context = new InitialLdapContext(tempEnv, null); } else if (dcMap != null && dcMap.size() != 0) { try { //first try the first entry in dcMap, if it fails, try iteratively Integer firstKey = dcMap.firstKey(); SRVRecord firstRecord = dcMap.get(firstKey); //compose the connection URL tempEnv.put(Context.PROVIDER_URL, getLDAPURLFromSRVRecord(firstRecord)); context = new InitialLdapContext(tempEnv, null); } catch (AuthenticationException e) { throw e; } catch (NamingException e) { log.error("Error obtaining connection to first Domain Controller." + e.getMessage(), e); log.info("Trying to connect with other Domain Controllers"); for (Integer integer : dcMap.keySet()) { try { SRVRecord srv = dcMap.get(integer); environment.put(Context.PROVIDER_URL, getLDAPURLFromSRVRecord(srv)); context = new InitialLdapContext(environment, null); break; } catch (AuthenticationException e2) { throw e2; } catch (NamingException e1) { if (integer == (dcMap.lastKey())) { log.error("Error obtaining connection for all " + integer + " Domain Controllers." + e1.getMessage(), e1); throw new UserStoreException("Error obtaining connection. " + e1.getMessage(), e1); } } } } } return (context); }