diff --git a/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson/OAuth2AuthorizationServerJacksonModuleTests.java b/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson/OAuth2AuthorizationServerJacksonModuleTests.java index baa8b47cd4a..fba1942a8ba 100644 --- a/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson/OAuth2AuthorizationServerJacksonModuleTests.java +++ b/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson/OAuth2AuthorizationServerJacksonModuleTests.java @@ -27,6 +27,8 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.FactorGrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.jackson.SecurityJacksonModules; import org.springframework.security.oauth2.jose.jws.MacAlgorithm; import org.springframework.security.oauth2.jwt.JwtClaimNames; @@ -71,6 +73,19 @@ public void readValueWhenOAuth2AuthorizationAttributesThenSuccess() { assertThat(this.mapper.readValue(json, STRING_OBJECT_MAP)).isEqualTo(attributes); } + @Test + public void readValueWhenOAuth2AuthorizationAttributesWithFactorGrantedAuthorityThenSuccess() { + Authentication principal = UsernamePasswordAuthenticationToken.authenticated("principal", "credentials", + List.of(new SimpleGrantedAuthority("ROLE_USER"), + FactorGrantedAuthority.fromAuthority(FactorGrantedAuthority.PASSWORD_AUTHORITY))); + OAuth2Authorization authorization = TestOAuth2Authorizations.authorization() + .attributes((attrs) -> attrs.put(Principal.class.getName(), principal)) + .build(); + Map attributes = authorization.getAttributes(); + String json = this.mapper.writeValueAsString(attributes); + assertThat(this.mapper.readValue(json, STRING_OBJECT_MAP)).isEqualTo(attributes); + } + @Test public void readValueWhenOAuth2AccessTokenMetadataThenSuccess() { OAuth2Authorization authorization = TestOAuth2Authorizations.authorization().build(); diff --git a/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationServerJackson2ModuleTests.java b/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationServerJackson2ModuleTests.java index f06d3f81f1f..b25b4127d74 100644 --- a/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationServerJackson2ModuleTests.java +++ b/oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/jackson2/OAuth2AuthorizationServerJackson2ModuleTests.java @@ -28,6 +28,8 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.FactorGrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.jackson2.SecurityJackson2Modules; import org.springframework.security.oauth2.jose.jws.MacAlgorithm; import org.springframework.security.oauth2.jwt.JwtClaimNames; @@ -74,6 +76,19 @@ public void readValueWhenOAuth2AuthorizationAttributesThenSuccess() throws Excep assertThat(this.objectMapper.readValue(json, STRING_OBJECT_MAP)).isEqualTo(attributes); } + @Test + public void readValueWhenOAuth2AuthorizationAttributesWithFactorGrantedAuthorityThenSuccess() throws Exception { + Authentication principal = UsernamePasswordAuthenticationToken.authenticated("principal", "credentials", + List.of(new SimpleGrantedAuthority("ROLE_USER"), + FactorGrantedAuthority.fromAuthority(FactorGrantedAuthority.PASSWORD_AUTHORITY))); + OAuth2Authorization authorization = TestOAuth2Authorizations.authorization() + .attributes((attrs) -> attrs.put(Principal.class.getName(), principal)) + .build(); + Map attributes = authorization.getAttributes(); + String json = this.objectMapper.writeValueAsString(attributes); + assertThat(this.objectMapper.readValue(json, STRING_OBJECT_MAP)).isEqualTo(attributes); + } + @Test public void readValueWhenOAuth2AccessTokenMetadataThenSuccess() throws Exception { OAuth2Authorization authorization = TestOAuth2Authorizations.authorization().build();