Explorar el Código

恢复以前配置

yq hace 4 años
padre
commit
d52df0d052
Se han modificado 24 ficheros con 714 adiciones y 638 borrados
  1. 8 8
      fiveep-controller/src/main/java/com/bizmatics/controller/web/UserController.java
  2. 4 4
      fiveep-model/pom.xml
  3. 3 0
      fiveep-service/src/main/java/com/bizmatics/service/UserService.java
  4. 32 32
      fiveep-service/src/main/java/com/bizmatics/service/config/CorsConfig.java
  5. 25 25
      fiveep-service/src/main/java/com/bizmatics/service/config/MyWebConfigurer.java
  6. 62 62
      fiveep-service/src/main/java/com/bizmatics/service/config/SessionFilter.java
  7. 49 49
      fiveep-service/src/main/java/com/bizmatics/service/config/security/CustomPermissionEvaluator.java
  8. 50 50
      fiveep-service/src/main/java/com/bizmatics/service/config/security/CustomerDetailServiceImpl.java
  9. 55 55
      fiveep-service/src/main/java/com/bizmatics/service/config/security/MyAuthenticationProvider.java
  10. 68 68
      fiveep-service/src/main/java/com/bizmatics/service/config/security/UserDetail.java
  11. 94 94
      fiveep-service/src/main/java/com/bizmatics/service/config/security/WebSecurityConfig.java
  12. 46 46
      fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/AnonymousAuthenticationEntryPoint.java
  13. 25 25
      fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/FuryAuthFailureHandler.java
  14. 25 25
      fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/FuryAuthSuccessHandler.java
  15. 24 24
      fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/MyLogoutSuccessHandler.java
  16. 25 25
      fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/RestAuthAccessDeniedHandler.java
  17. 10 6
      fiveep-service/src/main/java/com/bizmatics/service/impl/AlarmPowerServiceImpl.java
  18. 5 3
      fiveep-service/src/main/java/com/bizmatics/service/impl/DeviceServiceImpl.java
  19. 9 5
      fiveep-service/src/main/java/com/bizmatics/service/impl/HtAnalogDataServiceImpl.java
  20. 6 4
      fiveep-service/src/main/java/com/bizmatics/service/impl/RtAnalogDataServiceImpl.java
  21. 7 5
      fiveep-service/src/main/java/com/bizmatics/service/impl/SiteServiceImpl.java
  22. 17 0
      fiveep-service/src/main/java/com/bizmatics/service/impl/UserServiceImpl.java
  23. 42 0
      fiveep-service/src/main/java/com/bizmatics/service/util/SessionLocal.java
  24. 23 23
      fiveep-service/src/main/java/com/bizmatics/service/util/UserUtil.java

+ 8 - 8
fiveep-controller/src/main/java/com/bizmatics/controller/web/UserController.java

@@ -1,13 +1,13 @@
 package com.bizmatics.controller.web;
 
 
+import com.bizmatics.common.core.bean.ApiResult;
 import com.bizmatics.model.User;
 import com.bizmatics.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
 
 /**
  *
@@ -22,10 +22,10 @@ public class UserController {
     @Autowired
     private UserService userService;
 
-//    @GetMapping("/login")
-//    public ApiResult<User> login(@RequestParam String name, @RequestParam String password, HttpServletRequest request){
-//        return ApiResult.success(userService.login(name, password, request));
-//    }
+    @GetMapping("/login")
+    public ApiResult<User> login(@RequestParam String name, @RequestParam String password, HttpServletRequest request){
+        return ApiResult.success(userService.login(name, password, request));
+    }
 
     @PostMapping("register")
     public void register(@RequestBody User user){

+ 4 - 4
fiveep-model/pom.xml

@@ -38,10 +38,10 @@
             <version>0.0.1</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-security</artifactId>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.springframework.boot</groupId>-->
+<!--            <artifactId>spring-boot-starter-security</artifactId>-->
+<!--        </dependency>-->
     </dependencies>
 
 

+ 3 - 0
fiveep-service/src/main/java/com/bizmatics/service/UserService.java

@@ -3,6 +3,8 @@ package com.bizmatics.service;
 import com.bizmatics.common.mvc.base.CrudService;
 import com.bizmatics.model.User;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * <p>
  *  服务类
@@ -13,6 +15,7 @@ import com.bizmatics.model.User;
  */
 public interface UserService extends CrudService<User> {
 
+    User login(String userName,String password, HttpServletRequest request);
 
     User getByUserName(String name);
 

+ 32 - 32
fiveep-service/src/main/java/com/bizmatics/service/config/CorsConfig.java

@@ -1,32 +1,32 @@
-//package com.bizmatics.service.config;
-//
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.web.cors.CorsConfiguration;
-//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
-//import org.springframework.web.filter.CorsFilter;
-//
-///**
-// * @author yq
-// * @date 2021/7/26 16:31
-// */
-//@Configuration
-//public class CorsConfig {
-//
-//    private CorsConfiguration buildConfig() {
-//        CorsConfiguration corsConfiguration = new CorsConfiguration();
-//        corsConfiguration.addAllowedOrigin("");
-//        corsConfiguration.addAllowedHeader("");
-//        corsConfiguration.addAllowedMethod("*");
-//        corsConfiguration.setAllowCredentials(true);
-//        return corsConfiguration;
-//    }
-//
-//    @Bean
-//    public CorsFilter corsFilter() {
-//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
-//        // 配置所有请求
-//        source.registerCorsConfiguration("/**", buildConfig());
-//        return new CorsFilter(source);
-//    }
-//}
+package com.bizmatics.service.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+/**
+ * @author yq
+ * @date 2021/7/26 16:31
+ */
+@Configuration
+public class CorsConfig {
+
+    private CorsConfiguration buildConfig() {
+        CorsConfiguration corsConfiguration = new CorsConfiguration();
+        corsConfiguration.addAllowedOrigin("");
+        corsConfiguration.addAllowedHeader("");
+        corsConfiguration.addAllowedMethod("*");
+        corsConfiguration.setAllowCredentials(true);
+        return corsConfiguration;
+    }
+
+    @Bean
+    public CorsFilter corsFilter() {
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+        // 配置所有请求
+        source.registerCorsConfiguration("/**", buildConfig());
+        return new CorsFilter(source);
+    }
+}

+ 25 - 25
fiveep-service/src/main/java/com/bizmatics/service/config/MyWebConfigurer.java

@@ -1,25 +1,25 @@
-//package com.bizmatics.service.config;
-//
-//import org.springframework.boot.SpringBootConfiguration;
-//import org.springframework.web.servlet.config.annotation.CorsRegistry;
-//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-//
-//@SpringBootConfiguration
-//public class MyWebConfigurer implements WebMvcConfigurer {
-//
-//    @Override
-//    public void addCorsMappings(CorsRegistry registry) {
-//        // 设置允许跨域的路径
-//        /**
-//         * 所有请求都允许跨域,使用这种配置就不需要
-//         * 在interceptor中配置header了
-//         */
-//        registry.addMapping("/**")
-//                .allowedOrigins("*")
-//                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
-//                .allowCredentials(true)
-//                .maxAge(3600)
-//                .allowedHeaders("*");
-//    }
-//
-//}
+package com.bizmatics.service.config;
+
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@SpringBootConfiguration
+public class MyWebConfigurer implements WebMvcConfigurer {
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        // 设置允许跨域的路径
+        /**
+         * 所有请求都允许跨域,使用这种配置就不需要
+         * 在interceptor中配置header了
+         */
+        registry.addMapping("/**")
+                .allowedOrigins("*")
+                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
+                .allowCredentials(true)
+                .maxAge(3600)
+                .allowedHeaders("*");
+    }
+
+}

+ 62 - 62
fiveep-service/src/main/java/com/bizmatics/service/config/SessionFilter.java

@@ -1,62 +1,62 @@
-//package com.bizmatics.service.config;
-//
-//
-//import com.bizmatics.common.core.exception.BusinessException;
-//import com.bizmatics.model.User;
-//import com.bizmatics.service.util.SessionLocal;
-//import lombok.extern.slf4j.Slf4j;
-//import org.elasticsearch.rest.RestRequest;
-//import org.springframework.stereotype.Component;
-//
-//import javax.servlet.*;
-//import javax.servlet.annotation.WebFilter;
-//import javax.servlet.http.HttpServletRequest;
-//import javax.servlet.http.HttpServletResponse;
-//import javax.servlet.http.HttpSession;
-//import java.io.IOException;
-//import java.util.Collections;
-//import java.util.HashSet;
-//import java.util.Set;
-//
-///**
-// * @author yq
-// * @date 2021/7/8 10:35
-// */
-//@Component
-//@Slf4j
-//@WebFilter(urlPatterns = "/*", filterName = "reqResFilter")
-//public class SessionFilter implements Filter {
-//
-//    private static final Set<String> ALLOWED_PATHS = Collections.unmodifiableSet(new HashSet<>(
-//            Collections.singletonList("/user/login")));
-//
-//
-//    @Override
-//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
-//        HttpServletResponse  response = (HttpServletResponse)servletResponse;
-//        HttpServletRequest request = (HttpServletRequest)servletRequest;
-//        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
-//        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
-//        response.setHeader("Access-Control-Max-Age", "3600");
-//        response.setHeader("Access-Control-Allow-Credentials", "true");
-//        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization,token, content-type");
-//        if(request.getMethod().toUpperCase().equals(RestRequest.Method.OPTIONS.name())){
-//            return;
-//        }
-//        String path = request.getRequestURI().substring(request.getContextPath().length()).replaceAll("[/]+$", "");
-//        boolean allowedPath = ALLOWED_PATHS.contains(path);
-//        if (!allowedPath){
-//            HttpSession session = request.getSession();
-//            if(session.getAttribute( "sessionuser") != null) {
-//                if(SessionLocal.getUser() == null) {
-//                    log.info("【当前线程"+Thread.currentThread().getName()+"中用户信息为空,从session中set到ThreadLocal.】");
-//                    SessionLocal.setUser( (User)session.getAttribute( "sessionuser") );
-//                }
-//            } else {
-//                throw new BusinessException("用户未登录请先登录");
-//            }
-//        }
-//        chain.doFilter(servletRequest,servletResponse);
-//    }
-//
-//}
+package com.bizmatics.service.config;
+
+
+import com.bizmatics.common.core.exception.BusinessException;
+import com.bizmatics.model.User;
+import com.bizmatics.service.util.SessionLocal;
+import lombok.extern.slf4j.Slf4j;
+import org.elasticsearch.rest.RestRequest;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.annotation.WebFilter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author yq
+ * @date 2021/7/8 10:35
+ */
+@Component
+@Slf4j
+@WebFilter(urlPatterns = "/*", filterName = "reqResFilter")
+public class SessionFilter implements Filter {
+
+    private static final Set<String> ALLOWED_PATHS = Collections.unmodifiableSet(new HashSet<>(
+            Collections.singletonList("/user/login")));
+
+
+    @Override
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
+        HttpServletResponse  response = (HttpServletResponse)servletResponse;
+        HttpServletRequest request = (HttpServletRequest)servletRequest;
+        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
+        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
+        response.setHeader("Access-Control-Max-Age", "3600");
+        response.setHeader("Access-Control-Allow-Credentials", "true");
+        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization,token, content-type");
+        if(request.getMethod().toUpperCase().equals(RestRequest.Method.OPTIONS.name())){
+            return;
+        }
+        String path = request.getRequestURI().substring(request.getContextPath().length()).replaceAll("[/]+$", "");
+        boolean allowedPath = ALLOWED_PATHS.contains(path);
+        if (!allowedPath){
+            HttpSession session = request.getSession();
+            if(session.getAttribute( "sessionuser") != null) {
+                if(SessionLocal.getUser() == null) {
+                    log.info("【当前线程"+Thread.currentThread().getName()+"中用户信息为空,从session中set到ThreadLocal.】");
+                    SessionLocal.setUser( (User)session.getAttribute( "sessionuser") );
+                }
+            } else {
+                throw new BusinessException("用户未登录请先登录");
+            }
+        }
+        chain.doFilter(servletRequest,servletResponse);
+    }
+
+}

+ 49 - 49
fiveep-service/src/main/java/com/bizmatics/service/config/security/CustomPermissionEvaluator.java

@@ -1,49 +1,49 @@
-package com.bizmatics.service.config.security;
-
-import org.springframework.security.access.PermissionEvaluator;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.stereotype.Component;
-
-import java.io.Serializable;
-import java.util.Collection;
-
-/**
- * 我们需要自定义对hasPermission()方法的处理,
- * 就需要自定义PermissionEvaluator,创建类CustomPermissionEvaluator,实现PermissionEvaluator接口。
- * @author zhoukebo
- * @date 2018/9/5
- */
-@Component
-public class CustomPermissionEvaluator implements PermissionEvaluator {
-    /**
-     * 自定义验证方法
-     * @param authentication        登录的时候存储的用户信息
-     * @param targetDomainObject    @PreAuthorize("hasPermission('/hello/**','r')") 中hasPermission的第一个参数
-     * @param permission            @PreAuthorize("hasPermission('/hello/**','r')") 中hasPermission的第二个参数
-     * @return
-     */
-    @Override
-    public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
-        // 获得loadUserByUsername()方法的结果
-        UserDetail userDetail = (UserDetail)authentication.getPrincipal();
-        // 获得loadUserByUsername()中注入的权限
-        Collection<? extends GrantedAuthority> authorities = userDetail.getAuthorities();
-        // 遍历用户权限进行判定
-        for(GrantedAuthority authority : authorities) {
-            SimpleGrantedAuthority urlGrantedAuthority = (SimpleGrantedAuthority) authority;
-            String permissionUrl = urlGrantedAuthority.getAuthority();
-            // 如果访问的Url和权限用户符合的话,返回true
-            if(targetDomainObject.equals(permissionUrl)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
-        return false;
-    }
-}
+//package com.bizmatics.service.config.security;
+//
+//import org.springframework.security.access.PermissionEvaluator;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.authority.SimpleGrantedAuthority;
+//import org.springframework.stereotype.Component;
+//
+//import java.io.Serializable;
+//import java.util.Collection;
+//
+///**
+// * 我们需要自定义对hasPermission()方法的处理,
+// * 就需要自定义PermissionEvaluator,创建类CustomPermissionEvaluator,实现PermissionEvaluator接口。
+// * @author zhoukebo
+// * @date 2018/9/5
+// */
+//@Component
+//public class CustomPermissionEvaluator implements PermissionEvaluator {
+//    /**
+//     * 自定义验证方法
+//     * @param authentication        登录的时候存储的用户信息
+//     * @param targetDomainObject    @PreAuthorize("hasPermission('/hello/**','r')") 中hasPermission的第一个参数
+//     * @param permission            @PreAuthorize("hasPermission('/hello/**','r')") 中hasPermission的第二个参数
+//     * @return
+//     */
+//    @Override
+//    public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
+//        // 获得loadUserByUsername()方法的结果
+//        UserDetail userDetail = (UserDetail)authentication.getPrincipal();
+//        // 获得loadUserByUsername()中注入的权限
+//        Collection<? extends GrantedAuthority> authorities = userDetail.getAuthorities();
+//        // 遍历用户权限进行判定
+//        for(GrantedAuthority authority : authorities) {
+//            SimpleGrantedAuthority urlGrantedAuthority = (SimpleGrantedAuthority) authority;
+//            String permissionUrl = urlGrantedAuthority.getAuthority();
+//            // 如果访问的Url和权限用户符合的话,返回true
+//            if(targetDomainObject.equals(permissionUrl)) {
+//                return true;
+//            }
+//        }
+//        return false;
+//    }
+//
+//    @Override
+//    public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
+//        return false;
+//    }
+//}

+ 50 - 50
fiveep-service/src/main/java/com/bizmatics/service/config/security/CustomerDetailServiceImpl.java

@@ -1,50 +1,50 @@
-package com.bizmatics.service.config.security;
-
-import com.bizmatics.common.core.exception.BusinessException;
-import com.bizmatics.model.SysResource;
-import com.bizmatics.model.SysRole;
-import com.bizmatics.model.User;
-import com.bizmatics.service.UserService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UserDetailsService;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 需要自定义UserDetailsService实现spring security的UserDetailsService接口
- * @author zhoukebo
- * @date 2018/9/4
- */
-@Service
-public class CustomerDetailServiceImpl implements UserDetailsService {
-
-    @Autowired
-    public UserService userService;
-
-    @Override
-    public UserDetails loadUserByUsername(String username) {
-        User user = userService.getByUserName(username);
-        if (user == null) {
-            throw new BusinessException("用户名不存在");
-        }
-        //先通过用户查询角色信息
-        List<SysRole> roles = new ArrayList<>();
-        UserDetail userDetail = new UserDetail(user.getId(),user.getUserName(), user.getUserPassword(), roles);
-        //再获取角色对应的权限信息
-        List<SysResource> resources = new ArrayList<>();
-        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
-        for (SysResource resource : resources) {
-            if (resource != null && resource.getResourceName()!=null) {
-                GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(resource.getResourceName());
-                grantedAuthorities.add(grantedAuthority);
-            }
-        }
-        userDetail.setGrantedAuthority(grantedAuthorities);
-        return userDetail;
-    }
-}
+//package com.bizmatics.service.config.security;
+//
+//import com.bizmatics.common.core.exception.BusinessException;
+//import com.bizmatics.model.SysResource;
+//import com.bizmatics.model.SysRole;
+//import com.bizmatics.model.User;
+//import com.bizmatics.service.UserService;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.authority.SimpleGrantedAuthority;
+//import org.springframework.security.core.userdetails.UserDetails;
+//import org.springframework.security.core.userdetails.UserDetailsService;
+//import org.springframework.stereotype.Service;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//
+///**
+// * 需要自定义UserDetailsService实现spring security的UserDetailsService接口
+// * @author zhoukebo
+// * @date 2018/9/4
+// */
+//@Service
+//public class CustomerDetailServiceImpl implements UserDetailsService {
+//
+//    @Autowired
+//    public UserService userService;
+//
+//    @Override
+//    public UserDetails loadUserByUsername(String username) {
+//        User user = userService.getByUserName(username);
+//        if (user == null) {
+//            throw new BusinessException("用户名不存在");
+//        }
+//        //先通过用户查询角色信息
+//        List<SysRole> roles = new ArrayList<>();
+//        UserDetail userDetail = new UserDetail(user.getId(),user.getUserName(), user.getUserPassword(), roles);
+//        //再获取角色对应的权限信息
+//        List<SysResource> resources = new ArrayList<>();
+//        List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
+//        for (SysResource resource : resources) {
+//            if (resource != null && resource.getResourceName()!=null) {
+//                GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(resource.getResourceName());
+//                grantedAuthorities.add(grantedAuthority);
+//            }
+//        }
+//        userDetail.setGrantedAuthority(grantedAuthorities);
+//        return userDetail;
+//    }
+//}

+ 55 - 55
fiveep-service/src/main/java/com/bizmatics/service/config/security/MyAuthenticationProvider.java

@@ -1,55 +1,55 @@
-package com.bizmatics.service.config.security;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AuthenticationProvider;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.stereotype.Component;
-
-import java.util.Collection;
-
-/**
- * 实现自己的AuthenticationProvider类,用来自定义用户校验机制
- * @author zhoukebo
- * @date 2018/9/5
- */
-@Component
-public class MyAuthenticationProvider implements AuthenticationProvider {
-
-    @Autowired
-    private CustomerDetailServiceImpl customerDetailServiceImpl;
-
-    @Override
-    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
-        // 获取表单输入中返回的用户名;
-        String userName = (String) authentication.getPrincipal();
-        // 获取表单中输入的密码;
-        String password = (String) authentication.getCredentials();
-        // 这里调用我们的自己写的获取用户的方法;
-        UserDetails userInfo = customerDetailServiceImpl.loadUserByUsername(userName);
-        if (userInfo == null) {
-            throw new BadCredentialsException("用户名不存在");
-        }
-
-        // 这里我们还要判断密码是否正确,这里我们的密码使用BCryptPasswordEncoder进行加密的
-        if (!new BCryptPasswordEncoder().matches(password, userInfo.getPassword())) {
-            throw new BadCredentialsException("密码不正确");
-        }
-        // 这里还可以加一些其他信息的判断,比如用户账号已停用等判断。
-
-        Collection<? extends GrantedAuthority> authorities = userInfo.getAuthorities();
-        // 构建返回的用户登录成功的token
-        return new UsernamePasswordAuthenticationToken(userInfo, password, authorities);
-    }
-
-    @Override
-    public boolean supports(Class<?> authentication) {
-//      这里直接改成retrun true;表示是支持这个执行
-        return true;
-    }
-}
+//package com.bizmatics.service.config.security;
+//
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.authentication.AuthenticationProvider;
+//import org.springframework.security.authentication.BadCredentialsException;
+//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.core.AuthenticationException;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.userdetails.UserDetails;
+//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+//import org.springframework.stereotype.Component;
+//
+//import java.util.Collection;
+//
+///**
+// * 实现自己的AuthenticationProvider类,用来自定义用户校验机制
+// * @author zhoukebo
+// * @date 2018/9/5
+// */
+//@Component
+//public class MyAuthenticationProvider implements AuthenticationProvider {
+//
+//    @Autowired
+//    private CustomerDetailServiceImpl customerDetailServiceImpl;
+//
+//    @Override
+//    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+//        // 获取表单输入中返回的用户名;
+//        String userName = (String) authentication.getPrincipal();
+//        // 获取表单中输入的密码;
+//        String password = (String) authentication.getCredentials();
+//        // 这里调用我们的自己写的获取用户的方法;
+//        UserDetails userInfo = customerDetailServiceImpl.loadUserByUsername(userName);
+//        if (userInfo == null) {
+//            throw new BadCredentialsException("用户名不存在");
+//        }
+//
+//        // 这里我们还要判断密码是否正确,这里我们的密码使用BCryptPasswordEncoder进行加密的
+//        if (!new BCryptPasswordEncoder().matches(password, userInfo.getPassword())) {
+//            throw new BadCredentialsException("密码不正确");
+//        }
+//        // 这里还可以加一些其他信息的判断,比如用户账号已停用等判断。
+//
+//        Collection<? extends GrantedAuthority> authorities = userInfo.getAuthorities();
+//        // 构建返回的用户登录成功的token
+//        return new UsernamePasswordAuthenticationToken(userInfo, password, authorities);
+//    }
+//
+//    @Override
+//    public boolean supports(Class<?> authentication) {
+////      这里直接改成retrun true;表示是支持这个执行
+//        return true;
+//    }
+//}

+ 68 - 68
fiveep-service/src/main/java/com/bizmatics/service/config/security/UserDetail.java

@@ -1,68 +1,68 @@
-package com.bizmatics.service.config.security;
-
-import com.bizmatics.model.SysRole;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import lombok.Data;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author yq
- * @date 2021/8/3 11:19
- */
-@Data
-public class UserDetail implements UserDetails {
-
-    private Integer id;
-    private String username;
-    private String password;
-    private List<SysRole> roles;
-    private  Collection<? extends GrantedAuthority> grantedAuthority;
-    public UserDetail(
-            Integer id,
-            String username,
-            String password,
-            List<SysRole> roles) {
-        this.id = id;
-        this.username = username;
-        this.password = password;
-        this.roles = roles;
-    }
-    /***
-     * 正常情况下,角色和权限是两回事,
-     * 所以我们还需要重写getAuthorities方法,将用户的角色和权限关联起来
-     */
-    @Override
-    public Collection<? extends GrantedAuthority> getAuthorities() {
-        return this.grantedAuthority;
-    }
-
-    //isAccountNonExpired方法返回boolean类型,用于判断账户是否未过期,未过期返回true反之返回false;
-    @JsonIgnore
-    @Override
-    public boolean isAccountNonExpired() {
-        return true;
-    }
-    //isAccountNonLocked方法用于判断账户是否未锁定;
-    @JsonIgnore
-    @Override
-    public boolean isAccountNonLocked() {
-        return true;
-    }
-    //isCredentialsNonExpired用于判断用户凭证是否没过期,即密码是否未过期;
-    @JsonIgnore
-    @Override
-    public boolean isCredentialsNonExpired() {
-        return true;
-    }
-    //isEnabled方法用于判断用户是否可用。
-    @JsonIgnore
-    @Override
-    public boolean isEnabled() {
-        return true;
-    }
-
-}
+//package com.bizmatics.service.config.security;
+//
+//import com.bizmatics.model.SysRole;
+//import com.fasterxml.jackson.annotation.JsonIgnore;
+//import lombok.Data;
+//import org.springframework.security.core.GrantedAuthority;
+//import org.springframework.security.core.userdetails.UserDetails;
+//
+//import java.util.Collection;
+//import java.util.List;
+//
+///**
+// * @author yq
+// * @date 2021/8/3 11:19
+// */
+//@Data
+//public class UserDetail implements UserDetails {
+//
+//    private Integer id;
+//    private String username;
+//    private String password;
+//    private List<SysRole> roles;
+//    private  Collection<? extends GrantedAuthority> grantedAuthority;
+//    public UserDetail(
+//            Integer id,
+//            String username,
+//            String password,
+//            List<SysRole> roles) {
+//        this.id = id;
+//        this.username = username;
+//        this.password = password;
+//        this.roles = roles;
+//    }
+//    /***
+//     * 正常情况下,角色和权限是两回事,
+//     * 所以我们还需要重写getAuthorities方法,将用户的角色和权限关联起来
+//     */
+//    @Override
+//    public Collection<? extends GrantedAuthority> getAuthorities() {
+//        return this.grantedAuthority;
+//    }
+//
+//    //isAccountNonExpired方法返回boolean类型,用于判断账户是否未过期,未过期返回true反之返回false;
+//    @JsonIgnore
+//    @Override
+//    public boolean isAccountNonExpired() {
+//        return true;
+//    }
+//    //isAccountNonLocked方法用于判断账户是否未锁定;
+//    @JsonIgnore
+//    @Override
+//    public boolean isAccountNonLocked() {
+//        return true;
+//    }
+//    //isCredentialsNonExpired用于判断用户凭证是否没过期,即密码是否未过期;
+//    @JsonIgnore
+//    @Override
+//    public boolean isCredentialsNonExpired() {
+//        return true;
+//    }
+//    //isEnabled方法用于判断用户是否可用。
+//    @JsonIgnore
+//    @Override
+//    public boolean isEnabled() {
+//        return true;
+//    }
+//
+//}

+ 94 - 94
fiveep-service/src/main/java/com/bizmatics/service/config/security/WebSecurityConfig.java

@@ -1,94 +1,94 @@
-package com.bizmatics.service.config.security;
-
-import com.bizmatics.service.config.security.handler.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationProvider;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
-import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
-
-/**
- * spring Security配置安全控制中心
- *
- * @author zhoukb
- */
-@Configuration
-@EnableWebSecurity
-@EnableGlobalMethodSecurity(prePostEnabled = true)
-public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-    /**
-     * 依赖注入自定义的登录成功处理器
-     */
-    @Autowired
-    private FuryAuthSuccessHandler furyAuthSuccessHandler;
-    /**
-     * 依赖注入自定义的登录失败处理器
-     */
-    @Autowired
-    private FuryAuthFailureHandler furyAuthFailureHandler;
-    /**
-     * 依赖注入自定义的注销成功的处理器
-     */
-    @Autowired
-    private MyLogoutSuccessHandler myLogoutSuccessHandler;
-    @Autowired
-    private AnonymousAuthenticationEntryPoint anonymousAuthenticationEntryPoint;
-
-    /**
-     * 注册没有权限的处理器
-     */
-    @Autowired
-    private RestAuthAccessDeniedHandler restAuthAccessDeniedHandler;
-
-    /***注入自定义的CustomPermissionEvaluator*/
-    @Bean
-    public DefaultWebSecurityExpressionHandler webSecurityExpressionHandler() {
-        DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
-        handler.setPermissionEvaluator(new CustomPermissionEvaluator());
-        return handler;
-    }
-
-    /***注入我们自己的登录逻辑验证器AuthenticationProvider*/
-    @Autowired
-    private AuthenticationProvider authenticationProvider;
-
-    @Override
-    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
-        //这里可启用我们自己的登陆验证逻辑
-        auth.authenticationProvider(authenticationProvider);
-    }
-
-    /**
-     * 配置spring security的控制逻辑
-     */
-    @Override
-    protected void configure(HttpSecurity http) throws Exception {
-        http.cors().and().csrf().disable();
-        http.authorizeRequests()
-                // 放行接口
-                .antMatchers("/login","/user/register").permitAll()
-                // 除上面外的所有请求全部需要鉴权认证
-                .anyRequest().authenticated()
-                .and()
-                .formLogin()
-                //loginProcessingUrl用于指定前后端分离的时候调用后台登录接口的名称
-                .loginProcessingUrl("/login")
-                // 异常处理(权限拒绝、登录失效等)
-                .and().exceptionHandling()
-                .authenticationEntryPoint(anonymousAuthenticationEntryPoint)//匿名用户访问无权限资源时的异常处理
-                .accessDeniedHandler(restAuthAccessDeniedHandler)//登录用户没有权限访问资源
-                // 登入
-                .and().formLogin().permitAll()
-                .successHandler(furyAuthSuccessHandler)
-                .failureHandler(furyAuthFailureHandler)
-                // 登出
-                .and().logout().permitAll()//允许所有用户
-                .logoutSuccessHandler(myLogoutSuccessHandler);
-
-    }
-}
+//package com.bizmatics.service.config.security;
+//
+//import com.bizmatics.service.config.security.handler.*;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.security.authentication.AuthenticationProvider;
+//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+//import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
+//
+///**
+// * spring Security配置安全控制中心
+// *
+// * @author zhoukb
+// */
+//@Configuration
+//@EnableWebSecurity
+//@EnableGlobalMethodSecurity(prePostEnabled = true)
+//public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+//    /**
+//     * 依赖注入自定义的登录成功处理器
+//     */
+//    @Autowired
+//    private FuryAuthSuccessHandler furyAuthSuccessHandler;
+//    /**
+//     * 依赖注入自定义的登录失败处理器
+//     */
+//    @Autowired
+//    private FuryAuthFailureHandler furyAuthFailureHandler;
+//    /**
+//     * 依赖注入自定义的注销成功的处理器
+//     */
+//    @Autowired
+//    private MyLogoutSuccessHandler myLogoutSuccessHandler;
+//    @Autowired
+//    private AnonymousAuthenticationEntryPoint anonymousAuthenticationEntryPoint;
+//
+//    /**
+//     * 注册没有权限的处理器
+//     */
+//    @Autowired
+//    private RestAuthAccessDeniedHandler restAuthAccessDeniedHandler;
+//
+//    /***注入自定义的CustomPermissionEvaluator*/
+//    @Bean
+//    public DefaultWebSecurityExpressionHandler webSecurityExpressionHandler() {
+//        DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
+//        handler.setPermissionEvaluator(new CustomPermissionEvaluator());
+//        return handler;
+//    }
+//
+//    /***注入我们自己的登录逻辑验证器AuthenticationProvider*/
+//    @Autowired
+//    private AuthenticationProvider authenticationProvider;
+//
+//    @Override
+//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+//        //这里可启用我们自己的登陆验证逻辑
+//        auth.authenticationProvider(authenticationProvider);
+//    }
+//
+//    /**
+//     * 配置spring security的控制逻辑
+//     */
+//    @Override
+//    protected void configure(HttpSecurity http) throws Exception {
+//        http.cors().and().csrf().disable();
+//        http.authorizeRequests()
+//                // 放行接口
+//                .antMatchers("/login","/user/register").permitAll()
+//                // 除上面外的所有请求全部需要鉴权认证
+//                .anyRequest().authenticated()
+//                .and()
+//                .formLogin()
+//                //loginProcessingUrl用于指定前后端分离的时候调用后台登录接口的名称
+//                .loginProcessingUrl("/login")
+//                // 异常处理(权限拒绝、登录失效等)
+//                .and().exceptionHandling()
+//                .authenticationEntryPoint(anonymousAuthenticationEntryPoint)//匿名用户访问无权限资源时的异常处理
+//                .accessDeniedHandler(restAuthAccessDeniedHandler)//登录用户没有权限访问资源
+//                // 登入
+//                .and().formLogin().permitAll()
+//                .successHandler(furyAuthSuccessHandler)
+//                .failureHandler(furyAuthFailureHandler)
+//                // 登出
+//                .and().logout().permitAll()//允许所有用户
+//                .logoutSuccessHandler(myLogoutSuccessHandler);
+//
+//    }
+//}

+ 46 - 46
fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/AnonymousAuthenticationEntryPoint.java

@@ -1,46 +1,46 @@
-package com.bizmatics.service.config.security.handler;
-
-import com.bizmatics.common.core.bean.ApiResult;
-import com.bizmatics.common.spring.util.JsonUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.AuthenticationEntryPoint;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * @author yq
- * @date 2021/8/3 13:59
- */
-@Slf4j
-@Component
-public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint {
-
-
-    @Override
-    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
-        log.warn("用户需要登录,访问[{}]失败,AuthenticationException={}", request.getRequestURI(), e);
-        ServletUtils.render(request, response, ApiResult.error("500","用户未登录"));
-    }
-}
-
-class ServletUtils {
-
-    /**
-     * 渲染到客户端
-     *
-     * @param object   待渲染的实体类,会自动转为json
-     */
-    public static void render(HttpServletRequest request, HttpServletResponse response, Object object) throws IOException {
-        // 允许跨域
-        response.setHeader("Access-Control-Allow-Origin", "*");
-        // 允许自定义请求头token(允许head跨域)
-        response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified");
-        response.setHeader("Content-type", "application/json;charset=UTF-8");
-        response.getWriter().print(JsonUtils.toJson(object));
-    }
-}
+//package com.bizmatics.service.config.security.handler;
+//
+//import com.bizmatics.common.core.bean.ApiResult;
+//import com.bizmatics.common.spring.util.JsonUtils;
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.security.core.AuthenticationException;
+//import org.springframework.security.web.AuthenticationEntryPoint;
+//import org.springframework.stereotype.Component;
+//
+//import javax.servlet.ServletException;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.IOException;
+//
+///**
+// * @author yq
+// * @date 2021/8/3 13:59
+// */
+//@Slf4j
+//@Component
+//public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoint {
+//
+//
+//    @Override
+//    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
+//        log.warn("用户需要登录,访问[{}]失败,AuthenticationException={}", request.getRequestURI(), e);
+//        ServletUtils.render(request, response, ApiResult.error("500","用户未登录"));
+//    }
+//}
+//
+//class ServletUtils {
+//
+//    /**
+//     * 渲染到客户端
+//     *
+//     * @param object   待渲染的实体类,会自动转为json
+//     */
+//    public static void render(HttpServletRequest request, HttpServletResponse response, Object object) throws IOException {
+//        // 允许跨域
+//        response.setHeader("Access-Control-Allow-Origin", "*");
+//        // 允许自定义请求头token(允许head跨域)
+//        response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified");
+//        response.setHeader("Content-type", "application/json;charset=UTF-8");
+//        response.getWriter().print(JsonUtils.toJson(object));
+//    }
+//}

+ 25 - 25
fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/FuryAuthFailureHandler.java

@@ -1,25 +1,25 @@
-package com.bizmatics.service.config.security.handler;
-
-import com.bizmatics.common.core.bean.ApiResult;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.authentication.AuthenticationFailureHandler;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * 处理登录验证失败的类
- * @author zhoukebo
- * @date 2018/9/4
- */
-@Component
-public class FuryAuthFailureHandler implements AuthenticationFailureHandler {
-
-    @Override
-    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
-        ServletUtils.render(request,response,ApiResult.error("500",exception.getMessage()));
-    }
-}
+//package com.bizmatics.service.config.security.handler;
+//
+//import com.bizmatics.common.core.bean.ApiResult;
+//import org.springframework.security.core.AuthenticationException;
+//import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+//import org.springframework.stereotype.Component;
+//
+//import javax.servlet.ServletException;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.IOException;
+//
+///**
+// * 处理登录验证失败的类
+// * @author zhoukebo
+// * @date 2018/9/4
+// */
+//@Component
+//public class FuryAuthFailureHandler implements AuthenticationFailureHandler {
+//
+//    @Override
+//    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
+//        ServletUtils.render(request,response,ApiResult.error("500",exception.getMessage()));
+//    }
+//}

+ 25 - 25
fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/FuryAuthSuccessHandler.java

@@ -1,25 +1,25 @@
-package com.bizmatics.service.config.security.handler;
-
-import com.bizmatics.common.core.bean.ApiResult;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * 处理登录验证成功的类
- * @author zhoukebo
- * @date 2018/9/4
- */
-@Component
-public class FuryAuthSuccessHandler implements AuthenticationSuccessHandler {
-
-    @Override
-    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
-        ServletUtils.render(request, response, ApiResult.success());
-    }
-
-}
+//package com.bizmatics.service.config.security.handler;
+//
+//import com.bizmatics.common.core.bean.ApiResult;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+//import org.springframework.stereotype.Component;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.IOException;
+//
+///**
+// * 处理登录验证成功的类
+// * @author zhoukebo
+// * @date 2018/9/4
+// */
+//@Component
+//public class FuryAuthSuccessHandler implements AuthenticationSuccessHandler {
+//
+//    @Override
+//    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
+//        ServletUtils.render(request, response, ApiResult.success());
+//    }
+//
+//}

+ 24 - 24
fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/MyLogoutSuccessHandler.java

@@ -1,24 +1,24 @@
-package com.bizmatics.service.config.security.handler;
-
-import com.bizmatics.common.core.bean.ApiResult;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * 处理注销成功
- * @author zhoukebo
- * @date 2018/9/4
- */
-@Component
-public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
-
-    @Override
-    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
-        ServletUtils.render(request, response, ApiResult.success());
-    }
-}
+//package com.bizmatics.service.config.security.handler;
+//
+//import com.bizmatics.common.core.bean.ApiResult;
+//import org.springframework.security.core.Authentication;
+//import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
+//import org.springframework.stereotype.Component;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.IOException;
+//
+///**
+// * 处理注销成功
+// * @author zhoukebo
+// * @date 2018/9/4
+// */
+//@Component
+//public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
+//
+//    @Override
+//    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
+//        ServletUtils.render(request, response, ApiResult.success());
+//    }
+//}

+ 25 - 25
fiveep-service/src/main/java/com/bizmatics/service/config/security/handler/RestAuthAccessDeniedHandler.java

@@ -1,25 +1,25 @@
-package com.bizmatics.service.config.security.handler;
-
-import com.bizmatics.common.core.bean.ApiResult;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.security.web.access.AccessDeniedHandler;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * 处理没有权限的类
- * @author zhoukebo
- * @date 2018/9/5
- */
-@Component
-public class RestAuthAccessDeniedHandler implements AccessDeniedHandler {
-
-    @Override
-    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
-        ServletUtils.render(request,response,ApiResult.error("500", e.getMessage()));
-    }
-}
+//package com.bizmatics.service.config.security.handler;
+//
+//import com.bizmatics.common.core.bean.ApiResult;
+//import org.springframework.security.access.AccessDeniedException;
+//import org.springframework.security.web.access.AccessDeniedHandler;
+//import org.springframework.stereotype.Component;
+//
+//import javax.servlet.ServletException;
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.IOException;
+//
+///**
+// * 处理没有权限的类
+// * @author zhoukebo
+// * @date 2018/9/5
+// */
+//@Component
+//public class RestAuthAccessDeniedHandler implements AccessDeniedHandler {
+//
+//    @Override
+//    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
+//        ServletUtils.render(request,response,ApiResult.error("500", e.getMessage()));
+//    }
+//}

+ 10 - 6
fiveep-service/src/main/java/com/bizmatics/service/impl/AlarmPowerServiceImpl.java

@@ -13,7 +13,7 @@ import com.bizmatics.common.spring.util.GlobalUtils;
 import com.bizmatics.model.AlarmPower;
 import com.bizmatics.persistence.mapper.AlarmPowerMapper;
 import com.bizmatics.service.AlarmPowerService;
-import com.bizmatics.service.util.UserUtil;
+import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.AlarmPowerExportVO;
 import com.bizmatics.service.vo.ApCountVO;
 import com.bizmatics.service.vo.CommonIcoVO;
@@ -43,7 +43,8 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
 
     @Override
     public ApCountVO selectCount(Integer siteId,Date startTime,Date endTime) {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         ApCountVO apCountVo = new ApCountVO();
         apCountVo.setCount(baseMapper.selectCount(userId, siteId, null, startTime, endTime, null, null));
         apCountVo.setUnCount(baseMapper.selectCount(userId, siteId, 0, startTime, endTime, null, null));
@@ -56,7 +57,8 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
         List<Object> rushList = new ArrayList<>();
         List<Object> noDisposeList = new ArrayList<>();
         List<Object> dateList = new ArrayList<>();
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         List<AlarmPower> alarmPowers = baseMapper.list(userId, siteId, null, startTime, endTime, null, null);
         for (int i = 0; i < DateUtils.getDistanceDayOfTwoDate(startTime,endTime); i++) {
             Date setDays = DateUtils.addDays(startTime, i);
@@ -77,7 +79,7 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
     @Override
     public CommonPage<AlarmPower> page(Date startTime, Date endTime, Integer status, Integer siteId,Integer current,Integer size) {
         Page<AlarmPower> page = new Page<>(current, size);
-        page = baseMapper.page(page,UserUtil.getUserId(),siteId,status,startTime,endTime);
+        page = baseMapper.page(page,SessionLocal.getUserId(),siteId,status,startTime,endTime);
         return this.ToCommonPage(page);
     }
 
@@ -126,7 +128,8 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
 
     @Override
     public String export(Date startTime, Date endTime, Integer status, Integer siteId){
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         Workbook workbook = null;
         File file = null;
         try {
@@ -162,7 +165,8 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
 
     @Override
     public List<CommonIcoVO> runStatus(Date startTime, Date endTime, Integer siteId) {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         List<CommonIcoVO> list = new ArrayList<>();
         List<Object> offCounts = new ArrayList<>();
         List<Object> offDateS = new ArrayList<>();

+ 5 - 3
fiveep-service/src/main/java/com/bizmatics/service/impl/DeviceServiceImpl.java

@@ -6,7 +6,7 @@ import com.bizmatics.persistence.mapper.DeviceMapper;
 import com.bizmatics.service.DeviceService;
 import com.bizmatics.service.enums.DeviceStatusCode;
 import com.bizmatics.service.enums.DeviceType;
-import com.bizmatics.service.util.UserUtil;
+import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.DeviceCountVO;
 import org.springframework.stereotype.Service;
 
@@ -28,7 +28,8 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
 
     @Override
     public DeviceCountVO selectDeviceCount(Date startTime, Date endTime) {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         DeviceCountVO deviceCountVo = new DeviceCountVO();
         deviceCountVo.setNormalCount(baseMapper
                 .selectCount(userId,null,DeviceStatusCode.NORMAL.getValue(),startTime,endTime,null));
@@ -46,7 +47,8 @@ public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device>
     @Override
     public DeviceCountVO selectDeviceCountByType(Integer site) {
         DeviceCountVO deviceCountVo = new DeviceCountVO();
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         int oneEightThreeEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_EIGHT_THREE_EP.getValue());
         int oneSevenOneEp = baseMapper.selectCount(userId, site,null , null, null, DeviceType.ONE_SEVEN_ONE_EP.getValue());
         int oneSevenThreeEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_SEVEN_THREE_EP.getValue());

+ 9 - 5
fiveep-service/src/main/java/com/bizmatics/service/impl/HtAnalogDataServiceImpl.java

@@ -9,7 +9,7 @@ import com.bizmatics.persistence.mapper.HtAnalogDataMapper;
 import com.bizmatics.service.HadSiteStaticService;
 import com.bizmatics.service.HtAnalogDataService;
 import com.bizmatics.service.util.Arith;
-import com.bizmatics.service.util.UserUtil;
+import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.CommonIcoVO;
 import com.bizmatics.service.vo.HadCountVO;
 import com.bizmatics.service.vo.TimeShareVO;
@@ -36,7 +36,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
     @Override
     public HadCountVO selectCount() {
         HadCountVO hadCountVO = new HadCountVO();
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         Date date = new Date();
         hadCountVO.setDayCount(hadSiteStaticService.getCount(userId,DateUtils.getDayStartTime(date),date,null));
         hadCountVO.setMonthCount(hadSiteStaticService.getCount(userId, DateUtils.getFirstDayOfMonth(date), date,null));
@@ -46,7 +47,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
 
     @Override
     public List<CommonIcoVO> selectTrendByDate(Integer siteId) {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         Date date = new Date();
         Date sTime = DateUtils.getDayStartTime(date);
         Date eTime = DateUtils.getDayEndTime(date);
@@ -114,7 +116,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
     @Override
     public List<CommonIcoVO> selectTrendByMonth() {
         Date date = new Date();
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         List<CommonIcoVO> list = new ArrayList<>();
         list.add(selectTreedMonthOne(DateUtils.getLastDayOfMonth(DateUtils.addMonths(date,-1)),userId,"上月趋势图"));
         list.add(selectTreedMonthOne(DateUtils.getLastDayOfMonth(date),userId,"当月趋势图"));
@@ -136,7 +139,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
 
     @Override
     public HadCountVO getCountBySite(Integer siteId) {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         Date date = new Date();
         //当日开始时间
         Date firstDayOfDate = DateUtils.getDayStartTime(date);

+ 6 - 4
fiveep-service/src/main/java/com/bizmatics/service/impl/RtAnalogDataServiceImpl.java

@@ -16,7 +16,7 @@ import com.bizmatics.persistence.mapper.DeviceMapper;
 import com.bizmatics.persistence.mapper.RtAnalogDataMapper;
 import com.bizmatics.service.RtAnalogDataService;
 import com.bizmatics.service.util.Arith;
-import com.bizmatics.service.util.UserUtil;
+import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.RadCountVO;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -48,7 +48,8 @@ public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMap
 
     @Override
     public RadCountVO selectCount() {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         AtomicReference<Integer> heavyLoad = new AtomicReference<>(0);
         AtomicReference<Integer> easyLoad = new AtomicReference<>(0);
         AtomicReference<Integer> norMalLoad = new AtomicReference<>(0);
@@ -106,7 +107,7 @@ public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMap
 
     @Override
     public Double getEpLoad(Integer siteId) {
-        return baseMapper.selectTotalLoad(UserUtil.getUserId(), siteId);
+        return baseMapper.selectTotalLoad(SessionLocal.getUserId(), siteId);
     }
 
     /**
@@ -598,7 +599,8 @@ public class RtAnalogDataServiceImpl extends AbstractCrudService<RtAnalogDataMap
 
     @Override
     public String DataReportExport(Integer siteId,Date startTime, Date endTime,String queryType){
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         Workbook workbook = null;
         File file = null;
         long diff = endTime.getTime() - startTime.getTime();

+ 7 - 5
fiveep-service/src/main/java/com/bizmatics/service/impl/SiteServiceImpl.java

@@ -16,7 +16,7 @@ import com.bizmatics.service.DeviceService;
 import com.bizmatics.service.SiteService;
 import com.bizmatics.service.UserSiteService;
 import com.bizmatics.service.enums.DeviceStatusCode;
-import com.bizmatics.service.util.UserUtil;
+import com.bizmatics.service.util.SessionLocal;
 import com.bizmatics.service.vo.DeviceCountVO;
 import com.bizmatics.service.vo.SiteVO;
 import lombok.extern.slf4j.Slf4j;
@@ -52,7 +52,8 @@ public class SiteServiceImpl extends AbstractCrudService<SiteMapper, Site> imple
 
     @Override
     public DeviceCountVO selectCount() {
-        Integer userId = UserUtil.getUserId();
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
         DeviceCountVO deviceCountVO = new DeviceCountVO();
         deviceCountVO.setNormalCount(baseMapper.selectCount(userId,null,DeviceStatusCode.NORMAL.getValue()));
         deviceCountVO.setOffLineCount(baseMapper.selectCount(userId,null,DeviceStatusCode.OFFLINE.getValue()));
@@ -64,15 +65,16 @@ public class SiteServiceImpl extends AbstractCrudService<SiteMapper, Site> imple
 
     @Override
     public List<Site> list(String name) {
-        return baseMapper.list(UserUtil.getUserId(),name);
+        return baseMapper.list(SessionLocal.getUserId(),name);
 
     }
 
     @Override
     public List<SiteVO> siteAndStatusList(String name) {
         List<SiteVO> list = new ArrayList<>();
-        Integer userId = UserUtil.getUserId();
-        List<Site> sites = baseMapper.list(UserUtil.getUserId(), name);
+//        Integer userId = UserUtil.getUserId();
+        Integer userId = SessionLocal.getUserId();
+        List<Site> sites = baseMapper.list(SessionLocal.getUserId(), name);
         List<Device> deviceList = deviceMapper.list(userId, null, null, null, null, null);
         List<AlarmPower> alarmPowers = alarmPowerMapper.list(userId, null, null, null, null, null, 1);
         sites.forEach(site -> list.add(enhanceSite(deviceList,site,alarmPowers)));

+ 17 - 0
fiveep-service/src/main/java/com/bizmatics/service/impl/UserServiceImpl.java

@@ -6,9 +6,13 @@ import com.bizmatics.common.mvc.base.AbstractCrudService;
 import com.bizmatics.model.User;
 import com.bizmatics.persistence.mapper.UserMapper;
 import com.bizmatics.service.UserService;
+import com.bizmatics.service.util.SessionLocal;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.Optional;
+
 /**
  * <p>
  *  服务实现类
@@ -20,6 +24,19 @@ import org.springframework.stereotype.Service;
 @Service
 public class UserServiceImpl extends AbstractCrudService<UserMapper, User> implements UserService {
 
+    @Override
+    public User login(String name, String password, HttpServletRequest request) {
+        User user = baseMapper.selectOne(Wrappers.lambdaQuery(User.class)
+                .eq(User::getUserName, name)
+                .eq(User::getUserPassword, password));
+        //存储session
+        request.getSession().setAttribute( "sessionuser", user );
+        //存储ThreadLocal
+        SessionLocal.setUser( user );
+        return Optional.ofNullable(user).orElseThrow(() -> new BusinessException("用户信息为空"));
+
+    }
+
     @Override
     public User getByUserName(String name) {
         return baseMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUserName, name));

+ 42 - 0
fiveep-service/src/main/java/com/bizmatics/service/util/SessionLocal.java

@@ -0,0 +1,42 @@
+package com.bizmatics.service.util;
+
+import com.bizmatics.common.core.exception.BusinessException;
+import com.bizmatics.model.User;
+import lombok.extern.log4j.Log4j2;
+
+import java.util.Optional;
+
+import static com.bizmatics.common.core.exception.BusinessErrorCode.BIZ_LACK_NECESSARY_PARAM_ERROR;
+
+/**
+ * @author yq
+ * @date 2021/7/8 10:34
+ */
+@Log4j2
+public class SessionLocal {
+    private static ThreadLocal<User> local = new ThreadLocal<User>();
+
+    /**
+     * 设置用户信息
+     *
+     * @param user
+     */
+    public static void setUser( User user )
+    {
+        local.set( user );
+    }
+
+    /**
+     * 获取登录用户信息
+     *
+     * @return
+     */
+    public static User getUser() {
+        log.info( "当前线程:" + Thread.currentThread().getName() );
+        return local.get();
+    }
+
+    public static Integer getUserId(){
+        return Optional.ofNullable(getUser()).map(User::getId).orElseThrow(() ->new BusinessException(BIZ_LACK_NECESSARY_PARAM_ERROR,"用户未登录"));
+    }
+}

+ 23 - 23
fiveep-service/src/main/java/com/bizmatics/service/util/UserUtil.java

@@ -1,23 +1,23 @@
-package com.bizmatics.service.util;
-
-import com.bizmatics.service.config.security.UserDetail;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-/**
- * @author yq
- * @date 2021/8/3 15:18
- */
-public class UserUtil {
-
-
-
-    public static UserDetail getUserDetail(){
-        return (UserDetail) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();
-    }
-
-
-    public static Integer getUserId(){
-        UserDetail userDetail = (UserDetail)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-        return userDetail.getId();
-    }
-}
+//package com.bizmatics.service.util;
+//
+//import com.bizmatics.service.config.security.UserDetail;
+//import org.springframework.security.core.context.SecurityContextHolder;
+//
+///**
+// * @author yq
+// * @date 2021/8/3 15:18
+// */
+//public class UserUtil {
+//
+//
+//
+//    public static UserDetail getUserDetail(){
+//        return (UserDetail) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();
+//    }
+//
+//
+//    public static Integer getUserId(){
+//        UserDetail userDetail = (UserDetail)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+//        return userDetail.getId();
+//    }
+//}