File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/main/java/guru/springframework/services/security Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ package guru .springframework .services .security ;
2
+
3
+ import org .aspectj .lang .annotation .*;
4
+ import org .springframework .security .core .Authentication ;
5
+ import org .springframework .stereotype .Component ;
6
+
7
+ /**
8
+ * Created by jt on 1/6/16.
9
+ */
10
+ @ Aspect
11
+ @ Component
12
+ public class LoginAspect {
13
+
14
+ @ Pointcut ("execution(* org.springframework.security.authentication.AuthenticationProvider.authenticate(..))" )
15
+ public void doAuthenticate (){
16
+
17
+ }
18
+
19
+ @ Before ("guru.springframework.services.security.LoginAspect.doAuthenticate() && args(authentication)" )
20
+ public void logBefore (Authentication authentication ){
21
+
22
+ System .out .println ("This is before the Authenticate Method: authentication: " + authentication .isAuthenticated ());
23
+ }
24
+
25
+ @ AfterReturning (value = "guru.springframework.services.security.LoginAspect.doAuthenticate()" ,
26
+ returning = "authentication" )
27
+ public void logAfterAuthenticate ( Authentication authentication ){
28
+ System .out .println ("This is after the Authenticate Method authentication: " + authentication .isAuthenticated ());
29
+ }
30
+
31
+ @ AfterThrowing ("guru.springframework.services.security.LoginAspect.doAuthenticate() && args(authentication)" )
32
+ public void logAuthenicationException (Authentication authentication ){
33
+ String userDetails = (String ) authentication .getPrincipal ();
34
+ System .out .println ("Login failed for user: " + userDetails );
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments