Example usage for org.springframework.security.config.annotation.web.builders HttpSecurity antMatcher

List of usage examples for org.springframework.security.config.annotation.web.builders HttpSecurity antMatcher

Introduction

In this page you can find the example usage for org.springframework.security.config.annotation.web.builders HttpSecurity antMatcher.

Prototype

public HttpSecurity antMatcher(String antPattern) 

Source Link

Document

Allows configuring the HttpSecurity to only be invoked when matching the provided ant pattern.

Usage

From source file:shiver.me.timbers.spring.security.integration.JwtCustomPrincipleSecurityConfigurationApply.java

@Override
protected final void configure(HttpSecurity http) throws Exception {
    http.apply(jwt());/*from  w w  w . j  a  v  a2s  . c  om*/
    http.antMatcher("/custom/**");
    http.csrf().disable();
    http.authorizeRequests().anyRequest().authenticated();
    http.formLogin().successHandler(new NoRedirectAuthenticationSuccessHandler()).loginPage("/custom/signIn")
            .permitAll();
    http.logout().logoutUrl("/custom/signOut")
            .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
    http.exceptionHandling().authenticationEntryPoint(new Http403ForbiddenEntryPoint());
}

From source file:shiver.me.timbers.spring.security.integration.JwtAnnotationSecurityConfiguration.java

@Override
protected final void configure(HttpSecurity http) throws Exception {
    http.sessionManagement().sessionCreationPolicy(STATELESS);
    http.antMatcher("/jwt/**");
    http.csrf().disable();//from   ww w .  ja v a2 s.  com
    http.authorizeRequests().antMatchers("/jwt/one").access("hasRole('ONE')").antMatchers("/jwt/two")
            .access("hasRole('TWO')").anyRequest().authenticated();
    http.formLogin().successHandler(new NoRedirectAuthenticationSuccessHandler()).loginPage("/jwt/signIn")
            .permitAll();
    http.logout().logoutUrl("/jwt/signOut").logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
    http.exceptionHandling().authenticationEntryPoint(new Http403ForbiddenEntryPoint());
}

From source file:com.github.bonndan.fullofstars.FOSApplication.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    // @formatter:off   
    http.antMatcher("/**").authorizeRequests().antMatchers("/", "/login**", "/webjars/**").permitAll()
            .anyRequest().authenticated().and().exceptionHandling()
            .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
            .logoutSuccessUrl("/").permitAll().and().csrf().csrfTokenRepository(csrfTokenRepository()).and()
            .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
            .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
    // @formatter:on
}

From source file:com.github.lynxdb.server.api.http.WebSecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable();/* w w w .j a v  a  2 s .  c  o m*/

    http.antMatcher("/api/**").authorizeRequests().antMatchers(HttpMethod.OPTIONS).permitAll()
            .antMatchers(EpAggregators.ENDPOINT, EpQuery.ENDPOINT, EpSuggest.ENDPOINT)
            .hasAnyRole(User.Rank.RO_USER.name(), User.Rank.RW_USER.name(), User.Rank.ADMIN.name())
            .antMatchers(HttpMethod.POST, EpPut.ENDPOINT)
            .hasAnyRole(User.Rank.RW_USER.name(), User.Rank.ADMIN.name())
            .antMatchers(EpUser.ENDPOINT, EpVhost.ENDPOINT).hasRole(User.Rank.ADMIN.name());

    http.httpBasic().realmName("Lynx");

    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}

From source file:shiver.me.timbers.spring.security.integration.JwtApplySecurityConfiguration.java

@Override
protected final void configure(HttpSecurity http) throws Exception {
    http.sessionManagement().sessionCreationPolicy(STATELESS);
    http.apply(jwt());/*from   w w  w . java2s.c om*/
    http.antMatcher("/jwt/**");
    http.csrf().disable();
    http.authorizeRequests().antMatchers("/jwt/one").access("hasRole('ONE')").antMatchers("/jwt/two")
            .access("hasRole('TWO')").anyRequest().authenticated();
    http.formLogin().successHandler(new NoRedirectAuthenticationSuccessHandler()).loginPage("/jwt/signIn")
            .permitAll();
    http.logout().logoutUrl("/jwt/signOut").logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());
    http.exceptionHandling().authenticationEntryPoint(new Http403ForbiddenEntryPoint());
}

From source file:com.emusic.SecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    // @formatter:off   
    http.antMatcher("/**").authorizeRequests()
            .antMatchers("/", "/login**", "/webjars/**", "/views/**", "/products").permitAll().anyRequest()
            .authenticated().and().exceptionHandling()
            .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")).and().logout()
            .logoutSuccessUrl("/").permitAll().and().csrf().csrfTokenRepository(csrfTokenRepository()).and()
            .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
            .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
    // @formatter:on
}

From source file:com.epam.reportportal.auth.OAuthSecurityConfig.java

@Override
protected final void configure(HttpSecurity http) throws Exception {
    //@formatter:off
    http.antMatcher("/**").authorizeRequests()
            .antMatchers(SSO_LOGIN_PATH + "/**", "/webjars/**", "/index.html", "/epam/**", "/info", "/health")
            .permitAll().anyRequest().authenticated().and().csrf().disable().sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    CompositeFilter authCompositeFilter = new CompositeFilter();
    List<OAuth2ClientAuthenticationProcessingFilter> additionalFilters = ImmutableList
            .<OAuth2ClientAuthenticationProcessingFilter>builder()
            .addAll(getDefaultFilters(oauth2ClientContext)).addAll(getAdditionalFilters(oauth2ClientContext))
            .build();//  www. ja  va  2s  .c  om

    /* make sure filters have correct exception handler */
    additionalFilters.forEach(filter -> filter.setAuthenticationFailureHandler(OAUTH_ERROR_HANDLER));
    authCompositeFilter.setFilters(additionalFilters);

    //install additional OAuth Authentication filters
    http.addFilterAfter(authCompositeFilter, BasicAuthenticationFilter.class);
    //@formatter:on
}

From source file:com.netflix.genie.web.security.SecurityConfig.java

/**
 * {@inheritDoc}/*w  w  w  .  ja va 2  s . com*/
 */
@Override
protected void configure(final HttpSecurity http) throws Exception {
    // This is a catch all in the case that SAML isn't turned on but one of the API security is.
    // If this isn't all the default implementation of WebSecurityConfigurerAdapter kicks in and presents
    // a default login page with the Spring Boot generated password. This allows everything through but the UI
    // won't be able to call the server to get any information. As such that configuration (SAML off but something
    // else on) is kind of pointless if you want to use the UI.
    // TODO: Revisit if there is a way to enforce this or at least provide some in memory login if nothing else
    http.antMatcher("/**").authorizeRequests().anyRequest().permitAll();
}

From source file:it.infn.mw.iam.config.saml.SamlConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    String pattern = "/saml/**";

    http.antMatcher(pattern);

    http.csrf().ignoringAntMatchers(pattern);

    http.authorizeRequests().antMatchers(pattern).permitAll();

    http.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class).addFilterAfter(samlFilter(),
            BasicAuthenticationFilter.class);
}

From source file:com.naveen.demo.config.Saml2SSOConfig.java

/**
  * Defines the web based security configuration.
  * /* w w  w .j  av  a 2  s. c  o m*/
  * @param   http It allows configuring web based security for specific http requests.
  * @throws  Exception 
  */
@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().antMatchers("/js/**", "/libs/**", "/login**").permitAll();

    http.httpBasic().authenticationEntryPoint(samlEntryPoint());
    http.csrf().disable();
    http.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class).addFilterAfter(samlFilter(),
            BasicAuthenticationFilter.class);

    http.antMatcher("/login/**").authorizeRequests().anyRequest().authenticated();

    /* http        
    .authorizeRequests()
    .antMatchers("/").permitAll()
    .antMatchers("/error").permitAll()
    .antMatchers("/saml/**").permitAll()
    .anyRequest().authenticated();*/

    http.logout().logoutSuccessUrl("/");
}