List of usage examples for org.apache.shiro.authc AccountException AccountException
public AccountException(Throwable cause)
From source file:aaa.realms.MySQLRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { VTNAuthNToken upToken = (VTNAuthNToken) token; String username = upToken.getUsername(); String domainID = Integer.toString(upToken.getDomainId()); // Null username is invalid if (username == null) { throw new AccountException("Null usernames are not allowed by this realm."); }/*from ww w . j a v a2s.c om*/ Connection conn = null; SimpleAuthenticationInfo info = null; try { conn = dataSource.getConnection(); Set<String> domains = getUserDomain(conn, username); if (!(domains.contains(domainID))) { throw new AuthenticationException("Domain not found"); } String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(conn, username)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); //break; case COLUMN: String[] queryResults = getPasswordForUser(conn, username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(conn, username)[0]; salt = getSaltForUser(username); } if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (SQLException e) { final String message = "There was a SQL error while authenticating user [" + username + "]"; if (log.isErrorEnabled()) { log.error(message, e); } // Rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } finally { JdbcUtils.closeConnection(conn); } return info; }
From source file:b4f.seguridad.SecurityAuthenticator.java
@Override public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException { if (DEBUG) {/*from www . j av a2 s . co m*/ System.out.println("[SECURITY AUTHENTICATOR] Autenticando: " + at); } //SE ACCEDI CON UN JWT TOKEN if (at instanceof JwtToken) { JwtToken authToken = (JwtToken) at; if (authToken.getToken() != null && !authToken.getToken().equals("")) { if (!authToken.validar()) { throw new AccountException("Token invalido."); } try { Usuario user = UsersManager.getUser(authToken.getUser()); if (user == null) throw new Exception("Token invalido"); SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(); authenticationInfo.setPrincipals(new SimplePrincipalCollection(user, user.getUsuario())); return authenticationInfo; } catch (Exception ex) { Logger.getLogger(ShiroAuthorizingRealm.class.getName()).log(Level.SEVERE, null, ex); throw new AuthenticationException(ex.getMessage()); } } else { throw new AccountException("Token invalido."); } } DefaultSecurityManager dsm = new DefaultSecurityManager(getRealm()); AuthenticationInfo authenticationInfo = dsm.authenticate(at); if (DEBUG) { System.out.println("[SECURITY AUTHENTICATOR] " + authenticationInfo); } return authenticationInfo; }
From source file:br.com.betsportclub.controller.security.SecurityRealm.java
License:Apache License
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername(); // Null username is invalid if (username == null) { throw new AccountException("Null usernames are not allowed by this realm."); }//from w w w . j a v a 2 s . c o m Connection conn = null; SimpleAuthenticationInfo info = null; try { conn = dataSource.getConnection(); String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(conn, username)[0]; break; case CRYPT: // TODO: separate password and hash from getPasswordForUser[0] throw new ConfigurationException("Not implemented yet"); //break; case COLUMN: String[] queryResults = getPasswordForUser(conn, username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(conn, username)[0]; salt = getSaltForUser(username); } if (password == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } info = new SimpleAuthenticationInfo(username, password.toCharArray(), getName()); if (salt != null) { info.setCredentialsSalt(ByteSource.Util.bytes(salt)); } } catch (SQLException e) { final String message = "There was a SQL error while authenticating user [" + username + "]"; if (log.isErrorEnabled()) { log.error(message, e); } // Rethrow any SQL errors as an authentication exception throw new AuthenticationException(message, e); } finally { JdbcUtils.closeConnection(conn); } return info; }
From source file:cn.ruiyi.base.service.shiro.ShiroDbRealm.java
License:Apache License
/** * ?,./*from w ww. j av a 2 s . c o m*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; //System.out.println("?"); // System.out.println("token.getUsername():"+token.getUsername()); // System.out.println("token.getPassword():"+token.getPassword()); // System.out.println("token.getPrincipal().toString():"+(token.getPrincipal().toString())); // System.out.println("token.getCredentials().toString():"+(token.getCredentials().toString())); // //token.getPassword(); String username = token.getUsername(); if (token.getUsername() == null) { throw new AccountException("Null usernames are not allowed by this realm."); } User user = null; //try{ user = accountService.findUserByLoginName(token.getUsername()); if (user == null) { throw new UnknownAccountException("No account found for user [" + username + "]"); } //}catch(Exception e){ // throw new UnknownAccountException("No account found for user [" // + username + "]"); //} //System.out.println("user email:"+user.getEmail()); SimpleAuthenticationInfo saInfo = new SimpleAuthenticationInfo(user.getLoginName(), user.getPassword(), getName()); // ??? //saInfo.setCredentialsSalt(ByteSource.Util.bytes(username)); return saInfo; //return null; }
From source file:co.edu.uniandes.csw.miso4204.security.auth.SecurityAuthenticator.java
public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException { JwtToken authToken = (JwtToken) at;/*from ww w . j a v a2s.com*/ if (authToken.getToken() != null) { if (!authToken.getToken().equals("")) { //Descifrar token y establecer info de usuario UserDTO user = decodeUser(authToken.getToken()); if (validarToken(user)) { SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(); authenticationInfo.setPrincipals(new SimplePrincipalCollection(user, user.getUsername())); return authenticationInfo; } } } throw new AccountException("Token invalido."); }
From source file:co.edu.uniandes.csw.uniandes.seguridad.JwtAuthenticator.java
public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException { JwtToken authToken = (JwtToken) at;//w w w . j a v a 2 s . c o m if (authToken.getToken() != null) { //Descifrar token y establecer info de usuario if (validarToken(authToken.getToken())) { SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(); info.setPrincipals(new SimplePrincipalCollection(new Usuario("usuario1", "1"), "usuario1")); return info; } } throw new AccountException("Token invalido."); }
From source file:co.edu.uniandes.hospitalkennedy.security.otro.SecurityAuthenticator.java
public AuthenticationInfo authenticate(AuthenticationToken at) throws AuthenticationException { System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); JwtToken authToken = (JwtToken) at;// ww w. j a v a 2s . c o m if (authToken.getToken() != null) { if (!authToken.getToken().equals("")) { //Descifrar token y establecer info de usuario UserDTO user = decodeUser(authToken.getToken()); if (validarToken(user)) { SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(); authenticationInfo.setPrincipals(new SimplePrincipalCollection(user, user.getUsername())); PathInfo pathInfo = PathInfo.getInstance(); if (!pathInfo.autenticar(user.getGrupo())) throw new AccountException("Token invalido."); return authenticationInfo; } } } throw new AccountException("Token invalido."); }
From source file:com.asia.bomc.workflow.security.SecurityRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; String username = token.getUsername(); if (StringUtils.isEmpty(username)) { throw new AccountException("Null usernames are not allowed."); }/*from w w w. j a v a2 s.c o m*/ UserLogin user = null; try { List<UserLogin> users = UserService.findByUserName(username); if (users.size() > 0) user = users.get(0); else throw new UnknownAccountException("???:[" + username + "]?"); } catch (Exception e) { throw new UnknownAccountException(e.getMessage()); } SimpleAuthenticationInfo saInfo = new SimpleAuthenticationInfo(user.getUserLoginId(), user.getPassword(), getName()); return saInfo; }
From source file:com.autumnframework.common.shiroconfig.realm.ShiroDbRealm.java
License:Open Source License
/** * ???//from ww w.j a v a 2 s. c o m * * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { // if (!super.isAuthenticationCachingEnabled()) { // super.setCachingEnabled(authenticationCachingEnabled); // } UsernamePasswordToken userToken = (UsernamePasswordToken) token; String username = userToken.getUsername(); if (StringUtils.isEmpty(username)) { log.error("???:??"); throw new AccountException("??"); } // ???? User user = userService.selectUserByloginName(username); if (user == null) { throw new AccountException("?"); } log.debug("authenticationCachingEnabled:" + super.isAuthenticationCachingEnabled()); SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), getName()); if (null != info) { log.info("?:??:" + user.getUser_login_name()); return info; } return null; }
From source file:com.baguaz.module.user.realm.AdminAuthorizingRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername(); if (username == null) { log.warn("???"); throw new AccountException("???"); }//w w w . j a v a2s . c o m User admin = null; try { admin = User.dao.getAdminByUsername(username); log.debug("???" + username + "?"); } catch (Exception ex) { log.warn("?\n" + ex.getMessage()); } if (admin == null) { log.warn("?"); throw new UnknownAccountException("?!"); } /* if(!admin.getBoolean("isAccountEnabled")) { log.warn("?"); throw new UnknownAccountException("?!"); } if(admin.getBoolean("isAccountLocked")){ log.warn("??"); throw new LockedAccountException("?!"); }*/ UserPrincipal principal = new UserPrincipal(admin); Session session = SecurityUtils.getSubject().getSession(); String tokenV = (String) session.getAttribute(IndexAdminController.TOKEN_NAME); session.removeAttribute(IndexAdminController.TOKEN_NAME); String password = admin.getStr("password"); password = DigestUtils.sha256Hex(password + tokenV); //AdminRoleM role=AdminRoleM.dao.findById(admin.getInt("roleid")); //principal.setRole(role); //List<String> authorities = AdminRolePrivM.dao.getAuthoritiesName(admin.getInt("roleid")); //principal.setAuthorities(authorities); //principal.setAuthorized(true); return new SimpleAuthenticationInfo(principal, password, getName()); }