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