1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.security.kim; |
17 |
|
|
18 |
|
import org.kuali.student.security.spring.KSRiceDefaultUserDetailsService; |
19 |
|
import org.springframework.dao.DataAccessException; |
20 |
|
import org.springframework.security.AuthenticationException; |
21 |
|
import org.springframework.security.AuthenticationServiceException; |
22 |
|
import org.springframework.security.BadCredentialsException; |
23 |
|
import org.springframework.security.providers.AuthenticationProvider; |
24 |
|
import org.springframework.security.providers.UsernamePasswordAuthenticationToken; |
25 |
|
import org.springframework.security.providers.dao.AbstractUserDetailsAuthenticationProvider; |
26 |
|
import org.springframework.security.providers.dao.DaoAuthenticationProvider; |
27 |
|
import org.springframework.security.providers.dao.SaltSource; |
28 |
|
import org.springframework.security.providers.encoding.PasswordEncoder; |
29 |
|
import org.springframework.security.providers.encoding.PlaintextPasswordEncoder; |
30 |
|
import org.springframework.security.userdetails.UserDetails; |
31 |
|
import org.springframework.security.userdetails.UserDetailsService; |
32 |
|
import org.springframework.util.Assert; |
33 |
|
|
34 |
|
|
35 |
|
@link |
36 |
|
@link@link |
37 |
|
|
38 |
|
@author |
39 |
|
|
40 |
|
|
|
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 18 |
Complexity Density: 0.69 |
|
41 |
|
public class KimAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private PasswordEncoder passwordEncoder = new PlaintextPasswordEncoder(); |
46 |
|
|
47 |
|
private SaltSource saltSource; |
48 |
|
|
49 |
|
private UserDetailsService userDetailsService; |
50 |
|
|
51 |
|
private boolean includeDetailsObject = true; |
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.75 |
|
55 |
0
|
protected void additionalAuthenticationChecks(UserDetails userDetails,... |
56 |
|
UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { |
57 |
0
|
Object salt = null; |
58 |
|
|
59 |
0
|
if (this.saltSource != null) { |
60 |
0
|
salt = this.saltSource.getSalt(userDetails); |
61 |
|
} |
62 |
|
|
63 |
0
|
if (authentication.getCredentials() == null) { |
64 |
0
|
throw new BadCredentialsException(messages.getMessage( |
65 |
|
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), |
66 |
0
|
includeDetailsObject ? userDetails : null); |
67 |
|
} |
68 |
|
|
69 |
0
|
String presentedPassword = authentication.getCredentials().toString(); |
70 |
|
|
71 |
0
|
if (!passwordEncoder.isPasswordValid(userDetails.getPassword(), presentedPassword, salt)) { |
72 |
0
|
throw new BadCredentialsException(messages.getMessage( |
73 |
|
"AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), |
74 |
0
|
includeDetailsObject ? userDetails : null); |
75 |
|
} |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0
|
protected void doAfterPropertiesSet() throws Exception {... |
79 |
0
|
Assert.notNull(this.userDetailsService, "A UserDetailsService must be set"); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
82 |
0
|
protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)... |
83 |
|
throws AuthenticationException { |
84 |
0
|
UserDetails loadedUser; |
85 |
|
|
86 |
0
|
UserDetailsService ksRiceDefaultUserDetailsService = this.getUserDetailsService(); |
87 |
0
|
if(!(ksRiceDefaultUserDetailsService instanceof KSRiceDefaultUserDetailsService)){ |
88 |
0
|
throw new AuthenticationServiceException( |
89 |
|
"UserDetailsService is not an an instance of KSRiceDefaultUserDetailsService"); |
90 |
|
} |
91 |
|
|
92 |
0
|
try { |
93 |
|
|
94 |
0
|
loadedUser = ((KSRiceDefaultUserDetailsService)ksRiceDefaultUserDetailsService).loadUserByUsernameAndToken(username, authentication); |
95 |
|
} |
96 |
|
catch (DataAccessException repositoryProblem) { |
97 |
0
|
throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); |
98 |
|
} |
99 |
|
|
100 |
0
|
if (loadedUser == null) { |
101 |
0
|
throw new AuthenticationServiceException( |
102 |
|
"UserDetailsService returned null, which is an interface contract violation"); |
103 |
|
} |
104 |
0
|
return loadedUser; |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@link |
110 |
|
|
111 |
|
@param |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0
|
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {... |
114 |
0
|
this.passwordEncoder = passwordEncoder; |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0
|
protected PasswordEncoder getPasswordEncoder() {... |
118 |
0
|
return passwordEncoder; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
0
|
public void setSaltSource(SaltSource saltSource) {... |
129 |
0
|
this.saltSource = saltSource; |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0
|
protected SaltSource getSaltSource() {... |
133 |
0
|
return saltSource; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0
|
public void setUserDetailsService(UserDetailsService userDetailsService) {... |
137 |
0
|
this.userDetailsService = userDetailsService; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0
|
protected UserDetailsService getUserDetailsService() {... |
141 |
0
|
return userDetailsService; |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
0
|
protected boolean isIncludeDetailsObject() {... |
145 |
0
|
return includeDetailsObject; |
146 |
|
} |
147 |
|
} |