|
@@ -2,12 +2,15 @@ package com.community.huiju.security;
|
2
|
2
|
|
3
|
3
|
import com.community.commom.constant.Constant;
|
4
|
4
|
import com.community.huiju.exception.WisdomSecurityException;
|
|
5
|
+import com.community.huiju.service.IRoleService;
|
|
6
|
+import lombok.extern.slf4j.Slf4j;
|
5
|
7
|
import org.springframework.security.authentication.AuthenticationProvider;
|
6
|
8
|
import org.springframework.security.core.Authentication;
|
7
|
9
|
import org.springframework.security.core.AuthenticationException;
|
8
|
10
|
import org.springframework.security.core.GrantedAuthority;
|
9
|
11
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
10
|
12
|
|
|
13
|
+import javax.servlet.http.HttpServletRequest;
|
11
|
14
|
import java.util.Collection;
|
12
|
15
|
import java.util.List;
|
13
|
16
|
|
|
@@ -16,12 +19,17 @@ import java.util.List;
|
16
|
19
|
*
|
17
|
20
|
* @author weiximei
|
18
|
21
|
*/
|
|
22
|
+@Slf4j
|
19
|
23
|
public class RestPreAuthenticateProvider implements AuthenticationProvider {
|
20
|
24
|
|
|
25
|
+ private HttpServletRequest request;
|
|
26
|
+
|
|
27
|
+ private IRoleService iRoleService;
|
|
28
|
+
|
21
|
29
|
@Override
|
22
|
30
|
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
23
|
31
|
|
24
|
|
-
|
|
32
|
+ log.info("provider session: {}", request.getSession().getId());
|
25
|
33
|
TokenAuthrentication tokenAuthrentication = (TokenAuthrentication) authentication.getPrincipal();
|
26
|
34
|
if (null != tokenAuthrentication) {
|
27
|
35
|
Collection<GrantedAuthority> grantedAuthorityList = tokenAuthrentication.getAuthorities();
|
|
@@ -31,7 +39,8 @@ public class RestPreAuthenticateProvider implements AuthenticationProvider {
|
31
|
39
|
tokenAuthrentication.setAuthenticated(false);
|
32
|
40
|
return tokenAuthrentication;
|
33
|
41
|
}
|
34
|
|
- tokenAuthrentication.setAuthenticated(true);
|
|
42
|
+ boolean hasPermission = iRoleService.hasPermission(request);
|
|
43
|
+ tokenAuthrentication.setAuthenticated(hasPermission);
|
35
|
44
|
return tokenAuthrentication;
|
36
|
45
|
}
|
37
|
46
|
|
|
@@ -52,4 +61,9 @@ public class RestPreAuthenticateProvider implements AuthenticationProvider {
|
52
|
61
|
return PreAuthenticatedAuthenticationToken.class.isAssignableFrom(authentication)
|
53
|
62
|
|| TokenAuthrentication.class.isAssignableFrom(authentication);
|
54
|
63
|
}
|
|
64
|
+
|
|
65
|
+ public RestPreAuthenticateProvider(HttpServletRequest request, IRoleService iRoleService) {
|
|
66
|
+ this.request = request;
|
|
67
|
+ this.iRoleService = iRoleService;
|
|
68
|
+ }
|
55
|
69
|
}
|