Skip to content

Commit 18fbf88

Browse files
committed
Polish CAS Authentication Builder
Issue spring-projectsgh-17861
1 parent dd50dc0 commit 18fbf88

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

cas/src/main/java/org/springframework/security/cas/authentication/CasAuthenticationToken.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.jspecify.annotations.Nullable;
2424

2525
import org.springframework.security.authentication.AbstractAuthenticationToken;
26-
import org.springframework.security.core.Authentication;
2726
import org.springframework.security.core.GrantedAuthority;
2827
import org.springframework.security.core.userdetails.UserDetails;
2928
import org.springframework.util.Assert;
@@ -183,7 +182,7 @@ public String toString() {
183182
}
184183

185184
/**
186-
* A builder preserving the concrete {@link Authentication} type
185+
* A builder of {@link CasAuthenticationToken} instances
187186
*
188187
* @since 7.0
189188
*/
@@ -208,8 +207,13 @@ protected Builder(CasAuthenticationToken token) {
208207
this.assertion = token.assertion;
209208
}
210209

211-
public B keyHash(Integer keyHash) {
212-
this.keyHash = keyHash;
210+
/**
211+
* Use this key
212+
* @param key the key to use
213+
* @return the {@link Builder} for further configurations
214+
*/
215+
public B key(String key) {
216+
this.keyHash = key.hashCode();
213217
return (B) this;
214218
}
215219

@@ -227,11 +231,21 @@ public B credentials(@Nullable Object credentials) {
227231
return (B) this;
228232
}
229233

234+
/**
235+
* Use this {@link UserDetails}
236+
* @param userDetails the {@link UserDetails} to use
237+
* @return the {@link Builder} for further configurations
238+
*/
230239
public B userDetails(UserDetails userDetails) {
231240
this.userDetails = userDetails;
232241
return (B) this;
233242
}
234243

244+
/**
245+
* Use this {@link Assertion}
246+
* @param assertion the {@link Assertion} to use
247+
* @return the {@link Builder} for further configurations
248+
*/
235249
public B assertion(Assertion assertion) {
236250
this.assertion = assertion;
237251
return (B) this;

cas/src/main/java/org/springframework/security/cas/authentication/CasServiceTicketAuthenticationToken.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.jspecify.annotations.Nullable;
2323

2424
import org.springframework.security.authentication.AbstractAuthenticationToken;
25-
import org.springframework.security.core.Authentication;
2625
import org.springframework.security.core.GrantedAuthority;
2726
import org.springframework.util.Assert;
2827

@@ -122,7 +121,7 @@ public Builder<?> toBuilder() {
122121
}
123122

124123
/**
125-
* A builder preserving the concrete {@link Authentication} type
124+
* A builder of {@link CasServiceTicketAuthenticationToken} instances
126125
*
127126
* @since 7.0
128127
*/

cas/src/test/java/org/springframework/security/cas/authentication/CasAuthenticationTokenTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void toBuilderWhenApplyThenCopies() {
167167
AuthorityUtils.createAuthorityList("FACTOR_TWO"), PasswordEncodedUser.admin(), assertionTwo);
168168
CasAuthenticationToken authentication = factorOne.toBuilder()
169169
.authorities((a) -> a.addAll(factorTwo.getAuthorities()))
170-
.keyHash(factorTwo.getKeyHash())
170+
.key("yek")
171171
.principal(factorTwo.getPrincipal())
172172
.credentials(factorTwo.getCredentials())
173173
.userDetails(factorTwo.getUserDetails())

0 commit comments

Comments
 (0)