congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
OAuth2AuthorizationRequestRedirectWebFilter
Code IndexAdd Tabnine to your IDE (free)

How to use
OAuth2AuthorizationRequestRedirectWebFilter
in
org.springframework.security.oauth2.client.web.server

Best Java code snippets using org.springframework.security.oauth2.client.web.server.OAuth2AuthorizationRequestRedirectWebFilter (Showing top 12 results out of 315)

origin: spring-projects/spring-security

private OAuth2AuthorizationRequestRedirectWebFilter getRedirectWebFilter() {
  OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter;
  if (this.authorizationRequestResolver == null) {
    oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(getClientRegistrationRepository());
  } else {
    oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(this.authorizationRequestResolver);
  }
  return oauthRedirectFilter;
}
origin: spring-projects/spring-security

@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
  return this.authorizationRequestResolver.resolve(exchange)
    .switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
    .onErrorResume(ClientAuthorizationRequiredException.class, e -> {
      return this.requestCache.saveRequest(exchange)
        .then(this.authorizationRequestResolver.resolve(exchange, e.getClientRegistrationId()));
    })
    .flatMap(clientRegistration -> sendRedirectForAuthorization(exchange, clientRegistration));
}
origin: spring-projects/spring-security

@Before
public void setup() {
  this.filter = new OAuth2AuthorizationRequestRedirectWebFilter(this.clientRepository);
  this.filter.setAuthorizationRequestRepository(this.authzRequestRepository);
  FilteringWebHandler webHandler = new FilteringWebHandler(e -> e.getResponse().setComplete(), Arrays.asList(this.filter));
  this.client = WebTestClient.bindToWebHandler(webHandler).build();
  when(this.clientRepository.findByRegistrationId(this.registration.getRegistrationId())).thenReturn(
      Mono.just(this.registration));
  when(this.authzRequestRepository.saveAuthorizationRequest(any(), any())).thenReturn(
      Mono.empty());
}
origin: spring-projects/spring-security

  @Test
  public void filterWhenPathMatchesThenRequestSessionAttributeNotSaved() {
    this.filter.setRequestCache(this.requestCache);
    this.client.get()
        .uri("https://example.com/oauth2/authorization/registration-id")
        .exchange()
        .expectStatus()
        .is3xxRedirection()
        .returnResult(String.class);
    verifyZeroInteractions(this.requestCache);
  }
}
origin: spring-projects/spring-security

@Test
public void filterWhenExceptionThenSaveRequestSessionAttribute() {
  this.filter.setRequestCache(this.requestCache);
  when(this.requestCache.saveRequest(any())).thenReturn(Mono.empty());
  FilteringWebHandler webHandler = new FilteringWebHandler(
      e -> Mono.error(new ClientAuthorizationRequiredException(this.registration.getRegistrationId())),
      Arrays.asList(this.filter));
  this.client = WebTestClient.bindToWebHandler(webHandler).build();
  this.client.get()
      .uri("https://example.com/foo")
      .exchange()
      .expectStatus()
      .is3xxRedirection()
      .returnResult(String.class);
  verify(this.requestCache).saveRequest(any());
}
origin: spring-projects/spring-security

@Test
public void constructorWhenClientRegistrationRepositoryNullThenIllegalArgumentException() {
  this.clientRepository = null;
  assertThatThrownBy(() -> new OAuth2AuthorizationRequestRedirectWebFilter(this.clientRepository))
    .isInstanceOf(IllegalArgumentException.class);
}
origin: apache/servicemix-bundles

@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
  return this.authorizationRequestResolver.resolve(exchange)
    .switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
    .onErrorResume(ClientAuthorizationRequiredException.class, e -> this.authorizationRequestResolver.resolve(exchange, e.getClientRegistrationId()))
    .flatMap(clientRegistration -> sendRedirectForAuthorization(exchange, clientRegistration));
}
origin: spring-projects/spring-security

protected void configure(ServerHttpSecurity http) {
  ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository();
  ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository();
  ServerAuthenticationConverter authenticationConverter = getAuthenticationConverter();
  ReactiveAuthenticationManager authenticationManager = getAuthenticationManager();
  OAuth2AuthorizationCodeGrantWebFilter codeGrantWebFilter = new OAuth2AuthorizationCodeGrantWebFilter(authenticationManager,
      authenticationConverter,
      authorizedClientRepository);
  OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(
      clientRegistrationRepository);
  http.addFilterAt(codeGrantWebFilter, SecurityWebFiltersOrder.OAUTH2_AUTHORIZATION_CODE);
  http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
}
origin: org.springframework.security/spring-security-config

protected void configure(ServerHttpSecurity http) {
  ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository();
  ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository();
  ServerAuthenticationConverter authenticationConverter = getAuthenticationConverter();
  ReactiveAuthenticationManager authenticationManager = getAuthenticationManager();
  OAuth2AuthorizationCodeGrantWebFilter codeGrantWebFilter = new OAuth2AuthorizationCodeGrantWebFilter(authenticationManager,
      authenticationConverter,
      authorizedClientRepository);
  OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(
      clientRegistrationRepository);
  http.addFilterAt(codeGrantWebFilter, SecurityWebFiltersOrder.OAUTH2_AUTHORIZATION_CODE);
  http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
}
origin: org.springframework.security/spring-security-config

protected void configure(ServerHttpSecurity http) {
  ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository();
  ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository();
  OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(clientRegistrationRepository);
  ReactiveAuthenticationManager manager = getAuthenticationManager();
  AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager, authorizedClientRepository);
  authenticationFilter.setRequiresAuthenticationMatcher(createAttemptAuthenticationRequestMatcher());
  authenticationFilter.setServerAuthenticationConverter(getAuthenticationConverter(clientRegistrationRepository));
  RedirectServerAuthenticationSuccessHandler redirectHandler = new RedirectServerAuthenticationSuccessHandler();
  authenticationFilter.setAuthenticationSuccessHandler(redirectHandler);
  authenticationFilter.setAuthenticationFailureHandler(new ServerAuthenticationFailureHandler() {
    @Override
    public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange,
        AuthenticationException exception) {
      return Mono.error(exception);
    }
  });
  authenticationFilter.setSecurityContextRepository(new WebSessionServerSecurityContextRepository());
  MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher(
      MediaType.TEXT_HTML);
  htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
  Map<String, String> urlToText = http.oauth2Login.getLinks();
  if (urlToText.size() == 1) {
    http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint(urlToText.keySet().iterator().next())));
  } else {
    http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint("/login")));
  }
  http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
  http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION);
}
origin: apache/servicemix-bundles

protected void configure(ServerHttpSecurity http) {
  ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository();
  ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository();
  ServerAuthenticationConverter authenticationConverter = getAuthenticationConverter();
  ReactiveAuthenticationManager authenticationManager = getAuthenticationManager();
  OAuth2AuthorizationCodeGrantWebFilter codeGrantWebFilter = new OAuth2AuthorizationCodeGrantWebFilter(authenticationManager,
      authenticationConverter,
      authorizedClientRepository);
  OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(
      clientRegistrationRepository);
  http.addFilterAt(codeGrantWebFilter, SecurityWebFiltersOrder.OAUTH2_AUTHORIZATION_CODE);
  http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
}
origin: apache/servicemix-bundles

protected void configure(ServerHttpSecurity http) {
  ReactiveClientRegistrationRepository clientRegistrationRepository = getClientRegistrationRepository();
  ServerOAuth2AuthorizedClientRepository authorizedClientRepository = getAuthorizedClientRepository();
  OAuth2AuthorizationRequestRedirectWebFilter oauthRedirectFilter = new OAuth2AuthorizationRequestRedirectWebFilter(clientRegistrationRepository);
  ReactiveAuthenticationManager manager = getAuthenticationManager();
  AuthenticationWebFilter authenticationFilter = new OAuth2LoginAuthenticationWebFilter(manager, authorizedClientRepository);
  authenticationFilter.setRequiresAuthenticationMatcher(createAttemptAuthenticationRequestMatcher());
  authenticationFilter.setServerAuthenticationConverter(getAuthenticationConverter(clientRegistrationRepository));
  RedirectServerAuthenticationSuccessHandler redirectHandler = new RedirectServerAuthenticationSuccessHandler();
  authenticationFilter.setAuthenticationSuccessHandler(redirectHandler);
  authenticationFilter.setAuthenticationFailureHandler(new ServerAuthenticationFailureHandler() {
    @Override
    public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange,
        AuthenticationException exception) {
      return Mono.error(exception);
    }
  });
  authenticationFilter.setSecurityContextRepository(new WebSessionServerSecurityContextRepository());
  MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher(
      MediaType.TEXT_HTML);
  htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
  Map<String, String> urlToText = http.oauth2Login.getLinks();
  if (urlToText.size() == 1) {
    http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint(urlToText.keySet().iterator().next())));
  } else {
    http.defaultEntryPoints.add(new DelegateEntry(htmlMatcher, new RedirectServerAuthenticationEntryPoint("/login")));
  }
  http.addFilterAt(oauthRedirectFilter, SecurityWebFiltersOrder.HTTP_BASIC);
  http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.AUTHENTICATION);
}
org.springframework.security.oauth2.client.web.serverOAuth2AuthorizationRequestRedirectWebFilter

Javadoc

This WebFilter initiates the authorization code grant or implicit grant flow by redirecting the End-User's user-agent to the Authorization Server's Authorization Endpoint.

It builds the OAuth 2.0 Authorization Request, which is used as the redirect URI to the Authorization Endpoint. The redirect URI will include the client identifier, requested scope(s), state, response type, and a redirection URI which the authorization server will send the user-agent back to once access is granted (or denied) by the End-User (Resource Owner).

By default, this Filter responds to authorization requests at the URI /oauth2/authorization/{registrationId}}. The URI template variable {registrationId}} represents the ClientRegistration#getRegistrationId() of the client that is used for initiating the OAuth 2.0 Authorization Request.

Most used methods

  • <init>
    Constructs an OAuth2AuthorizationRequestRedirectFilter using the provided parameters.
  • sendRedirectForAuthorization
  • setAuthorizationRequestRepository
    Sets the repository used for storing OAuth2AuthorizationRequest's.
  • setRequestCache
    The request cache to use to save the request before sending a redirect.

Popular in Java

  • Parsing JSON documents to java classes using gson
  • addToBackStack (FragmentTransaction)
  • getContentResolver (Context)
  • compareTo (BigDecimal)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Sublime Text for Python
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now