List of usage examples for org.apache.shiro.authc UnknownAccountException UnknownAccountException
public UnknownAccountException(String message, Throwable cause)
From source file:com.digitalplay.network.ireader.shiro.ShiroDbRealm.java
License:Apache License
/** * ?,./* w w w . j av a2 s . c o m*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) authcToken; String username = upToken.getUsername().trim(); String password = ""; if (upToken.getPassword() != null) { password = new String(upToken.getPassword()); } User user = null; try { user = userService.login(username, password); } catch (UserNotExistsException e) { throw new UnknownAccountException(e.getMessage(), e); } catch (UserPasswordNotMatchException e) { throw new AuthenticationException(e.getMessage(), e); } catch (UserPasswordRetryLimitExceedException e) { throw new ExcessiveAttemptsException(e.getMessage(), e); } catch (UserBlockedException e) { throw new LockedAccountException(e.getMessage(), e); } catch (Exception e) { throw new AuthenticationException(new UserException("user.unknown.error", null)); } SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), password.toCharArray(), getName()); return info; }
From source file:com.huntering.security.UserRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername().trim(); String password = ""; if (upToken.getPassword() != null) { password = new String(upToken.getPassword()); }/* w ww . j a v a2 s .c om*/ Account account = null; try { account = accountService.login(username, password); } catch (UserNotExistsException e) { throw new UnknownAccountException(e.getMessage(), e); } catch (UserPasswordNotMatchException e) { throw new AuthenticationException(e.getMessage(), e); } catch (UserPasswordRetryLimitExceedException e) { throw new ExcessiveAttemptsException(e.getMessage(), e); } catch (UserBlockedException e) { throw new LockedAccountException(e.getMessage(), e); } catch (Exception e) { log.error("login error", e); throw new AuthenticationException(new UserException("user.unknown.error", null)); } String name = username; for (Email email : account.getEmails()) { if (Boolean.TRUE.equals(email.getMain())) { name = email.getEmail(); break; } } SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(name, password.toCharArray(), getName()); return info; }
From source file:com.playersun.jbf.common.shiro.realm.UserRealm.java
License:Apache License
/** * ?//from w w w.ja v a2 s . co m */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername().trim(); String password = ""; if (upToken.getPassword() != null) { password = new String(upToken.getPassword()); } User user = null; try { user = userService.login(username, password); } catch (UserNotExistsException e) { throw new UnknownAccountException(e.getMessage(), e); } catch (UserPasswordNotMatchException e) { throw new AuthenticationException(e.getMessage(), e); } catch (UserPasswordRetryLimitExceedException e) { throw new ExcessiveAttemptsException(e.getMessage(), e); } catch (UserBlockedException e) { throw new LockedAccountException(e.getMessage(), e); } catch (Exception e) { LogUtils.logError("login error", e); throw new AuthenticationException(new UserException("user.unknown.error", null)); } SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), password.toCharArray(), getName()); return info; }
From source file:com.teemo.core.security.ShiroSecurityRealm.java
License:GNU General Public License
/** * /* w w w. j a va 2 s . c om*/ * @param authcToken token * @return SimpleAuthenticationInfo * @throws AuthenticationException */ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; String username = token.getUsername(); String password = ""; if (token.getPassword() != null) { password = new String(token.getPassword()); } User user; try { user = userService.login(username, password); } catch (UserNotExistsException e) { throw new UnknownAccountException(e.getMessage(), e); } catch (UserPasswordIncorrectnessException e) { throw new IncorrectCredentialsException(e.getMessage(), e); } catch (UserBlockedException e) { throw new LockedAccountException(e.getMessage(), e); } setSession(Constants.CURRENT_USER, user); return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), this.getName()); }
From source file:org.apache.camel.component.shiro.security.ShiroSecurityProcessor.java
License:Apache License
private void authenticateUser(Subject currentUser, ShiroSecurityToken securityToken) { boolean authenticated = currentUser.isAuthenticated(); boolean sameUser = securityToken.getUsername().equals(currentUser.getPrincipal()); LOG.trace("Authenticated: {}, same Username: {}", authenticated, sameUser); if (!authenticated || !sameUser) { UsernamePasswordToken token = new UsernamePasswordToken(securityToken.getUsername(), securityToken.getPassword()); if (policy.isAlwaysReauthenticate()) { token.setRememberMe(false);//from w w w .java 2 s .co m } else { token.setRememberMe(true); } try { currentUser.login(token); LOG.debug("Current user {} successfully authenticated", currentUser.getPrincipal()); } catch (UnknownAccountException uae) { throw new UnknownAccountException( "Authentication Failed. There is no user with username of " + token.getPrincipal(), uae.getCause()); } catch (IncorrectCredentialsException ice) { throw new IncorrectCredentialsException( "Authentication Failed. Password for account " + token.getPrincipal() + " was incorrect!", ice.getCause()); } catch (LockedAccountException lae) { throw new LockedAccountException("Authentication Failed. The account for username " + token.getPrincipal() + " is locked." + "Please contact your administrator to unlock it.", lae.getCause()); } catch (AuthenticationException ae) { throw new AuthenticationException("Authentication Failed.", ae.getCause()); } } }
From source file:org.sonatype.nexus.jsecurity.realms.external.crowd.CrowdAuthenticatingRealm.java
License:Open Source License
@Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { String username = (String) principals.getPrimaryPrincipal(); try {/* www. ja v a 2s.co m*/ List<String> roles = crowdClientHolder.getNexusRoleManager().getNexusRoles(username); return new SimpleAuthorizationInfo(new HashSet<String>(roles)); } catch (RemoteException e) { throw new AuthorizationException("Could not retrieve info from Crowd.", e); } catch (UserNotFoundException e) { throw new UnknownAccountException("User " + username + " not found", e); } catch (InvalidAuthenticationException e) { throw new IncorrectCredentialsException(e); } catch (InvalidAuthorizationTokenException e) { throw new AuthorizationException("Could not retrieve info from Crowd.", e); } }