1.1.8 优化登录
This commit is contained in:
parent
0888447168
commit
e1ea387530
|
@ -1,8 +1,8 @@
|
|||
yexuejc-springboot 更新内容
|
||||
-------------------
|
||||
|
||||
#### version :1.1.6-1.1.7
|
||||
**time:2018-11-21 14:18:46** <br/>
|
||||
#### version :1.1.6-1.1.8
|
||||
**time:2018-11-21 15:03:01** <br/>
|
||||
**branch:** master <br/>
|
||||
**关联工程:** <br/>
|
||||
```
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.yexuejc.springboot</groupId>
|
||||
<artifactId>yexuejc-springboot-parent</artifactId>
|
||||
<version>1.1.7</version>
|
||||
<version>1.1.8</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>com.yexuejc.springboot</groupId>
|
||||
<artifactId>yexuejc-springboot-parent</artifactId>
|
||||
<version>1.1.7</version>
|
||||
<version>1.1.8</version>
|
||||
<!-- 本地打包:使用相对关联路径 -->
|
||||
<!--<relativePath>../../yexuejc</relativePath>-->
|
||||
</parent>
|
||||
|
|
|
@ -178,15 +178,14 @@ public class ConsumerAuthenticationProvider extends AbstractUserDetailsAuthentic
|
|||
throw notFound;
|
||||
} else {
|
||||
try {
|
||||
third(consumerToken, loadedUser, logtype);
|
||||
return third(consumerToken, loadedUser, logtype);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (e instanceof ThirdPartyAuthorizationException) {
|
||||
throw e;
|
||||
}
|
||||
throw new ThirdPartyAuthorizationException("登录失败,请稍后重试");
|
||||
throw new ThirdPartyAuthorizationException(e.getMessage());
|
||||
}
|
||||
throw notFound;
|
||||
}
|
||||
} catch (Exception repositoryProblem) {
|
||||
throw new InternalAuthenticationServiceException(
|
||||
|
@ -211,10 +210,10 @@ public class ConsumerAuthenticationProvider extends AbstractUserDetailsAuthentic
|
|||
//其他方式登录:查询账号 没有->创建账号
|
||||
//第三方登录
|
||||
if (consumerToken != null && StrUtil.isNotEmpty(consumerToken.getOpenid())) {
|
||||
ApiVO apiVO = accountView.checkOpenId(consumerToken);
|
||||
if (apiVO.isSucc()) {
|
||||
Object obj = accountView.checkOpenId(consumerToken);
|
||||
if (obj != null) {
|
||||
|
||||
//已有账号
|
||||
Object obj = apiVO.getObject1(Object.class);
|
||||
if (obj instanceof User) {
|
||||
User consumer = (User) obj;
|
||||
// 处理用户权限
|
||||
|
@ -229,7 +228,8 @@ public class ConsumerAuthenticationProvider extends AbstractUserDetailsAuthentic
|
|||
logtype, System.currentTimeMillis());
|
||||
return loadedUser;
|
||||
} else if (obj instanceof UserDetails) {
|
||||
return (UserDetails) obj;
|
||||
loadedUser = (UserDetails) obj;
|
||||
return loadedUser;
|
||||
} else {
|
||||
throw new ClassConvertExeption("获取登录用户信息返回结果类型必须是com.yexuejc.springboot.base.security.inte.User实现类" +
|
||||
"或者org.springframework.security.core.userdetails.UserDetails实现类" +
|
||||
|
@ -241,25 +241,26 @@ public class ConsumerAuthenticationProvider extends AbstractUserDetailsAuthentic
|
|||
if (consumerToken != null) {
|
||||
//没有->创建账号
|
||||
consumerToken.isReg = true;
|
||||
ApiVO apiVO = accountView.addConsumer(consumerToken);
|
||||
if (apiVO.isSucc()) {
|
||||
Object obj = apiVO.getObject1(Object.class);
|
||||
Object obj = accountView.addConsumer(consumerToken);
|
||||
if (obj != null) {
|
||||
if (obj instanceof User) {
|
||||
User consumer = (User) obj;
|
||||
loadedUser = display(consumerToken, consumer);
|
||||
return loadedUser;
|
||||
} else if (obj instanceof UserDetails) {
|
||||
return (UserDetails) obj;
|
||||
loadedUser = (UserDetails) obj;
|
||||
return loadedUser;
|
||||
} else {
|
||||
throw new ClassConvertExeption("获取登录用户信息返回结果类型必须是com.yexuejc.springboot.base.security.inte.User实现类" +
|
||||
"或者org.springframework.security.core.userdetails.UserDetails实现类" +
|
||||
"或者com.yexuejc.springboot.base.security.ConsumerUser继承类");
|
||||
}
|
||||
} else {
|
||||
throw new ThirdPartyAuthorizationException(apiVO.getMsg());
|
||||
throw new ThirdPartyAuthorizationException("第三方登录失败");
|
||||
}
|
||||
} else {
|
||||
throw new ThirdPartyAuthorizationException();
|
||||
}
|
||||
return loadedUser;
|
||||
}
|
||||
|
||||
private void prepareTimingAttackProtection() {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class UserDetailsManager extends InMemoryUserDetailsManager {
|
|||
return loadUser(username);
|
||||
}
|
||||
|
||||
protected ConsumerUser loadUser(String username) {
|
||||
protected ConsumerUser loadUser(String username) throws UsernameNotFoundException{
|
||||
Object user = userService.getConsumerByUserName(username);
|
||||
if (user instanceof User) {
|
||||
User consumer = (User) user;
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.yexuejc.springboot.base.security.inte;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录用户接口
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName User
|
||||
|
|
|
@ -2,9 +2,13 @@ package com.yexuejc.springboot.base.security.inte;
|
|||
|
||||
import com.yexuejc.base.pojo.ApiVO;
|
||||
import com.yexuejc.springboot.base.constant.BizConsts;
|
||||
import com.yexuejc.springboot.base.exception.UserNotAuthoriayException;
|
||||
import com.yexuejc.springboot.base.security.ConsumerToken;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
* 用户登录处理接口
|
||||
*
|
||||
* @author maxf
|
||||
* @version 1.0
|
||||
* @ClassName UserService
|
||||
|
@ -14,11 +18,18 @@ import com.yexuejc.springboot.base.security.ConsumerToken;
|
|||
public interface UserService {
|
||||
/**
|
||||
* 根据用户名到数据库查询用户
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 获取登录用户信息返回结果类型必须是
|
||||
* {@link com.yexuejc.springboot.base.security.inte.User}实现类<br/>
|
||||
* 或者{@link com.yexuejc.springboot.base.security.ConsumerUser}继承类
|
||||
* </p>
|
||||
*
|
||||
* @param username 登录账号
|
||||
* @return
|
||||
*/
|
||||
Object getConsumerByUserName(String username);
|
||||
Object getConsumerByUserName(String username) throws UserNotAuthoriayException, UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
* 校验短信验证码=>短信登录
|
||||
|
@ -32,17 +43,29 @@ public interface UserService {
|
|||
|
||||
/**
|
||||
* 校验第三方登录openid
|
||||
* <p>
|
||||
* 获取登录用户信息返回结果类型必须是
|
||||
* {@link com.yexuejc.springboot.base.security.inte.User}实现类<br/>
|
||||
* 或者{@link org.springframework.security.core.userdetails.UserDetails}实现类<br/>
|
||||
* 或者{@link com.yexuejc.springboot.base.security.ConsumerUser}继承类
|
||||
* </p>
|
||||
*
|
||||
* @param consumerToken 登录信息
|
||||
* @return apiVO.setObject1(User.class) 自己封装登录用户信息
|
||||
* @return 自己封装登录用户信息
|
||||
*/
|
||||
ApiVO checkOpenId(ConsumerToken consumerToken);
|
||||
Object checkOpenId(ConsumerToken consumerToken);
|
||||
|
||||
/**
|
||||
* 没有账号时根据登录信息创建账号
|
||||
* <p>
|
||||
* 获取登录用户信息返回结果类型必须是
|
||||
* {@link com.yexuejc.springboot.base.security.inte.User}实现类<br/>
|
||||
* 或者{@link org.springframework.security.core.userdetails.UserDetails}实现类<br/>
|
||||
* 或者{@link com.yexuejc.springboot.base.security.ConsumerUser}继承类
|
||||
* </p>
|
||||
*
|
||||
* @param consumerToken 登录信息
|
||||
* @return
|
||||
* @return 自己封装登录用户信息
|
||||
*/
|
||||
ApiVO addConsumer(ConsumerToken consumerToken);
|
||||
Object addConsumer(ConsumerToken consumerToken);
|
||||
}
|
||||
|
|
|
@ -238,6 +238,7 @@ public class Consumer extends Model<Consumer> implements User {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue