/** * 认证回调函数,登录时调用. */ @Override protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken authcToken) throws AuthenticationException { UsernamePassword2Token token = (UsernamePassword2Token) authcToken; String username = token.getUsername(); if (username == null || null == username) { throw new AccountException( "Null usernames are not allowed by this realm."); } User entity = new User(); entity.setEmail(username); entity.setStatus(Constant.STATUS_ENABLED); entity = (User) service.iUserService.select(entity); if (null == entity) { throw new UnknownAccountException("No account found for user [" + username + "]"); } byte[] key = Encode.decodeHex(entity.getRandom()); return new SimpleAuthenticationInfo(new Shiro(entity.getId(), entity.getEmail(), entity.getName()), entity.getPassword(), ByteSource.Util.bytes(key), getName()); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { //UsernamePasswordToken对象用来存放提交的登录信息 UsernamePasswordToken token=(UsernamePasswordToken) authenticationToken; log.info("验证当前Subject时获取到token为:" + ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE)); // return new SimpleAuthenticationInfo("hsjhsj","8e24137dee97c9bbddb9a0cd6e043be4" , getName()); return new SimpleAuthenticationInfo("hsjhsj","" , getName()); //查出是否有此用户 // TbUser user=null; // if(user!=null){ // 若存在,将此用户存放到登录认证info中,无需自己做密码对比,Shiro会为我们进行密码对比校验 // return new SimpleAuthenticationInfo(user.getUsername(), , getName()); // } // return null; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException { String token = (String) auth.getCredentials(); Cache<String, String> authCache = CacheController.getAuthCache(); if (! authCache.containsKey(token)) { // get user info from database int uid = JWTUtil.getUid(token); UserEntity userEntity = userService.getUserByUid(uid); authCache.put(token, String.valueOf(userEntity.getPassword())); } String secret = authCache.get(token); if (!JWTUtil.decode(token, secret)) { throw new AuthenticationException("Token invalid"); } return new SimpleAuthenticationInfo(token, token, "jwt_realm"); }
/** * 用户认证-验证用户是否登录、用户名密码是否匹配 */ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { logger.info(">>> 【用户认证】token = {}", token); String userName = (String)token.getPrincipal(); AdminUser user = getPrincipalService().getPrincipalObject(userName); if(user == null) { throw new UnknownAccountException("Unknown account: " + userName);//没找到帐号 } if(AdminUserStatusEnum.ADMIN_USER_STATUS_DISABLED.getStatusCode().equals(user.getStatus())) { throw new LockedAccountException("Account[" + userName + "] has been locked!"); //帐号锁定 } //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配 SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( user.getUserName(), //用户名 user.getPassword(), //密码 ByteSource.Util.bytes(user.getPasswordSalt()),//salt getName() //realm name ); return authenticationInfo; }
/** * 先执行登录验证 * @param token * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { //获取用户名密码 String username = token.getPrincipal().toString(); TbUser tbUser = userService.getUserByUsername(username); if (tbUser != null){ //得到用户账号和密码存放到authenticationInfo中用于Controller层的权限判断 第三个参数随意不能为null AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(tbUser.getUsername(),tbUser.getPassword(), tbUser.getUsername()) ; return authenticationInfo ; }else{ return null ; } }
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; Map<String, Object> params = new HashMap<String, Object>(); params.put("enable", 1); params.put("account", token.getUsername()); Parameter parameter = new Parameter("sysUserService", "queryList").setMap(params); logger.info("{} execute sysUserService.queryList start...", parameter.getNo()); List<?> list = provider.execute(parameter).getList(); logger.info("{} execute sysUserService.queryList end.", parameter.getNo()); if (list.size() == 1) { SysUser user = (SysUser) list.get(0); StringBuilder sb = new StringBuilder(100); for (int i = 0; i < token.getPassword().length; i++) { sb.append(token.getPassword()[i]); } if (user.getPassword().equals(sb.toString())) { WebUtil.saveCurrentUser(user.getId()); saveSession(user.getAccount(), token.getHost()); AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(), user.getUserName()); return authcInfo; } logger.warn("USER [{}] PASSWORD IS WRONG: {}", token.getUsername(), sb.toString()); return null; } else { logger.warn("No user: {}", token.getUsername()); return null; } }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { // token是用户输入的用户名和密码 // 第一步从token中取出用户名 String userCode = (String) token.getPrincipal(); // 如果查询不到返回null //数据库中用户账号是zhangsansan // if(!userCode.equals("zhangsansan")){// // return null; // } // 模拟从数据库查询到密码 String password = "111111"; //将activeUser设置simpleAuthenticationInfo SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo( userCode, password, this.getName()); return simpleAuthenticationInfo; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String) token.getPrincipal();// 根据刚刚传过来的token获取用户名 Blogger blogger = bloggerService.findByUsername(username);// 只是根据用户名查询出,不涉及密码 if (blogger != null) { System.out.println("验证信息:" + blogger); // 把获取到的用户存到session中 SecurityUtils.getSubject().getSession().setAttribute("blogger", blogger); // 把从数据库中查询出来的博主信息放到AuthenticationInfo中,即把正确的用户名,密码,交给shiro,再和前台输入的校验。 AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(blogger.getUsername(), blogger.getPassword(), "MyRealm"); return authenticationInfo; } else { return null; } }
/** * 认证回调函数,登录时调用. */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; // User user = accountManager.findUserByLoginName(token.getUsername()); //根据loginToken 看能不查到当前token token有效期就1分钟 String tokenPassword=new String(token.getPassword()); User user = accountManager.findUserByLoginNameOrEmail(token.getUsername()); //user.getStandardLock()==1 if (user != null && user.getStatus().intValue()!=0 && !user.getLoginName().endsWith("@chacuo.net")) { return new SimpleAuthenticationInfo(user.getLoginName(), user.getShaPassword() , getName()); } else { return null; } }
/** * 登录认证,在权限认证前执行 * * @param token * @return AuthenticationInfo * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = token.getPrincipal().toString(); UUser user = userMService.findUserByUserName(username); if (null == user) { return null; } else { /** * info中principal选择方案:1.username, 2.User, 3.UserWithRoleAndPermission * 各有优劣,这里选择使用username * * EAO isssue: 新建对象WholeUser,有属性roles,permissions,登录时产生此对象作为principals,则authorization时无需再和sql交互 * 1.优势: 减少sql交互, * 2.劣势:缓存大,对变更的用户信息反馈不及时 * 适用: 变化不大信息量少,但权限校验频繁的用户类型. * * SimpleAuthorizationInfo: param: principal检查源码最后被强转为Collection不知何意?? */ SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), "UserRealm"); return info; } }
/** * 登录认证,在权限认证前执行 * * @param token * @return AuthenticationInfo * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String userName = token.getPrincipal().toString(); UUser user = userFService.findUserByUsername(userName); if (null == user) { return null; } else { /** * info中principal选择方案:1.username, 2.User, 3.UserWithRoleAndPermission * 各有优劣,这里选择使用username * * EAO isssue: 新建对象WholeUser,有属性roles,permissions,登录时产生此对象作为principals,则authorization时无需再和sql交互 * 1.优势: 减少sql交互, * 2.劣势:缓存大,对变更的用户信息反馈不及时 * 适用: 变化不大信息量少,但权限校验频繁的用户类型. * * SimpleAuthorizationInfo: param: principal检查源码最后被强转为Collection不知何意?? */ SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), "UserRealm"); return info; } }
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; /* if (Strings.isBlank(upToken.getCaptcha())) throw new AuthenticationException("验证码不能为空"); String _captcha = Strings.sBlank(SecurityUtils.getSubject().getSession(true).getAttribute(Toolkit.captcha_attr)); if (!upToken.getCaptcha().equalsIgnoreCase(_captcha)) throw new AuthenticationException("验证码错误");*/ User user = dao().fetch(User.class, Cnd.where("name", "=", upToken.getUsername())); if (user == null) return null; if (user.isLocked()) throw new LockedAccountException("Account [" + upToken.getUsername() + "] is locked."); ByteSource salt = ByteSource.Util.bytes(user.getSalt()); SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), getName()); info.setCredentialsSalt(salt); return info; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String phoneNumber = (String)token.getPrincipal(); if(StringUtils.trimToNull(phoneNumber) == null){ throw new IncorrectCredentialsException();//账号或密码错误 } CdMember query = new CdMember(); query.setPhoneNumber(phoneNumber); CdMember member = memberService.findMember(query); if(member == null) { throw new UnknownAccountException();//没找到帐号 } SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( phoneNumber, //用户名 member.getPassword(), //密码 ByteSource.Util.bytes(AppConstants.PC_PASSWORD_SALT),//salt=phoneNumber getName() //realm name ); return authenticationInfo; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String)token.getPrincipal(); SysUsers user = userService.findByUsername(username); if(user == null) { throw new UnknownAccountException();//没找到帐号 } if(Boolean.TRUE.equals(user.getLocked())) { throw new LockedAccountException(); //帐号锁定 } //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得人家的不好可以自定义实现 SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( username, //用户名 user.getPassword(), //密码 ByteSource.Util.bytes(user.getSalt()),//salt=salt getName() //realm name ); return authenticationInfo; }
protected AuthenticationInfo createPasswordAuthenticationInfo(SysUser u){ if (u != null) { byte[] salt = Encodes.decodeHex(u.getSalt()); List<Integer> roleIds = Lists.newArrayList(); for (SysRole role : u.getRoleList()) { roleIds.add(role.getId()); } Object principal = new ShiroUser(u.getLoginName(), u.getUsername(),u.getUniqueCode(), u.getUserCode(), u.getId(), u.getSysOrg().getId(), u.getSysOrg().getOrgName(), roleIds, u.getHeadimgurl(), u.getAccesstoken(), u.getOpenid(), u.getUnionid(), u.getPhone(), u.getOwnerOrgId()); AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(principal,u.getPassword(),ByteSource.Util.bytes(salt), getName()); return authenticationInfo; } else { return null; } }
protected AuthenticationInfo createAuthenticationInfo(SysUser u){ if (u != null) { List<Integer> roleIds = Lists.newArrayList(); for (SysRole role : u.getRoleList()) { roleIds.add(role.getId()); } AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( new ShiroUser(u.getLoginName(), u.getUsername(),u.getUniqueCode(), u.getUserCode(), u.getId(), u.getSysOrg() .getId(), u.getSysOrg().getOrgName(), roleIds, u.getHeadimgurl(), u.getAccesstoken(), u.getOpenid(), u.getUnionid(), u.getPhone(), u.getOwnerOrgId()), u.getPassword(), getName()); return authenticationInfo; } else { return null; } }
@Override protected AuthenticationInfo doGetAuthenticationInfo( final AuthenticationToken token) throws AuthenticationException { final UsernamePasswordToken credentials = (UsernamePasswordToken) token; final String userName = credentials.getUsername(); if (userName == null) { throw new UnknownAccountException("userName not provided"); } Account account = accountRepository.findByLoginName(userName); if (account == null) { throw new UnknownAccountException("Account does not exist"); } return new SimpleAuthenticationInfo(userName, account.getPassword().toCharArray(), ByteSource.Util.bytes(userName), getName()); }
/** * 登录认证 */ @Override protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken authenticationToken) throws AuthenticationException { //UsernamePasswordToken对象用来存放提交的登录信息 UsernamePasswordToken token=(UsernamePasswordToken) authenticationToken; logger.info("验证当前Subject时获取到token为:" + ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE)); //查出是否有此用户 User user=userDao.findByUsername(token.getUsername()); if(user!=null){ // 若存在,将此用户存放到登录认证info中,无需自己做密码对比,Shiro会为我们进行密码对比校验 return new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName()); } return null; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { if (token instanceof UsernamePasswordToken) { String username = ((UsernamePasswordToken) token).getUsername(); char[] password = ((UsernamePasswordToken) token).getPassword(); if (Strings.isNullOrEmpty(username) || password == null) { return null; } User user = userRepository.findByUsername(username); if (user == null) { throw new UnknownAccountException(); } return new SimpleAuthenticationInfo(new Principal(user.getId(), username), user.getPassword(), new SimpleByteSource(user.getUsername()), getName()); } return null; }
/** * 认证回调函数,登录时调用 */ protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; String accountName = token.getUsername(); String password = new String(token.getPassword()); // 用户名密码验证 if (accountName != null && !"".equals(accountName)) { //UserService userService = BGDispatch.userService; User user = User.dao.findFirst( " select* from user where username= ? and password=?", accountName,password); if (user != null) return new SimpleAuthenticationInfo(new Principal(user), password, accountName); return null; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { log.debug("username[{}]doGetAuthenticationInfo", token.getPrincipal()); String username = (String)token.getPrincipal(); ShiroUser user = memberService.findUserModelByAccNo(username); if(user == null) { throw new UnknownAccountException(); } //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配 SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( user.getAccNo(), user.getPassword(), ByteSource.Util.bytes(""),//加盐 getName() //realm name ); return authenticationInfo; }
/** * 首先执行这个登录验证 * @param token * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { //获取用户账号 String username = token.getPrincipal().toString() ; T_user user = t_userService.findUserByUsername(username) ; if (user != null){ //将查询到的用户账号和密码存放到 authenticationInfo用于后面的权限判断。第三个参数随便放一个就行了。 AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUserName(),user.getPassword(), "a") ; return authenticationInfo ; }else{ return null ; } }
/** * create authentication info, by default, this create * SimpleAuthenticationInfo with principals using access token as primary * principal and a map contains attributes {@link OAuth#OAUTH_ACCESS_TOKEN} * and {@link OAuth#OAUTH_EXPIRES_IN} and {@link OAuth#OAUTH_REFRESH_TOKEN} * and {@link OAuthConstants#OAUTH_TOKEN_TIME} and * {@link OAuthConstants#OAUTH_SCOPES}, the credentials set to byte array of * access token. if sub-class override requestAttributes and returned * attributes contains key {@link OAuthConstants#OAUTH_PRINCIPAL}, then the * value will be used as primary principal. * * @param clientToken * the client token * @param oAuthResponse * OAuth access token response * @return authentication info */ protected AuthenticationInfo buildAuthenticationInfo(OAuthClientToken clientToken, OAuthAccessTokenResponse oAuthResponse) { String accessToken = oAuthResponse.getAccessToken(); Date tokenTime = new Date(); Map<String, Object> attributes = requestAttributes(oAuthResponse); if (attributes == null) attributes = new HashMap<String, Object>(); else attributes = new HashMap<String, Object>(attributes); List<Object> principals = new ArrayList<Object>(); if (attributes.containsKey(OAuthConstants.OAUTH_PRINCIPAL)) principals.add(attributes.get(OAuthConstants.OAUTH_PRINCIPAL)); else principals.add(accessToken); attributes.put(OAuth.OAUTH_ACCESS_TOKEN, accessToken); attributes.put(OAuth.OAUTH_EXPIRES_IN, oAuthResponse.getExpiresIn()); attributes.put(OAuth.OAUTH_REFRESH_TOKEN, oAuthResponse.getRefreshToken()); attributes.put(OAuthConstants.OAUTH_TOKEN_TIME, tokenTime); attributes.put(OAuthConstants.OAUTH_SCOPES, clientToken.getScopes()); principals.add(attributes); PrincipalCollection collection = new SimplePrincipalCollection(principals, getName()); return new SimpleAuthenticationInfo(collection, accessToken); }
@Override protected AuthenticationInfo doGetAuthenticationInfo( AuthenticationToken token ) throws AuthenticationException { UnitOfWork uow = uowf.newUnitOfWork(); try { String username = ( (UsernamePasswordToken) token ).getUsername(); PasswordSecurable account = findPasswordSecurable( uow, username ); if( account == null ) { LOG.debug( "Unknown subject identifier: {}" + username ); return null; } LOG.debug( "Found account for {}: {}", username, account ); return new SimpleAuthenticationInfo( account.subjectIdentifier().get(), account.password() .get(), getName() ); } finally { uow.discard(); } }
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { checkNotNull(token); final PrincipalCollection principals = keyStore.getPrincipals(format, (char[]) token.getCredentials()); if (null != principals) { try { if (anonymousAndSupported(principals) || UserStatus.active.equals(principalsHelper.getUserStatus(principals))) { ((NexusApiKeyAuthenticationToken) token).setPrincipal(principals.getPrimaryPrincipal()); return new SimpleAuthenticationInfo(principals, token.getCredentials()); } } catch (final UserNotFoundException e) { log.debug("Realm did not find user", e); keyStore.deleteApiKeys(principals); } } return null; }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String password = new String(upToken.getPassword()); String userId = upToken.getUsername(); // username == password try { if (userId.endsWith(password) && userManager.getUser(userId) != null) { return new SimpleAuthenticationInfo(new SimplePrincipalCollection(token.getPrincipal(), this.getName()), userId); } else { throw new IncorrectCredentialsException("User [" + userId + "] bad credentials."); } } catch (UserNotFoundException e) { throw new UnknownAccountException("User [" + userId + "] not found."); } }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String) token.getPrincipal(); User user = userService.findByName(username); if (user == null) { throw new UnknownAccountException();// 没找到帐号 } if (Boolean.TRUE.equals(user.getLocked())) { throw new LockedAccountException(); // 帐号锁定 } // 交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得不好可以自定义实现 SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user, user.getPassword(), // 密码 ByteSource.Util.bytes(user.getSalt()),// salt getName() // realm name ); return authenticationInfo; }
@Override public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { JsonWebToken jsonWebToken = (JsonWebToken) token; JWTVerifier verifier = new JWTVerifier(secret, audience); try { Map<String, Object> map = verifier.verify(jsonWebToken.getToken()); SimpleAuthenticationInfo authenticationInfo = (SimpleAuthenticationInfo) info; String realmName = authenticationInfo.getPrincipals().getRealmNames().iterator().next(); SimplePrincipalCollection principals = new SimplePrincipalCollection(); principals.add(map.get("iss"), realmName); authenticationInfo.setPrincipals(principals); return true; } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | SignatureException | IOException | JWTVerifyException e) { log.debug(e.getMessage()); return false; } }
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { Object _principal = token.getPrincipal(); final String username = ((String) _principal); final Operator operator = commonRepository.findOne("t_operator", "username", username, new OperatorRowMapper()); boolean _equals = Objects.equal(operator, null); if (_equals) { throw new UnknownAccountException(); } Boolean _enable = operator.getEnable(); boolean _equals_1 = Boolean.FALSE.equals(_enable); if (_equals_1) { throw new LockedAccountException(); } String _username = operator.getUsername(); String _password = operator.getPassword(); byte[] _bytes = "I\'m a salt".getBytes(); ByteSource _bytes_1 = ByteSource.Util.bytes(_bytes); String _name = this.getName(); final SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(_username, _password, _bytes_1, _name); return authenticationInfo; }
/** * * @param authenticationToken * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { final UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; final User user = this.accountService .findUserByUsername(token.getUsername()); if (user != null) { return new SimpleAuthenticationInfo( token.getUsername(), user.getPassword(), this.getName()); } throw new IncorrectCredentialsException("Invalid user or password"); }
/** * * @param authenticationToken * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { final UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; final User user = this.accountService .findUserByUsername(token.getUsername()); if (user != null) { return new SimpleAuthenticationInfo( user, user.getPassword(), this.getName()); } throw new IncorrectCredentialsException("Invalid user or password"); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken userToken = (UsernamePasswordToken) token; UnixUser user; try { user = (new PAM(this.getService())) .authenticate(userToken.getUsername(), new String(userToken.getPassword())); } catch (PAMException e) { throw new AuthenticationException("Authentication failed for PAM.", e); } return new SimpleAuthenticationInfo( new UserPrincipal(user), userToken.getCredentials(), getName()); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken; LoginUser loginUser = Goja.securityUserData.user(token.getUsername()); if (loginUser == null) { return null; } final AppUser appUser = loginUser.getAppUser(); if (appUser == null) { return null; } byte[] salt = EncodeKit.decodeHex(loginUser.getSalt()); return new SimpleAuthenticationInfo(appUser, loginUser.getPassword() , ByteSource.Util.bytes(salt), getName()); }
@Override public void setupModule(SetupContext context) { context.setMixInAnnotations(Object.class, DisableGetters.class); context.setMixInAnnotations(Collection.class, DisableTypeInfo.class); context.setMixInAnnotations(Map.class, DisableTypeInfo.class); // context.setMixInAnnotations(Array.class, DisableTypeInfo.class); //Default types for interfaces unknown to Jackson context.setMixInAnnotations(Bindings.class, UseSimpleBindings.class); context.setMixInAnnotations(PrincipalCollection.class, UseSimplePrincipalCollection.class); //serializers and typeinfo for shiro classes context.setMixInAnnotations(SimpleAuthenticationInfo.class, UseTypeInfoForCredentials.class); context.setMixInAnnotations(SimpleHash.class, SimpleHashMixin.class); context.setMixInAnnotations(ByteSource.class, UseSimpleByteSource.class); context.setMixInAnnotations(SimpleByteSource.class, SimpleByteSourceMixin.class); //and it's safer to use public interfaces on some classes context.setMixInAnnotations(ConstraintViolation.class, UseDefaultAutoDetect.class); context.setMixInAnnotations(ConstraintDescriptor.class, UseDefaultAutoDetect.class); context.setMixInAnnotations(Node.class, UseDefaultAutoDetect.class); }
/** * Method description * * * @param token * @param result * * @return */ private AuthenticationInfo createAuthenticationInfo(PublicKeyToken token, AuthenticationResult result) { User user = result.getUser(); Collection<String> groups = authenticate(result); SimplePrincipalCollection collection = new SimplePrincipalCollection(); /* * the first (primary) principal should be a unique identifier */ collection.add(user.getId(), NAME); collection.add(user, NAME); collection.add(new GroupNames(groups), NAME); return new SimpleAuthenticationInfo(collection, token.getPublicKey()); }
/** * Method description * * * @param token * @param result * * @return */ private AuthenticationInfo createAuthenticationInfo( UsernamePasswordToken token, AuthenticationResult result) { User user = result.getUser(); Collection<String> groups = authenticate( new String(token.getPassword()), result); SimplePrincipalCollection collection = new SimplePrincipalCollection(); /* * the first (primary) principal should be a unique identifier */ collection.add(user.getId(), NAME); collection.add(user, NAME); collection.add(new GroupNames(groups), NAME); return new SimpleAuthenticationInfo(collection, token.getPassword()); }
@Override protected AuthenticationInfo doGetAuthenticationInfo( final AuthenticationToken token) throws AuthenticationException { final UsernamePasswordToken credentials = (UsernamePasswordToken) token; final String email = credentials.getUsername(); if (email == null) { throw new UnknownAccountException("Email not provided"); } final User user = userRepository.findByEmailAndActive(email, true); if (user == null) { throw new UnknownAccountException("Account does not exist"); } return new SimpleAuthenticationInfo(email, user.getPassword().toCharArray(), ByteSource.Util.bytes(email), getName()); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = token.getPrincipal().toString(); User user = this.jpaRealmRepository.findUserByName(username); if (null == user) { log.error("没有相关用户!"); throw new UnknownAccountException(); } String principal = username; String hashedCredentials = user.getPasswordHash(); ByteSource credentialsSalt = ByteSource.Util.bytes(user.getName() + new String(user.getPasswordSalt())); String realmName = getName(); SimpleAuthenticationInfo authentication = new SimpleAuthenticationInfo(principal, hashedCredentials, credentialsSalt, realmName); return authentication; }
@Override 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."); } User user = userService.findActiveUser(username); if(user == null) user = userService.findActiveUserByEmail(username); if(user == null || !user.isEnabled() || !user.getRealm().equals(AGATE_REALM)) throw new UnknownAccountException("No account found for user [" + username + "]"); username = user.getName(); UserCredentials userCredentials = userService.findUserCredentials(username); if(userCredentials == null) throw new UnknownAccountException("No account found for user [" + username + "]"); SimpleAuthenticationInfo authInfo = new SimpleAuthenticationInfo(username, userCredentials.getPassword(), getName()); authInfo.setCredentialsSalt(new SimpleByteSource(salt)); return authInfo; }