Codota Logo
SecurityMockMvcRequestPostProcessors.authentication
Code IndexAdd Codota to your IDE (free)

How to use
authentication
method
in
org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors

Best Java code snippets using org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication (Showing top 4 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Connection c =
  • Codota IconDataSource dataSource;dataSource.getConnection()
  • Codota IconString url;DriverManager.getConnection(url)
  • Codota IconIdentityDatabaseUtil.getDBConnection()
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-security

@Test    // http@jaas-api-provision
public void configureWhenJaasApiIntegrationFilterAddedThenJaasSubjectObtained() throws Exception {
  LoginContext loginContext = mock(LoginContext.class);
  when(loginContext.getSubject()).thenReturn(new Subject());
  JaasAuthenticationToken authenticationToken = mock(JaasAuthenticationToken.class);
  when(authenticationToken.isAuthenticated()).thenReturn(true);
  when(authenticationToken.getLoginContext()).thenReturn(loginContext);
  this.spring.register(JaasApiProvisionConfig.class).autowire();
  this.mockMvc.perform(get("/").with(authentication(authenticationToken)));
  verify(loginContext, times(1)).getSubject();
}
origin: spring-projects/spring-security

@Test
public void requestWhenAuthorizedClientFoundThenMethodArgumentResolved() throws Exception {
  String clientRegistrationId = "client1";
  String principalName = "user1";
  TestingAuthenticationToken authentication = new TestingAuthenticationToken(principalName, "password");
  OAuth2AuthorizedClientRepository authorizedClientRepository = mock(OAuth2AuthorizedClientRepository.class);
  OAuth2AuthorizedClient authorizedClient = mock(OAuth2AuthorizedClient.class);
  when(authorizedClientRepository.loadAuthorizedClient(
      eq(clientRegistrationId), eq(authentication), any(HttpServletRequest.class))).thenReturn(authorizedClient);
  OAuth2AccessToken accessToken = mock(OAuth2AccessToken.class);
  when(authorizedClient.getAccessToken()).thenReturn(accessToken);
  OAuth2AuthorizedClientArgumentResolverConfig.AUTHORIZED_CLIENT_REPOSITORY = authorizedClientRepository;
  this.spring.register(OAuth2AuthorizedClientArgumentResolverConfig.class).autowire();
  this.mockMvc.perform(get("/authorized-client").with(authentication(authentication)))
    .andExpect(status().isOk())
    .andExpect(content().string("resolved"));
}
origin: spring-projects/spring-security

@Test
public void configureWhenEnableWebMvcThenAuthenticationPrincipalResolvable() throws Exception {
  this.spring.register(AuthenticationPrincipalConfig.class).autowire();
  this.mockMvc.perform(get("/").with(authentication(new TestingAuthenticationToken("user1", "password"))))
    .andExpect(content().string("user1"));
}
origin: spring-projects/spring-security

.param(OAuth2ParameterNames.CODE, "code")
.param(OAuth2ParameterNames.STATE, "state")
.with(authentication(authentication))
.session(session))
.andExpect(status().is3xxRedirection())
org.springframework.security.test.web.servlet.requestSecurityMockMvcRequestPostProcessorsauthentication

Javadoc

Establish a SecurityContext that uses the specified Authenticationfor the Authentication#getPrincipal() and a custom UserDetails. All details are declarative and do not require that the user actually exists.

The support works by associating the user to the HttpServletRequest. To associate the request to the SecurityContextHolder you need to ensure that the SecurityContextPersistenceFilter is associated with the MockMvc instance. A few ways to do this are:

  • Invoking apply SecurityMockMvcConfigurers#springSecurity()
  • Adding Spring Security's FilterChainProxy to MockMvc
  • Manually adding SecurityContextPersistenceFilter to the MockMvc instance may make sense when using MockMvcBuilders standaloneSetup

Popular methods of SecurityMockMvcRequestPostProcessors

  • httpBasic
    Convenience mechanism for setting the Authorization header to use HTTP Basic with the given username
  • user
    Establish a SecurityContext that has a UsernamePasswordAuthenticationToken for the Authentication#ge
  • csrf
    Creates a RequestPostProcessor that will automatically populate a valid CsrfToken in the request.
  • testSecurityContext
    Creates a RequestPostProcessor that can be used to ensure that the resulting request is ran with the
  • x509
    Populates the provided X509Certificate instances on the request.
  • digest
    Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a req
  • securityContext
    Establish the specified SecurityContext to be used. This works by associating the user to the HttpSe

Popular in Java

  • Running tasks concurrently on multiple threads
  • requestLocationUpdates (LocationManager)
  • onCreateOptionsMenu (Activity)
  • getExternalFilesDir (Context)
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • InputStreamReader (java.io)
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Locale (java.util)
    A Locale object represents a specific geographical, political, or cultural region. An operation that
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now