List of usage examples for org.apache.shiro.authc UnknownAccountException UnknownAccountException
public UnknownAccountException(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 ava 2 s . co m 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:au.org.theark.core.security.AAFRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { SimpleAuthenticationInfo sai = null; ArkUserVO userVO = null;//from ww w . j av a2 s . c o m UsernamePasswordToken token = (UsernamePasswordToken) authcToken; //log.info("IN AAFRealm.doGetAuthenticationInfo"); //log.info("authToken: " + authcToken.getPrincipal().toString()); log.info("AAF token username: " + token.getUsername()); try { //log.info("checking user"); userVO = iArkCommonService.getUser(token.getUsername().trim()); if (userVO != null) { // Check if the user is in the Ark Database ArkUser arkUser = iArkCommonService.getArkUser(token.getUsername().trim()); // Also check if the Ark User is linked with any study and has roles. // If no roles found, stop the user from logging in until an administrator has set it up if (!iArkCommonService.isArkUserLinkedToStudies(arkUser)) { throw new UnknownAccountException(UNKNOWN_ACCOUNT); } final WebRequest webRequest = (WebRequest) RequestCycle.get().getRequest(); final HttpServletRequest httpReq = (HttpServletRequest) webRequest.getContainerRequest(); //log.info("checking shib headers"); String userName = httpReq.getHeader("AJP_mail"); String password = httpReq.getHeader("AJP_Shib-Session-ID"); if (userName != null && password != null) { //log.info("creating SimpleAuthenticationInfo"); sai = new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } } } catch (ArkSystemException e) { log.error(e.getMessage()); } catch (EntityNotFoundException e) { throw new UnknownAccountException(UNKNOWN_ACCOUNT); } return sai; }
From source file:au.org.theark.core.security.ArkLdapRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { SimpleAuthenticationInfo sai = null; ArkUserVO userVO = null;/*from w ww.j a v a 2s . c o m*/ UsernamePasswordToken token = (UsernamePasswordToken) authcToken; try { userVO = iArkCommonService.getUser(token.getUsername().trim());// Example to use core services to get user if (userVO != null) { // Check if the user is in the Ark Database ArkUser arkUser = iArkCommonService.getArkUser(token.getUsername().trim()); // Also check if the Ark User is linked with any study and has roles. // If no roles found, stop the user from logging in until an administrator has set it up if (!iArkCommonService.isArkUserLinkedToStudies(arkUser)) { throw new UnknownAccountException(UNKNOWN_ACCOUNT); } sai = new SimpleAuthenticationInfo(userVO.getUserName(), userVO.getPassword(), getName()); } } catch (ArkSystemException e) { log.error(e.getMessage()); } catch (EntityNotFoundException e) { throw new UnknownAccountException(UNKNOWN_ACCOUNT); } return sai; }
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."); }// w w w . jav a 2 s. co 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.guoyukun.spring.shiro.realm.AbstractUserPasswordRealm.java
License:Apache License
/** * ??/*ww w . j a va 2 s.c o m*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upt = (UsernamePasswordToken) token; // String identify = upt.getUsername().trim(); try { // ? SystemAccount account = getAccountByLoginIdentify(identify); // ? if (account == null) { throw new UnknownAccountException("[" + identify + "]??"); } if (account.isLocked()) { throw new LockedAccountException("[" + identify + "]????"); } // LOG.debug("[{}]???:[{}]",identify,account.getCredentials()); SimpleAuthenticationInfo sai = new SimpleAuthenticationInfo(account.getIdentify(), account.getCredentials(), this.getName()); if (!getCredentialsMatcher().doCredentialsMatch(token, sai)) { throw new IncorrectCredentialsException("?"); } LOG.debug("[{}]?", identify); return sai; } catch (AuthenticationException ae) { throw ae; } catch (Exception e) { throw new AuthenticationException("?[" + identify + "]?", e); } }
From source file:cn.ruiyi.base.service.shiro.ShiroDbRealm.java
License:Apache License
/** * ?,.//from ww w .j av a 2s.c om */ @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: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."); }/* w w w .j a v a 2 s . com*/ 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.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("???"); }//from w w w . java 2 s. 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()); }
From source file:com.charmyin.shiro.realm.jdbc.JMongodbRealm.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."); }//w ww . java2 s . c om SimpleAuthenticationInfo info = null; try { //conn = dataSource.getConnection(); String password = null; String salt = null; switch (saltStyle) { case NO_SALT: password = getPasswordForUser(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(username); password = queryResults[0]; salt = queryResults[1]; break; case EXTERNAL: password = getPasswordForUser(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 (MongoException 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); } return info; }
From source file:com.codestudio.dorm.web.security.shiro.ShiroDataBaseRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token; String username = usernamePasswordToken.getUsername(); if (username == null) { throw new AccountException("???"); }/*from w ww .j a v a2s . c o m*/ User user = userService.getUserByWorkNumber(username, true); if (user == null) { throw new UnknownAccountException("?"); } // if (!user.isEnable()) { // throw new AccountException("???"); // } return new SimpleAuthenticationInfo(user, user.getPassword(), getName()); }