Class SecurityMockMvcResultMatchers.AuthenticatedMatcher
java.lang.Object
org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.AuthenticatedMatcher
- All Implemented Interfaces:
org.springframework.test.web.servlet.ResultMatcher
- Enclosing class:
- SecurityMockMvcResultMatchers
A
MockMvc ResultMatcher that verifies a specific user is associated
to the MvcResult.- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionprotected SecurityContextload(org.springframework.test.web.servlet.MvcResult result) voidmatch(org.springframework.test.web.servlet.MvcResult result) withAuthentication(Consumer<Authentication> assertAuthentication) Allows for any validating the authentication with arbitrary assertions.withAuthentication(Authentication expected) Specifies the expectedAuthentication.withAuthenticationName(String expected) Specifies the expectedPrincipal.getName().withAuthenticationPrincipal(Object expected) Specifies the expected principal.withAuthorities(String... authorities) Specifies theGrantedAuthority.getAuthority().withAuthorities(Collection<? extends GrantedAuthority> expected) Specifies theAuthentication.getAuthorities().Specifies the expected roles.Specifies the expected roles.withSecurityContext(SecurityContext expected) Specifies the expectedSecurityContext.withUsername(String expected) Specifies the expected username.
-
Method Details
-
match
@NullUnmarked public void match(org.springframework.test.web.servlet.MvcResult result) -
withAuthentication
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthentication(Consumer<Authentication> assertAuthentication) Allows for any validating the authentication with arbitrary assertions.- Parameters:
assertAuthentication- the Consumer which validates the authentication- Returns:
- the AuthenticatedMatcher to perform additional assertions
-
withUsername
Specifies the expected username.- Parameters:
expected- the expected username- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withSecurityContext
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withSecurityContext(SecurityContext expected) Specifies the expectedSecurityContext.- Parameters:
expected- the expectedSecurityContext- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withAuthentication
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthentication(Authentication expected) Specifies the expectedAuthentication.- Parameters:
expected- the expectedAuthentication- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withAuthenticationPrincipal
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthenticationPrincipal(Object expected) Specifies the expected principal.- Parameters:
expected- the expected principal- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withAuthenticationName
Specifies the expectedPrincipal.getName().- Parameters:
expected- the expectedPrincipal.getName()- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withAuthorities
Specifies theGrantedAuthority.getAuthority().- Parameters:
authorities- the authorityNames- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withAuthorities
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthorities(Collection<? extends GrantedAuthority> expected) Specifies theAuthentication.getAuthorities().- Parameters:
expected- theAuthentication.getAuthorities()- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withRoles
Specifies the expected roles.Since a set of authorities can contain more than just roles, this method differs from
withAuthorities(java.lang.String...)in that it only verifies the authorities prefixed byROLE_. Other authorities are ignored.If you want to validate more than just roles, please use
withAuthorities(java.lang.String...).- Parameters:
roles- the roles. Each value is automatically prefixed with "ROLE_"- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization
-
withRoles
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withRoles(String rolePrefix, String[] roles) Specifies the expected roles.Since a set of authorities can contain more than just roles, this method differs from
withAuthorities(java.lang.String...)in that it only verifies the authorities prefixed byROLE_. Other authorities are ignored.If you want to validate more than just roles, please use
withAuthorities(java.lang.String...).- Parameters:
rolePrefix- the role prefixroles- the roles. Each value is automatically prefixed with therolePrefix- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcherfor further customization - Since:
- 7.0
-
load
-