| 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 |
18 |
public class SiteminderAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
2 |
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 |
5 |
if (!user.isEnabled()) { |
| 67 |
0 |
throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", |
| 68 |
|
"Account disabled")); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
5 |
if (!user.isAccountNonExpired()) { |
| 72 |
0 |
throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired", |
| 73 |
|
"Account expired")); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
5 |
if (!user.isAccountNonLocked()) { |
| 77 |
0 |
throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked", |
| 78 |
|
"Account locked")); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
5 |
if (!user.isCredentialsNonExpired()) { |
| 82 |
1 |
throw new CredentialsExpiredException(messages.getMessage( |
| 83 |
|
"AbstractUserDetailsAuthenticationProvider.credentialsExpired", "Credentials expired")); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
4 |
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
protected void doAfterPropertiesSet() throws Exception { |
| 92 |
2 |
Assert.notNull(this.userDetailsService, "A UserDetailsService must be set"); |
| 93 |
1 |
} |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
public UserDetailsService getUserDetailsService() { |
| 100 |
14 |
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 |
13 |
loadedUser = this.getUserDetailsService().loadUserByUsername(username); |
| 113 |
1 |
} catch (DataAccessException repositoryProblem) { |
| 114 |
1 |
throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); |
| 115 |
8 |
} |
| 116 |
|
|
| 117 |
8 |
if (loadedUser == null) { |
| 118 |
1 |
throw new AuthenticationServiceException( |
| 119 |
|
"UserDetailsService returned null, which is an interface contract violation"); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
7 |
return loadedUser; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
public void setUserDetailsService(final UserDetailsService userDetailsService) { |
| 130 |
15 |
this.userDetailsService = userDetailsService; |
| 131 |
15 |
} |
| 132 |
|
|
| 133 |
|
} |