1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers.siteminder;
17
18 import org.acegisecurity.AccountExpiredException;
19 import org.acegisecurity.AuthenticationException;
20 import org.acegisecurity.AuthenticationServiceException;
21 import org.acegisecurity.CredentialsExpiredException;
22 import org.acegisecurity.DisabledException;
23 import org.acegisecurity.LockedException;
24 import org.acegisecurity.providers.AuthenticationProvider;
25 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
26 import org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider;
27 import org.acegisecurity.userdetails.UserDetails;
28 import org.acegisecurity.userdetails.UserDetailsService;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.springframework.dao.DataAccessException;
32 import org.springframework.util.Assert;
33
34
35
36
37
38
39
40 public class SiteminderAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
41
42
43
44
45
46 private static final Log logger = LogFactory.getLog(SiteminderAuthenticationProvider.class);
47
48
49
50
51
52
53 private UserDetailsService userDetailsService;
54
55
56
57
58
59
60 protected void additionalAuthenticationChecks(final UserDetails user,
61 final UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
62
63
64
65
66 if (!user.isEnabled()) {
67 throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled",
68 "Account disabled"));
69 }
70
71 if (!user.isAccountNonExpired()) {
72 throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired",
73 "Account expired"));
74 }
75
76 if (!user.isAccountNonLocked()) {
77 throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked",
78 "Account locked"));
79 }
80
81 if (!user.isCredentialsNonExpired()) {
82 throw new CredentialsExpiredException(messages.getMessage(
83 "AbstractUserDetailsAuthenticationProvider.credentialsExpired", "Credentials expired"));
84 }
85
86 }
87
88
89
90
91 protected void doAfterPropertiesSet() throws Exception {
92 Assert.notNull(this.userDetailsService, "A UserDetailsService must be set");
93 }
94
95
96
97
98
99 public UserDetailsService getUserDetailsService() {
100 return userDetailsService;
101 }
102
103
104
105
106 protected final UserDetails retrieveUser(final String username,
107 final UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
108
109 UserDetails loadedUser;
110
111 try {
112 loadedUser = this.getUserDetailsService().loadUserByUsername(username);
113 } catch (DataAccessException repositoryProblem) {
114 throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
115 }
116
117 if (loadedUser == null) {
118 throw new AuthenticationServiceException(
119 "UserDetailsService returned null, which is an interface contract violation");
120 }
121
122 return loadedUser;
123 }
124
125
126
127
128
129 public void setUserDetailsService(final UserDetailsService userDetailsService) {
130 this.userDetailsService = userDetailsService;
131 }
132
133 }