Skip to content

Commit

Permalink
升级至spring boot 2.0.2 RELEASE 主要解决spring-data-jpa 和social社交登录问题
Browse files Browse the repository at this point in the history
  • Loading branch information
longfeizheng committed Jun 13, 2018
1 parent fe39ea7 commit f51ee38
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 34 deletions.
68 changes: 61 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<name>logback</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--<parent>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-parent</artifactId>-->
<!--<version>2.0.2.RELEASE</version>-->
<!--<relativePath/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
<!--</parent>-->

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -29,7 +29,6 @@
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -159,6 +158,11 @@
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-autoconfigure</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand All @@ -183,6 +187,18 @@

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Cairo-SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand All @@ -195,4 +211,42 @@
</plugins>
<finalName>spring-security</finalName>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
response.getWriter().write(objectMapper.writeValueAsString(ResultUtil.error(ResultEnum.FAIL.getCode(), message)));
}else if(exception instanceof ValidateCodeException){
response.getWriter().write(objectMapper.writeValueAsString(ResultUtil.error(ResultEnum.CODE_ERROT.getCode(), exception.getMessage())));
}else{
response.getWriter().write(objectMapper.writeValueAsString(ResultUtil.error(ResultEnum.FAIL.getCode(), exception.getMessage())));
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/merryyou/logback/schedue/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Slf4j
public class Task {

//@Scheduled(cron = "0/10 * * * * ? ")
// @Scheduled(cron = "* 0/1 * * * ? ")
public void cron() throws Exception{
log.info("定时任务执行中。。。。");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.merryyou.logback.repository.SysUserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
Expand Down Expand Up @@ -49,8 +50,9 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
permissions = sysMenuService.getPermissions(user.getUsername());
log.info(permissions);
return new SysUser(user.getUsername(), user.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(permissions));
}else{
throw new BadCredentialsException("用户名不存在!");
}
return new SysUser();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class MerryyouBaseServiceImpl<T> implements MerryyouBaseService<

@Override
public T findOne(String id) {
return (T)merryyouRepository.findOne(id);
return (T)merryyouRepository.findById(id).get();
}

@Override
Expand All @@ -41,6 +41,6 @@ public Page<T> findAll(PageRequest pageRequest) {

@Override
public void delete(String id) {
merryyouRepository.delete(id);
merryyouRepository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public List<Person> findAll() {

@Override
public Person findOne(Integer id) {
return repository.findOne(id);
return repository.findById(id).get();
}

@Override
public void delete(Integer id) {
repository.delete(id);
repository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Result saveRole(String data) {
String menuIds = roleDtoList.get(0).getMenuIds();
if (StringUtils.isEmpty(menuIds)) return ResultUtil.error(ResultEnum.FAIL.getCode(), "请选择角色对应的权限!");
for (String str : menuIds.split(",")) {
sysMenu = menuRepository.findOne(str);
sysMenu = menuRepository.findById(str).get();
sysRole.getMenus().add(sysMenu);
}
roleRepository.save(sysRole);
Expand All @@ -72,7 +72,7 @@ public Result saveRole(String data) {

@Override
public RoleDto findRole(String id) {
SysRole sysRole = roleRepository.findOne(id);
SysRole sysRole = roleRepository.findById(id).get();
String menuIds = "";
List<SysMenu> menus = sysRole.getMenus();
for (SysMenu sysMenu : menus) {
Expand All @@ -94,7 +94,7 @@ public Result<String> delRoles(String ids) {
if (users != null && users.size() > 0) {
return ResultUtil.success("选择的角色已绑定用户!");
}
roleRepository.delete(id);
roleRepository.deleteById(id);
}

return ResultUtil.success("删除成功!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<UserDto> findAll() {
@Override
public UserDto findOne(String id) {

SysUser sysUser = userRepository.findOne(id);
SysUser sysUser = userRepository.findById(id).get();
if (sysUser != null) {
UserDto userDto = new UserDto();
BeanUtils.copyProperties(sysUser, userDto);
Expand Down Expand Up @@ -97,7 +97,7 @@ public Result save(String data) {
List<SysRole> roleList = new ArrayList<>();
SysRole sysRole;
for (String str : roles.split(",")) {
sysRole = roleRepository.findOne(str);
sysRole = roleRepository.findById(str).get();
roleList.add(sysRole);
}
SysUser sysUser = new SysUser();
Expand All @@ -114,7 +114,7 @@ public Result<String> delUsers(String ids) {
if (StringUtils.isEmpty(ids)) return ResultUtil.error(ResultEnum.FAIL.getCode(), "请选择要删除的行!");
String[] userIds = ids.split(",");
for (String id : userIds) {
userRepository.delete(id);
userRepository.deleteById(id);
}
return ResultUtil.success("删除成功!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
@Component
public class MyConnectionSignUp implements ConnectionSignUp {
@Override

public String execute(Connection<?> connection) {
//根据社交用户信息,默认创建用户并返回用户唯一标识
return connection.getDisplayName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import cn.merryyou.logback.social.SocialConnectView;
import cn.merryyou.logback.social.qq.connect.QQConnectionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.social.autoconfigure.SocialAutoConfigurerAdapter;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import cn.merryyou.logback.properties.SecurityConstants;
import cn.merryyou.logback.social.SocialConnectView;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.autoconfigure.SocialAutoConfigurerAdapter;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.social.weibo.connect.WeiboConnectionFactory;
import org.springframework.web.servlet.View;

//import cn.merryyou.logback.social.SocialAutoConfigurerAdapter;


/**
* Created on 2018/1/12.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import cn.merryyou.logback.social.SocialConnectView;
import cn.merryyou.logback.social.weixin.connect.WeixinConnectionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.autoconfigure.SocialAutoConfigurerAdapter;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;

import static cn.merryyou.logback.properties.SecurityConstants.DEFAULT_SOCIAL_WEIXIN_PROVIDER_ID;

//import cn.merryyou.logback.social.SocialAutoConfigurerAdapter;

/**
* Created on 2018/1/11.
*
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
server:
port: 80
session:
timeout: 1800
servlet:
session:
timeout: 1800s
spring:
profiles:
active: prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void save() {

@Test
public void findOne() {
Person person = repository.findOne(1);
Person person = repository.findById(1).get();
log.info("【person】 person={}",person);
}

Expand All @@ -50,7 +50,7 @@ public void findByAge() throws Exception {

@Test
public void update() {
Person person = repository.findOne(1);
Person person = repository.findById(1).get();
person.setAddress("city");
Person resultPerson = repository.save(person);
Assert.assertNotNull(resultPerson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class SysRoleRepositoryTest {

@Test
public void findOneTest() throws Exception {
SysRole role = sysRoleRepository.findOne("2619a672e53811e7b983201a068c6482");
SysRole role = sysRoleRepository.findById("2619a672e53811e7b983201a068c6482").get();
log.info("【SysRole】 role={}", role);
}

@Test
public void findMenuByRole() throws Exception {
SysRole role = sysRoleRepository.findOne("2619a672e53811e7b983201a068c6482");
SysRole role = sysRoleRepository.findById("2619a672e53811e7b983201a068c6482").get();
List<SysMenu> menus = role.getMenus();
for (SysMenu sysMenu : menus) {
log.info(sysMenu.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class SysUserRepositoryTest {
*/
@Test
public void findOneTest() throws Exception {
SysUser user = repository.findOne("acfc0e9232f54732a5d9ffe9071bf572");
SysUser user = repository.findById("acfc0e9232f54732a5d9ffe9071bf572").get();
log.info("【SysUser】 SysUser={}", user);
}

Expand All @@ -52,7 +52,7 @@ public void findOneTest() throws Exception {
*/
@Test
public void findRolesByUser() throws Exception {
SysUser user = repository.findOne("acfc0e9232f54732a5d9ffe9071bf572");
SysUser user = repository.findById("acfc0e9232f54732a5d9ffe9071bf572").get();
List<SysRole> roles = user.getRoles();
for (SysRole role : roles) {
log.info(role.toString());
Expand All @@ -67,7 +67,7 @@ public void findRolesByUser() throws Exception {
*/
@Test
public void findUserByRole() throws Exception {
SysRole sysRole = roleRepository.findOne("0ea934e5e55411e7b983201a068c6482");
SysRole sysRole = roleRepository.findById("0ea934e5e55411e7b983201a068c6482").get();
List<SysUser> users = sysRole.getUsers();
for (SysUser user : users) {
log.info(user.toString());
Expand All @@ -93,8 +93,8 @@ public void findByUsernameTest() throws Exception {
*/
@Test
public void saveSysUserTest() throws Exception {
SysRole sysRole1 = roleRepository.findOne("0ea934e5e55411e7b983201a068c6482");
SysRole sysRole2 = roleRepository.findOne("2619a672e53811e7b983201a068c6482");
SysRole sysRole1 = roleRepository.findById("0ea934e5e55411e7b983201a068c6482").get();
SysRole sysRole2 = roleRepository.findById("2619a672e53811e7b983201a068c6482").get();
SysUser user = new SysUser();
user.setUsername("test");
user.setPassword(bCryptPasswordEncoder.encode("123456"));
Expand Down

0 comments on commit f51ee38

Please sign in to comment.