Fix typos in Mock MVC docs

This commit is contained in:
Eleftheria Stein 2021-06-15 14:55:00 +02:00
parent b44d0fb319
commit e89db9fd69

View File

@ -379,7 +379,7 @@ In that case, you can configure an `OidcUser` by hand:
---- ----
OidcUser oidcUser = new DefaultOidcUser( OidcUser oidcUser = new DefaultOidcUser(
AuthorityUtils.createAuthorityList("SCOPE_message:read"), AuthorityUtils.createAuthorityList("SCOPE_message:read"),
Collections.singletonMap("user_name", "foo_user"), OidcIdToken.withTokenValue("id-token").claim("user_name", "foo_user").build(),
"user_name"); "user_name");
mvc mvc
@ -668,8 +668,6 @@ And the resulting `Jwt`, were it tested, would pass in the following way:
assertThat(jwt.getTokenValue()).isEqualTo("token"); assertThat(jwt.getTokenValue()).isEqualTo("token");
assertThat(jwt.getHeaders().get("alg")).isEqualTo("none"); assertThat(jwt.getHeaders().get("alg")).isEqualTo("none");
assertThat(jwt.getSubject()).isEqualTo("sub"); assertThat(jwt.getSubject()).isEqualTo("sub");
GrantedAuthority authority = jwt.getAuthorities().iterator().next();
assertThat(authority.getAuthority()).isEqualTo("read");
---- ----
These values can, of course be configured. These values can, of course be configured.
@ -716,7 +714,8 @@ You can also specify a complete `Jwt`, for which `{security-api-url}org/springfr
Jwt jwt = Jwt.withTokenValue("token") Jwt jwt = Jwt.withTokenValue("token")
.header("alg", "none") .header("alg", "none")
.claim("sub", "user") .claim("sub", "user")
.claim("scope", "read"); .claim("scope", "read")
.build();
mvc mvc
.perform(get("/endpoint") .perform(get("/endpoint")
@ -756,7 +755,7 @@ Let's say that we've got a controller that retrieves the authentication as a `Be
---- ----
@GetMapping("/endpoint") @GetMapping("/endpoint")
public String foo(BearerTokenAuthentication authentication) { public String foo(BearerTokenAuthentication authentication) {
return (String) authentication.getTokenAttributes("sub"); return (String) authentication.getTokenAttributes().get("sub");
} }
---- ----
@ -984,8 +983,8 @@ We can also combine the assertions:
[source,java] [source,java]
---- ----
mvc mvc
.perform(formLogin().user("admin").roles("USER","ADMIN")) .perform(formLogin().user("admin"))
.andExpect(authenticated().withUsername("admin")); .andExpect(authenticated().withUsername("admin").withRoles("USER", "ADMIN"));
---- ----
We can also make arbitrary assertions on the authentication We can also make arbitrary assertions on the authentication