Browse Source

token获取增加判断

test
smallchill 5 years ago
parent
commit
132051680b
  1. 7
      blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java
  2. 1
      blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java
  3. 5
      blade-ops/blade-resource/pom.xml

7
blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java

@ -31,6 +31,7 @@ import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
@ -68,7 +69,11 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService {
// 判断返回信息
if (result.isSuccess()) {
User user = result.getData().getUser();
UserInfo userInfo = result.getData();
if (Func.isEmpty(userInfo.getRoles())) {
throw new UserDeniedAuthorizationException(TokenUtil.USER_HAS_NO_ROLE);
}
User user = userInfo.getUser();
if (user == null) {
throw new UsernameNotFoundException(TokenUtil.USER_NOT_FOUND);
}

1
blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java

@ -53,6 +53,7 @@ public class TokenUtil {
public final static String USER_TYPE_HEADER_KEY = "User-Type";
public final static String DEFAULT_USER_TYPE = "web";
public final static String USER_NOT_FOUND = "用户名或密码错误";
public final static String USER_HAS_NO_ROLE = "未获得用户的角色信息";
public final static String HEADER_KEY = "Authorization";
public final static String HEADER_PREFIX = "Basic ";
public final static String DEFAULT_AVATAR = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png";

5
blade-ops/blade-resource/pom.xml

@ -40,6 +40,11 @@
<artifactId>blade-starter-qiniu</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-alioss</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-mybatis</artifactId>

Loading…
Cancel
Save