Codota Logo
OAuth2AuthorizationRequestRedirectWebFilter
Code IndexAdd Codota 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)

  • Common ways to obtain OAuth2AuthorizationRequestRedirectWebFilter
private void myMethod () {
OAuth2AuthorizationRequestRedirectWebFilter o =
  • Codota IconReactiveClientRegistrationRepository clientRegistrationRepository;new OAuth2AuthorizationRequestRedirectWebFilter(clientRegistrationRepository)
  • Smart code suggestions by Codota
}
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

  • Making http post requests using okhttp
  • getSupportFragmentManager (FragmentActivity)
  • getContentResolver (Context)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
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