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 SecurityContext
load
(org.springframework.test.web.servlet.MvcResult result) void
match
(org.springframework.test.web.servlet.MvcResult result) withAuthentication
(Consumer<Authentication> assertAuthentication) Allows for any validating the authentication with arbitrary assertionswithAuthentication
(Authentication expected) Specifies the expectedAuthentication
withAuthenticationName
(String expected) Specifies the expectedPrincipal.getName()
withAuthenticationPrincipal
(Object expected) Specifies the expected principalwithAuthorities
(Collection<? extends GrantedAuthority> expected) Specifies theAuthentication.getAuthorities()
Specifies theAuthentication.getAuthorities()
withSecurityContext
(SecurityContext expected) Specifies the expectedSecurityContext
withUsername
(String expected) Specifies the expected username
-
Method Details
-
match
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.AuthenticatedMatcher
for further customization
-
withSecurityContext
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withSecurityContext(SecurityContext expected) Specifies the expectedSecurityContext
- Parameters:
expected
- the expectedSecurityContext
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthentication
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthentication(Authentication expected) Specifies the expectedAuthentication
- Parameters:
expected
- the expectedAuthentication
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthenticationPrincipal
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthenticationPrincipal(Object expected) Specifies the expected principal- Parameters:
expected
- the expected principal- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthenticationName
Specifies the expectedPrincipal.getName()
- Parameters:
expected
- the expectedPrincipal.getName()
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthorities
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthorities(Collection<? extends GrantedAuthority> expected) Specifies theAuthentication.getAuthorities()
- Parameters:
expected
- theAuthentication.getAuthorities()
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withRoles
Specifies theAuthentication.getAuthorities()
- Parameters:
roles
- the roles. Each value is automatically prefixed with "ROLE_"- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
load
-