|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.adapters.cas; |
|
17 |
| |
|
18 |
| import org.acegisecurity.Authentication; |
|
19 |
| import org.acegisecurity.AuthenticationException; |
|
20 |
| import org.acegisecurity.AuthenticationManager; |
|
21 |
| import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; |
|
22 |
| |
|
23 |
| import org.apache.commons.logging.Log; |
|
24 |
| import org.apache.commons.logging.LogFactory; |
|
25 |
| |
|
26 |
| import org.springframework.beans.factory.InitializingBean; |
|
27 |
| |
|
28 |
| import javax.servlet.ServletRequest; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| public final class CasPasswordHandler implements InitializingBean { |
|
44 |
| |
|
45 |
| |
|
46 |
| private static final Log logger = LogFactory.getLog(CasPasswordHandler.class); |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| private AuthenticationManager authenticationManager; |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
6
| public void setAuthenticationManager(
|
|
55 |
| AuthenticationManager authenticationManager) { |
|
56 |
6
| this.authenticationManager = authenticationManager;
|
|
57 |
| } |
|
58 |
| |
|
59 |
1
| public AuthenticationManager getAuthenticationManager() {
|
|
60 |
1
| return authenticationManager;
|
|
61 |
| } |
|
62 |
| |
|
63 |
6
| public void afterPropertiesSet() throws Exception {
|
|
64 |
6
| if (this.authenticationManager == null) {
|
|
65 |
1
| throw new IllegalArgumentException(
|
|
66 |
| "An AuthenticationManager is required"); |
|
67 |
| } |
|
68 |
| } |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
9
| public boolean authenticate(ServletRequest servletRequest, String username,
|
|
85 |
| String password) { |
|
86 |
9
| if ((username == null) || "".equals(username)) {
|
|
87 |
2
| return false;
|
|
88 |
| } |
|
89 |
| |
|
90 |
7
| if (password == null) {
|
|
91 |
1
| password = "";
|
|
92 |
| } |
|
93 |
| |
|
94 |
7
| Authentication request = new UsernamePasswordAuthenticationToken(username
|
|
95 |
| .toString(), password.toString()); |
|
96 |
7
| Authentication response = null;
|
|
97 |
| |
|
98 |
7
| try {
|
|
99 |
7
| response = authenticationManager.authenticate(request);
|
|
100 |
| } catch (AuthenticationException failed) { |
|
101 |
3
| if (logger.isDebugEnabled()) {
|
|
102 |
0
| logger.debug("Authentication request for user: " + username
|
|
103 |
| + " failed: " + failed.toString()); |
|
104 |
| } |
|
105 |
| |
|
106 |
3
| return false;
|
|
107 |
| } |
|
108 |
| |
|
109 |
4
| if (logger.isDebugEnabled()) {
|
|
110 |
0
| logger.debug("Authentication request for user: " + username
|
|
111 |
| + " successful"); |
|
112 |
| } |
|
113 |
| |
|
114 |
4
| return true;
|
|
115 |
| } |
|
116 |
| } |