Java Code Examples for cn.hutool.core.util.ObjectUtil#isNotEmpty()

The following examples show how to use cn.hutool.core.util.ObjectUtil#isNotEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenProvider.java    From sk-admin with Apache License 2.0 6 votes vote down vote up
Authentication getAuthentication(String token) {
    Claims claims = Jwts.parser()
            .setSigningKey(key)
            .parseClaimsJws(token)
            .getBody();

    // fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException
    Object authoritiesStr = claims.get(AUTHORITIES_KEY);
    Collection<? extends GrantedAuthority> authorities =
            ObjectUtil.isNotEmpty(authoritiesStr) ?
                    Arrays.stream(authoritiesStr.toString().split(","))
                            .map(SimpleGrantedAuthority::new)
                            .collect(Collectors.toList()) : Collections.emptyList();

    User principal = new User(claims.getSubject(), "", authorities);

    return new UsernamePasswordAuthenticationToken(principal, token, authorities);
}
 
Example 2
Source File: QueryHelp.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) {
    if (ObjectUtil.isNotEmpty(join)) {
        return join.get(attributeName);
    } else {
        return root.get(attributeName);
    }
}
 
Example 3
Source File: TokenProvider.java    From eladmin with Apache License 2.0 5 votes vote down vote up
/**
 * 依据Token 获取鉴权信息
 *
 * @param token /
 * @return /
 */
Authentication getAuthentication(String token) {
    Claims claims = getClaims(token);

    // fix bug: 当前用户如果没有任何权限时,在输入用户名后,刷新验证码会抛IllegalArgumentException
    Object authoritiesStr = claims.get(AUTHORITIES_KEY);
    Collection<? extends GrantedAuthority> authorities =
            ObjectUtil.isNotEmpty(authoritiesStr) ?
                    Arrays.stream(authoritiesStr.toString().split(","))
                            .map(SimpleGrantedAuthority::new)
                            .collect(Collectors.toList()) : Collections.emptyList();
    User principal = new User(claims.getSubject(), "******", authorities);
    return new UsernamePasswordAuthenticationToken(principal, token, authorities);
}
 
Example 4
Source File: QueryHelp.java    From eladmin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) {
    if (ObjectUtil.isNotEmpty(join)) {
        return join.get(attributeName);
    } else {
        return root.get(attributeName);
    }
}
 
Example 5
Source File: UserAvatar.java    From sk-admin with Apache License 2.0 4 votes vote down vote up
public UserAvatar(UserAvatar userAvatar,String realName, String path, String size) {
    this.id = ObjectUtil.isNotEmpty(userAvatar) ? userAvatar.getId() : null;
    this.realName = realName;
    this.path = path;
    this.size = size;
}
 
Example 6
Source File: SysLoginService.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
/**
 * 登录
 */
public SysUser login(String username, String password) {
    // 验证码校验
    if (ObjectUtil.isNotEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA))) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
        throw new CaptchaException();
    }
    // 用户名或密码为空 错误
    if (StrUtil.isEmpty(username) || StrUtil.isEmpty(password)) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null")));
        throw new UserNotExistsException();
    }
    // 密码如果不在指定范围内 错误
    if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
            || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
        throw new UserPasswordNotMatchException();
    }

    // 用户名不在指定范围内 错误
    if (username.length() < UserConstants.USERNAME_MIN_LENGTH
            || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
        throw new UserPasswordNotMatchException();
    }

    // 查询用户信息
    SysUser user = userService.selectUserByLoginName(username);

    if (user == null && maybeMobilePhoneNumber(username)) {
        user = userService.selectUserByPhoneNumber(username);
    }

    if (user == null && maybeEmail(username)) {
        user = userService.selectUserByEmail(username);
    }

    if (user == null) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists")));
        throw new UserNotExistsException();
    }

    if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete")));
        throw new UserDeleteException();
    }

    if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked" , user.getRemark())));
        throw new UserBlockedException();
    }

    passwordService.validate(user, password);

    AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
    recordLoginInfo(user);
    return user;
}