1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Remove Generic Typing From Authentication.Builder

It would be better to introduce parameter types for
principal and credentials into Authentication.Builder
at the same time as doing so for Authentication

Issue gh-17861
This commit is contained in:
Josh Cummings
2025-09-09 09:03:57 -06:00
parent 4744752a1b
commit dd50dc0c40
17 changed files with 47 additions and 38 deletions
@@ -82,8 +82,7 @@ public class Saml2AssertionAuthentication extends Saml2Authentication {
*
* @since 7.0
*/
public static class Builder<B extends Builder<B>>
extends Saml2Authentication.Builder<Saml2ResponseAssertionAccessor, B> {
public static class Builder<B extends Builder<B>> extends Saml2Authentication.Builder<B> {
private Saml2ResponseAssertionAccessor assertion;
@@ -96,10 +95,11 @@ public class Saml2AssertionAuthentication extends Saml2Authentication {
}
@Override
public B credentials(@Nullable Saml2ResponseAssertionAccessor credentials) {
saml2Response(credentials.getResponseValue());
Assert.notNull(credentials, "assertion cannot be null");
this.assertion = credentials;
public B credentials(@Nullable Object credentials) {
Assert.isInstanceOf(Saml2ResponseAssertionAccessor.class, credentials,
"credentials must be of type Saml2ResponseAssertionAccessor");
saml2Response(((Saml2ResponseAssertionAccessor) credentials).getResponseValue());
this.assertion = (Saml2ResponseAssertionAccessor) credentials;
return (B) this;
}
@@ -71,7 +71,7 @@ public class Saml2Authentication extends AbstractAuthenticationToken {
setAuthenticated(true);
}
Saml2Authentication(Builder<?, ?> builder) {
Saml2Authentication(Builder<?> builder) {
super(builder);
this.principal = builder.principal;
this.saml2Response = builder.saml2Response;
@@ -95,7 +95,7 @@ public class Saml2Authentication extends AbstractAuthenticationToken {
return getSaml2Response();
}
abstract static class Builder<C, B extends Builder<C, B>> extends AbstractAuthenticationBuilder<Object, C, B> {
abstract static class Builder<B extends Builder<B>> extends AbstractAuthenticationBuilder<B> {
private Object principal;
@@ -32,7 +32,7 @@ class Saml2AssertionAuthenticationTests {
Saml2AssertionAuthentication factorOne = new Saml2AssertionAuthentication("alice",
prototype.nameId("alice").build(), AuthorityUtils.createAuthorityList("FACTOR_ONE"), "alice");
Saml2AssertionAuthentication factorTwo = new Saml2AssertionAuthentication("bob",
prototype.nameId("alice").build(), AuthorityUtils.createAuthorityList("FACTOR_TWO"), "bob");
prototype.nameId("bob").build(), AuthorityUtils.createAuthorityList("FACTOR_TWO"), "bob");
Saml2AssertionAuthentication result = factorOne.toBuilder()
.authorities((a) -> a.addAll(factorTwo.getAuthorities()))
.principal(factorTwo.getPrincipal())