提交 30064e3b authored 作者: gongwenjie's avatar gongwenjie

撤销 "合并分支 'gwj' 到 'master'"

这将还原合并请求 !8
上级 37a59a26
......@@ -52,10 +52,7 @@
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -3,7 +3,6 @@ package com.zjty.tynotes.pas.config;
import com.zjty.tynotes.pas.config.handler.MyAccessHandler;
import com.zjty.tynotes.pas.config.handler.MyFailHandler;
import com.zjty.tynotes.pas.config.handler.MyLogoutHandler;
import com.zjty.tynotes.pas.config.handler.MySuccessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -37,8 +36,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private MyAccessHandler accessHandler;
@Autowired
private MyEntryPoint myEntryPoint;
@Autowired
private MySuccessHandler successHandler;
@Autowired
private MyUserDetailsServiceImpl myUserDetailsServiceImpl;
......@@ -81,7 +78,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.addFilterAt(myFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(corsFilter(), ChannelProcessingFilter.class)
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).disable().sessionManagement().maximumSessions(1).expiredUrl("/userLogout").sessionRegistry(sessionRegistry())
;
}
......@@ -94,7 +90,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public MyFilter myFilter() throws Exception {
MyFilter filter = new MyFilter();
filter.setAuthenticationSuccessHandler(successHandler);
filter.setAuthenticationFailureHandler(failHandler);
filter.setFilterProcessesUrl("/userLogin");
filter.setAuthenticationManager(this.authenticationManager());
......
package com.zjty.tynotes.pas.config.handler;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zjty.tynotes.pas.dao.AuthorityDao;
import com.zjty.tynotes.pas.dao.RoleAuthorityDao;
import com.zjty.tynotes.pas.dao.RoleDao;
import com.zjty.tynotes.pas.dao.UserRoleDao;
import com.zjty.tynotes.pas.entity.*;
import com.zjty.tynotes.pas.entity.Authority;
import com.zjty.tynotes.pas.entity.Role;
import com.zjty.tynotes.pas.entity.User;
import com.zjty.tynotes.pas.service.IAuthorityService;
import com.zjty.tynotes.pas.service.IRoleService;
import com.zjty.tynotes.pas.service.IUserService;
import com.zjty.tynotes.pas.task.Init;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
......@@ -29,11 +26,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author mcj
......@@ -48,13 +42,7 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
private IAuthorityService iAuthorityService;
@Autowired
RoleDao roleDao;
@Autowired
private UserRoleDao userRoleDao;
@Autowired
private RoleAuthorityDao roleAuthorityDao;
@Autowired
private AuthorityDao authorityDao;
IRoleService iRoleService;
private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
......@@ -63,8 +51,6 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
@Autowired
RedisTemplate redisTemplate;
@Autowired
private Init init;
@Override
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
......@@ -88,32 +74,13 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
}
}
// redisTemplate.opsForValue().set(user.getUsername(),0);
if(("root").equals(user.getUsername())){
user = init.root;
}else{
List<UserRole> userRoles = userRoleDao.findAllByUserId(user.getId());
List<Role> roles = new ArrayList<>();
for (UserRole userRole : userRoles) {
String roleId = userRole.getRoleId();
Optional<Role> op = roleDao.findById(userRole.getRoleId());
if(op.isPresent()){
Role role = op.get();
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(roleId);
List<String> authorityIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) {
authorityIds.add(roleAuthority.getAuthorityId());
}
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
role.setAuthorities(authorities);
roles.add(role);
}
}
user.setRoles(roles);
}
redisTemplate.opsForValue().set(user.getUsername(),0);
sessionRegistry.registerNewSession(value, authentication.getPrincipal());
httpServletResponse.setStatus(200);
httpServletResponse.setContentType("application/json; charset=utf-8");
httpServletResponse.getWriter().println(new ObjectMapper().writeValueAsString(user));
httpServletResponse.getWriter().println(new ObjectMapper().writeValueAsString("登陆成功"));
}
}
......@@ -7,7 +7,6 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
......@@ -18,9 +17,9 @@ import java.util.HashMap;
* @Version 1.0
*/
@Api(tags = "用户管理权限管理模块",protocols = "http")
@RestController
@RequestMapping("/pas/count")
@AutoDocument
@Controller
public class LoginController {
@Autowired
......@@ -28,16 +27,10 @@ public class LoginController {
@ApiOperation(value = "登陆失败计数",response = String.class)
@PostMapping
@ResponseBody
public ResponseEntity login(@RequestBody String username){
String s = iUserService.addUserCount(username);
HashMap<Object, Object> map = new HashMap<>(16);
map.put("msg",s);
return ResponseEntity.ok(map);
}
@GetMapping("/login")
public String login2(){
return "login";
}
}
......@@ -18,7 +18,7 @@ spring.data.mongodb.uri=mongodb://localhost:27017/notes
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB
spring.redis.host=127.0.0.1
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.timeout=5000ms
......
......@@ -13,9 +13,8 @@ server.port=8289
## 证书别名
#server.ssl.keyAlias= alias
#mongodb configuration
spring.data.mongodb.uri=mongodb://localhost:27017/note
spring.data.mongodb.uri=mongodb://localhost:27017/notes
# servlet configuration
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论