List of usage examples for org.apache.shiro.authc AuthenticationToken getCredentials
Object getCredentials();
From source file:cn.evilcoder.fantasyblog4j.shiro.ShiroDbRealm.java
License:Apache License
/** * ?,.//from w ww .j a v a 2 s . c om */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = String.valueOf(token.getPrincipal()); String password = new String((char[]) token.getCredentials()); User user = userService.selectByUsername(username); if (user == null) { throw new AuthenticationException("???."); } if (!userService.checkPassword(user, password)) { throw new AuthenticationException("???."); } return new SimpleAuthenticationInfo(username, password, getName()); }
From source file:com.baomidou.kisso.common.shiro.SSOAuthRealm.java
License:Apache License
/** * ???/*from w ww.j a v a2 s. c o m*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); }
From source file:com.beginner.core.shiro.BeginnerRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String) token.getPrincipal(); // ?? String password = new String((char[]) token.getCredentials()); // ? if (null != username && null != password) { return new SimpleAuthenticationInfo(username, password, getName()); } else {//from w ww . j a v a2 s . c o m return null; } }
From source file:com.jeecms.core.security.BbsCredentialsMatcher.java
License:Apache License
/** * This implementation first hashes the {@code token}'s credentials, potentially using a * {@code salt} if the {@code info} argument is a * {@link org.apache.shiro.authc.SaltedAuthenticationInfo SaltedAuthenticationInfo}. It then compares the hash * against the {@code AuthenticationInfo}'s * {@link #getCredentials(org.apache.shiro.authc.AuthenticationInfo) already-hashed credentials}. This method * returns {@code true} if those two values are {@link #equals(Object, Object) equal}, {@code false} otherwise. * * @param token the {@code AuthenticationToken} submitted during the authentication attempt. * @param info the {@code AuthenticationInfo} stored in the system matching the token principal * @return {@code true} if the provided token credentials hash match to the stored account credentials hash, * {@code false} otherwise/*from ww w .j a v a 2 s . c o m*/ * @since 1.1 */ @Override public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { Object accountCredentials = getCredentials(info); char[] rawPass = (char[]) token.getCredentials(); String encodePass = encodePassword(String.valueOf(rawPass), salt); return equals(encodePass, accountCredentials); }
From source file:com.jeecms.core.security.BbsCredentialsMatcher.java
License:Apache License
/** * Hash the provided {@code token}'s credentials using the salt stored with the account if the * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see * the class-level JavaDoc for why this is the preferred approach). * <p/>//from w ww . j a va2 s .c o m * If the {@code info} instance is <em>not</em> * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0 * backwards-compatible logic: it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}. See the class-level * JavaDoc for why this is not recommended. This 'fallback' logic exists only for backwards-compatibility. * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances * if account credentials salting is enabled (highly recommended for password-based systems). * * @param token the submitted authentication token from which its credentials will be hashed * @param info the stored account data, potentially used to acquire a salt * @return the token credentials hash * @since 1.1 */ protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) { Object salt = null; if (info instanceof SaltedAuthenticationInfo) { salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt(); } else { //retain 1.0 backwards compatibility: if (isHashSalted()) { salt = getSalt(token); } } return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations()); }
From source file:com.josue.kingdom.security.application.ApplicationFilter.java
@Override protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) { HttpServletRequest httpRequest = WebUtils.toHttp(request); //TODO improve.... check null, etc ManagerToken managerToken = null;/*from www.jav a2 s. c om*/ String appCredentials = httpRequest.getHeader(KINGDOM_HEADER); if (appCredentials != null) { String parsedHeader = new String(DatatypeConverter.parseBase64Binary(appCredentials)); String[] split = parsedHeader.split(CREDENTIAL_SEPARATOR); if (split.length == 2) { String managerLogin = parsedHeader.split(CREDENTIAL_SEPARATOR)[0]; char[] managerPassword = parsedHeader.split(CREDENTIAL_SEPARATOR)[1].toCharArray(); managerToken = new ManagerToken(managerLogin, managerPassword); } } AuthenticationToken authToken = super.createToken(request, response); //TODO validate if its an email or a username ApplicationToken apiToken = new ApplicationToken(authToken.getPrincipal(), authToken.getCredentials(), managerToken); return apiToken; }
From source file:com.josue.shiro.token.based.custom.APIKeyAuthorizingRealm.java
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { AuthenticationInfo info = null;/*from w w w . j a v a2s. c o m*/ if ("123".equals(token.getPrincipal())) { info = new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName()); } return info; }
From source file:com.manydesigns.portofino.shiro.GAEPortofinoRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) { if (!(token instanceof ServletContainerToken)) { throw new UnsupportedTokenException("Token not supported: " + token); }/* w w w .j ava2 s. c o m*/ //On GAE, if the user was logged by the container, it is also known to the UserService UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user == null) { throw new UnknownAccountException( "User is authenticated to the container, but is not known to the UserService"); } //TODO verifica utilizzo User come principal direttamente return new SimpleAuthenticationInfo(user, token.getCredentials(), getName()); }
From source file:com.migo.shiro.UserRealm.java
License:Apache License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { String username = (String) authenticationToken.getPrincipal(); String password = new String((char[]) authenticationToken.getCredentials()); //?/*w ww . j a v a2s. co m*/ SysUserEntity user = sysUserService.queryByUserName(username); //?? if (user == null) { throw new UnknownAccountException("???"); } //? if (!password.equals(user.getPassword())) { throw new IncorrectCredentialsException("???"); } //?? if (user.getStatus() == 0) { throw new LockedAccountException("??,??"); } return new SimpleAuthenticationInfo(user, password, getName()); }
From source file:com.oakeel.shiro.PtpRealm.java
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken at) throws AuthenticationException { try {//from w w w . j a v a 2 s .com InitialContext ic = new InitialContext(); userEaoLocal = (UserEaoLocal) ic.lookup("java:global/PTPSystemManage/UserEao"); } catch (NamingException ex) { Logger.getLogger(PtpRealm.class.getName()).log(Level.SEVERE, null, ex); } String voucher = (String) at.getPrincipal(); //? String password = new String((char[]) at.getCredentials()); //? //?????-?-?-? Boolean pass = false; if (userEaoLocal.validateUserByName(voucher, password)) { pass = true; } else if (userEaoLocal.validateUserByTelephone(voucher, password)) { pass = true; } else if (userEaoLocal.validateUserByEmail(voucher, password)) { pass = true; } if (!pass) { throw new UnknownAccountException(); //?? } AuthenticationInfo info = new SimpleAuthenticationInfo(voucher, password, voucher); return info; }