EnableGlobalMultiFactorAuthentication->EnableMultiFactorAuthentication
Closes gh-18127
This commit is contained in:
+3
-3
@@ -27,12 +27,12 @@ import org.springframework.security.authorization.AuthorizationManagerFactories;
|
||||
import org.springframework.security.authorization.DefaultAuthorizationManagerFactory;
|
||||
|
||||
/**
|
||||
* Uses {@link EnableGlobalMultiFactorAuthentication} to configure a
|
||||
* Uses {@link EnableMultiFactorAuthentication} to configure a
|
||||
* {@link DefaultAuthorizationManagerFactory}.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @since 7.0
|
||||
* @see EnableGlobalMultiFactorAuthentication
|
||||
* @see EnableMultiFactorAuthentication
|
||||
*/
|
||||
class AuthorizationManagerFactoryConfiguration implements ImportAware {
|
||||
|
||||
@@ -49,7 +49,7 @@ class AuthorizationManagerFactoryConfiguration implements ImportAware {
|
||||
@Override
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
Map<String, Object> multiFactorAuthenticationAttrs = importMetadata
|
||||
.getAnnotationAttributes(EnableGlobalMultiFactorAuthentication.class.getName());
|
||||
.getAnnotationAttributes(EnableMultiFactorAuthentication.class.getName());
|
||||
|
||||
this.authorities = (String[]) multiFactorAuthenticationAttrs.getOrDefault("authorities", new String[0]);
|
||||
}
|
||||
|
||||
+9
-6
@@ -26,9 +26,12 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.security.authorization.DefaultAuthorizationManagerFactory;
|
||||
|
||||
/**
|
||||
* Exposes a {@link DefaultAuthorizationManagerFactory} as a Bean with the
|
||||
* {@link #authorities()} specified as additional required authorities. The configuration
|
||||
* will be picked up by both
|
||||
* Enables Multi-Factor Authentication (MFA) support within Spring Security.
|
||||
*
|
||||
* When {@link #authorities()} is specified creates a
|
||||
* {@link DefaultAuthorizationManagerFactory} as a Bean with the {@link #authorities()}
|
||||
* specified as additional required authorities. The configuration will be picked up by
|
||||
* both
|
||||
* {@link org.springframework.security.config.annotation.web.configuration.EnableWebSecurity}
|
||||
* and
|
||||
* {@link org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity}.
|
||||
@@ -36,7 +39,7 @@ import org.springframework.security.authorization.DefaultAuthorizationManagerFac
|
||||
* <pre>
|
||||
|
||||
* @Configuration
|
||||
* @EnableGlobalMultiFactorAuthentication(authorities = { GrantedAuthorities.FACTOR_OTT, GrantedAuthorities.FACTOR_PASSWORD })
|
||||
* @EnableMultiFactorAuthentication(authorities = { GrantedAuthorities.FACTOR_OTT, GrantedAuthorities.FACTOR_PASSWORD })
|
||||
* public class MyConfiguration {
|
||||
* // ...
|
||||
* }
|
||||
@@ -51,8 +54,8 @@ import org.springframework.security.authorization.DefaultAuthorizationManagerFac
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Documented
|
||||
@Import(GlobalMultiFactorAuthenticationSelector.class)
|
||||
public @interface EnableGlobalMultiFactorAuthentication {
|
||||
@Import(MultiFactorAuthenticationSelector.class)
|
||||
public @interface EnableMultiFactorAuthentication {
|
||||
|
||||
/**
|
||||
* The additional authorities that are required.
|
||||
+4
-4
@@ -25,19 +25,19 @@ import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.security.authorization.DefaultAuthorizationManagerFactory;
|
||||
|
||||
/**
|
||||
* Uses {@link EnableGlobalMultiFactorAuthentication} to configure a
|
||||
* Uses {@link EnableMultiFactorAuthentication} to configure a
|
||||
* {@link DefaultAuthorizationManagerFactory}.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @since 7.0
|
||||
* @see EnableGlobalMultiFactorAuthentication
|
||||
* @see EnableMultiFactorAuthentication
|
||||
*/
|
||||
class GlobalMultiFactorAuthenticationSelector implements ImportSelector {
|
||||
class MultiFactorAuthenticationSelector implements ImportSelector {
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata metadata) {
|
||||
Map<String, Object> multiFactorAuthenticationAttrs = metadata
|
||||
.getAnnotationAttributes(EnableGlobalMultiFactorAuthentication.class.getName());
|
||||
.getAnnotationAttributes(EnableMultiFactorAuthentication.class.getName());
|
||||
String[] authorities = (String[]) multiFactorAuthenticationAttrs.getOrDefault("authorities", new String[0]);
|
||||
List<String> imports = new ArrayList<>(2);
|
||||
if (authorities.length > 0) {
|
||||
+3
-3
@@ -53,14 +53,14 @@ import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnableGlobalMultiFactorAuthentication}.
|
||||
* Tests for {@link EnableMultiFactorAuthentication}.
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
@WithMockUser(authorities = FactorGrantedAuthority.PASSWORD_AUTHORITY)
|
||||
public class EnableGlobalMultiFactorAuthenticationFiltersSetTests {
|
||||
public class EnableMultiFactorAuthenticationFiltersSetTests {
|
||||
|
||||
@Autowired
|
||||
private AuthenticationManager manager;
|
||||
@@ -105,7 +105,7 @@ public class EnableGlobalMultiFactorAuthenticationFiltersSetTests {
|
||||
|
||||
@EnableWebSecurity
|
||||
@Configuration
|
||||
@EnableGlobalMultiFactorAuthentication(
|
||||
@EnableMultiFactorAuthentication(
|
||||
authorities = { FactorGrantedAuthority.OTT_AUTHORITY, FactorGrantedAuthority.PASSWORD_AUTHORITY })
|
||||
static class Config {
|
||||
|
||||
+3
-3
@@ -59,13 +59,13 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnableGlobalMultiFactorAuthentication}.
|
||||
* Tests for {@link EnableMultiFactorAuthentication}.
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
public class EnableGlobalMultiFactorAuthenticationTests {
|
||||
public class EnableMultiFactorAuthenticationTests {
|
||||
|
||||
private static final String ATTR_NAME = "org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors$SecurityContextRequestPostProcessorSupport$TestSecurityContextRepository.REPO";
|
||||
|
||||
@@ -111,7 +111,7 @@ public class EnableGlobalMultiFactorAuthenticationTests {
|
||||
@EnableWebSecurity
|
||||
@EnableMethodSecurity
|
||||
@Configuration
|
||||
@EnableGlobalMultiFactorAuthentication(
|
||||
@EnableMultiFactorAuthentication(
|
||||
authorities = { FactorGrantedAuthority.OTT_AUTHORITY, FactorGrantedAuthority.PASSWORD_AUTHORITY })
|
||||
static class Config {
|
||||
|
||||
Reference in New Issue
Block a user