mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-10-20 17:28:49 +00:00
Add RequiredFactor.Builder.<factor-name>Authority()
Closes gh-18033
This commit is contained in:
parent
702878acae
commit
2b4e36c67f
@ -127,6 +127,78 @@ public final class RequiredFactor {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#AUTHORIZATION_CODE_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder authorizationCodeAuthority() {
|
||||
return authority(FactorGrantedAuthority.AUTHORIZATION_CODE_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#BEARER_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder bearerTokenAuthority() {
|
||||
return authority(FactorGrantedAuthority.BEARER_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#CAS_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder casAuthority() {
|
||||
return authority(FactorGrantedAuthority.CAS_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#PASSWORD_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder passwordAuthority() {
|
||||
return authority(FactorGrantedAuthority.PASSWORD_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#OTT_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder ottAuthority() {
|
||||
return authority(FactorGrantedAuthority.OTT_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#SAML_RESPONSE_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder samlAuthority() {
|
||||
return authority(FactorGrantedAuthority.SAML_RESPONSE_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#WEBAUTHN_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder webauthnAuthority() {
|
||||
return authority(FactorGrantedAuthority.WEBAUTHN_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for invoking {@link #authority(String)} with
|
||||
* {@link FactorGrantedAuthority#X509_AUTHORITY}.
|
||||
* @return the builder.
|
||||
*/
|
||||
public Builder x509Authority() {
|
||||
return authority(FactorGrantedAuthority.X509_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional {@link Duration} of time that the {@link RequiredFactor} is
|
||||
* valid for.
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.springframework.security.authorization;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -57,4 +58,56 @@ class RequiredFactorTests {
|
||||
assertThat(requiredPassword.getValidDuration()).isEqualTo(validDuration);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderAuthorizationCodeAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::authorizationCodeAuthority,
|
||||
FactorGrantedAuthority.AUTHORIZATION_CODE_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderBearerTokenAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::bearerTokenAuthority,
|
||||
FactorGrantedAuthority.BEARER_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderCasAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::casAuthority, FactorGrantedAuthority.CAS_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderPasswordAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::passwordAuthority,
|
||||
FactorGrantedAuthority.PASSWORD_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderOttAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::ottAuthority, FactorGrantedAuthority.OTT_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderSamlAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::samlAuthority,
|
||||
FactorGrantedAuthority.SAML_RESPONSE_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWebauthnAuthority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::webauthnAuthority,
|
||||
FactorGrantedAuthority.WEBAUTHN_AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderX509Authority() {
|
||||
assertBuilderSetsAuthority(RequiredFactor.Builder::x509Authority, FactorGrantedAuthority.X509_AUTHORITY);
|
||||
}
|
||||
|
||||
private static void assertBuilderSetsAuthority(Consumer<RequiredFactor.Builder> configure, String expected) {
|
||||
RequiredFactor.Builder builder = RequiredFactor.builder();
|
||||
configure.accept(builder);
|
||||
RequiredFactor requiredFactor = builder.build();
|
||||
assertThat(requiredFactor.getAuthority()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user