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
public static final class SecurityMockMvcResultMatchers.AuthenticatedMatcher extends java.lang.Object
AMockMvc
ResultMatcher
that verifies a specific user is associated to theMvcResult
.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
match(org.springframework.test.web.servlet.MvcResult result)
SecurityMockMvcResultMatchers.AuthenticatedMatcher
withAuthentication(java.util.function.Consumer<org.springframework.security.core.Authentication> assesrtAuthentication)
Allows for any validating the authentication with arbitrary assertionsSecurityMockMvcResultMatchers.AuthenticatedMatcher
withAuthentication(org.springframework.security.core.Authentication expected)
Specifies the expectedAuthentication
SecurityMockMvcResultMatchers.AuthenticatedMatcher
withAuthenticationName(java.lang.String expected)
Specifies the expectedPrincipal.getName()
SecurityMockMvcResultMatchers.AuthenticatedMatcher
withAuthenticationPrincipal(java.lang.Object expected)
Specifies the expected principalSecurityMockMvcResultMatchers.AuthenticatedMatcher
withAuthorities(java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> expected)
Specifies theAuthentication.getAuthorities()
SecurityMockMvcResultMatchers.AuthenticatedMatcher
withRoles(java.lang.String... roles)
Specifies theAuthentication.getAuthorities()
SecurityMockMvcResultMatchers.AuthenticatedMatcher
withSecurityContext(org.springframework.security.core.context.SecurityContext expected)
Specifies the expectedSecurityContext
SecurityMockMvcResultMatchers.AuthenticatedMatcher
withUsername(java.lang.String expected)
Specifies the expected username
-
-
-
Method Detail
-
match
public void match(org.springframework.test.web.servlet.MvcResult result)
-
withAuthentication
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthentication(java.util.function.Consumer<org.springframework.security.core.Authentication> assesrtAuthentication)
Allows for any validating the authentication with arbitrary assertions- Parameters:
assesrtAuthentication
- the Consumer which validates the authentication- Returns:
- the AuthenticatedMatcher to perform additional assertions
-
withUsername
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withUsername(java.lang.String expected)
Specifies the expected username- Parameters:
expected
- the expected username- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withSecurityContext
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withSecurityContext(org.springframework.security.core.context.SecurityContext expected)
Specifies the expectedSecurityContext
- Parameters:
expected
- the expectedSecurityContext
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthentication
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthentication(org.springframework.security.core.Authentication expected)
Specifies the expectedAuthentication
- Parameters:
expected
- the expectedAuthentication
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthenticationPrincipal
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthenticationPrincipal(java.lang.Object expected)
Specifies the expected principal- Parameters:
expected
- the expected principal- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthenticationName
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthenticationName(java.lang.String expected)
Specifies the expectedPrincipal.getName()
- Parameters:
expected
- the expectedPrincipal.getName()
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withAuthorities
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withAuthorities(java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> expected)
Specifies theAuthentication.getAuthorities()
- Parameters:
expected
- theAuthentication.getAuthorities()
- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
withRoles
public SecurityMockMvcResultMatchers.AuthenticatedMatcher withRoles(java.lang.String... roles)
Specifies theAuthentication.getAuthorities()
- Parameters:
roles
- the roles. Each value is automatically prefixed with "ROLE_"- Returns:
- the
SecurityMockMvcResultMatchers.AuthenticatedMatcher
for further customization
-
-