org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter Java Examples

The following examples show how to use org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostServiceApplication.java    From spring-microservice-sample with GNU General Public License v3.0 6 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter securityConfigBean(){

    return new  WebSecurityConfigurerAdapter() {

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                .httpBasic()
                .and()
                .authorizeRequests()
                .antMatchers(HttpMethod.GET, "/posts/**").permitAll()
                .antMatchers(HttpMethod.DELETE, "/posts/**").hasRole("ADMIN")
                .anyRequest().authenticated()
                .and()
                .csrf().disable();
        }
    };
}
 
Example #2
Source File: LdapSecurityConfiguration.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter(LdapAuthenticationProvider authenticationProvider) {
  return new RoadWebSecurityConfigurerAdapter() {
    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.authenticationProvider(authenticationProvider);
    }

  };
}
 
Example #3
Source File: SecurityConfig.java    From angularjs-springmvc-sample-boot with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigure(){
    return new WebSecurityConfigurerAdapter() {
        
        @Override
        protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
            http
                .authorizeRequests()
                .antMatchers("/api/signup", "/api/users/username-check")
                .permitAll()
                .and()
                    .authorizeRequests()
                    .regexMatchers(HttpMethod.GET, "^/api/users/[\\d]*(\\/)?$").authenticated()
                    .regexMatchers(HttpMethod.GET, "^/api/users(\\/)?(\\?.+)?$").hasRole("ADMIN")
                    .regexMatchers(HttpMethod.DELETE, "^/api/users/[\\d]*(\\/)?$").hasRole("ADMIN")
                    .regexMatchers(HttpMethod.POST, "^/api/users(\\/)?$").hasRole("ADMIN")
                .and()
                    .authorizeRequests()
                    .antMatchers("/api/**").authenticated()
                .and()
                    .authorizeRequests()
                    .anyRequest().permitAll()
                .and()
                    .sessionManagement()
                    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                    .httpBasic()
                .and()
                    .csrf()
                    .disable();
        // @formatter:on
        }
    };
}
 
Example #4
Source File: EnableOAuth2SsoCondition.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String[] enablers = context.getBeanFactory().getBeanNamesForAnnotation(EnableOAuth2Sso.class);
	ConditionMessage.Builder message = ConditionMessage.forCondition("@EnableOAuth2Sso Condition");
	for (String name : enablers) {
		if (context.getBeanFactory().isTypeMatch(name, WebSecurityConfigurerAdapter.class)) {
			return ConditionOutcome.match(
					message.found("@EnableOAuth2Sso annotation on WebSecurityConfigurerAdapter").items(name));
		}
	}
	return ConditionOutcome.noMatch(
			message.didNotFind("@EnableOAuth2Sso annotation " + "on any WebSecurityConfigurerAdapter").atAll());
}
 
Example #5
Source File: OAuth2SsoCustomConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
	if (invocation.getMethod().getName().equals("init")) {
		Method method = ReflectionUtils.findMethod(WebSecurityConfigurerAdapter.class, "getHttp");
		ReflectionUtils.makeAccessible(method);
		HttpSecurity http = (HttpSecurity) ReflectionUtils.invokeMethod(method, invocation.getThis());
		this.configurer.configure(http);
	}
	return invocation.proceed();
}
 
Example #6
Source File: OAuth2SsoCustomConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	if (this.configType.isAssignableFrom(bean.getClass()) && bean instanceof WebSecurityConfigurerAdapter) {
		ProxyFactory factory = new ProxyFactory();
		factory.setTarget(bean);
		factory.addAdvice(new SsoSecurityAdapter(this.applicationContext));
		bean = factory.getProxy();
	}
	return bean;
}
 
Example #7
Source File: AuthSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfig() {
      return new WebSecurityConfigurerAdapter() {
          @Override
          protected void configure(AuthenticationManagerBuilder builder) throws Exception {
              builder.inMemoryAuthentication()
                     .passwordEncoder(passwordEncoder)
                     .withUser("caterpillar")
                      .password(passwordEncoder.encode("12345678"))
                      .roles("MEMBER");
          }
      };
}
 
Example #8
Source File: AuthSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfig() {
      return new WebSecurityConfigurerAdapter() {
          @Override
          protected void configure(AuthenticationManagerBuilder builder) throws Exception {
              builder.inMemoryAuthentication()
                     .passwordEncoder(passwordEncoder)
                     .withUser("caterpillar")
                      .password(passwordEncoder.encode("12345678"))
                      .roles("MEMBER");
          }
      };
}
 
Example #9
Source File: AuthSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfig() {
      return new WebSecurityConfigurerAdapter() {
          @Override
          protected void configure(AuthenticationManagerBuilder builder) throws Exception {
              builder.inMemoryAuthentication()
                     .passwordEncoder(passwordEncoder)
                     .withUser("caterpillar")
                      .password(passwordEncoder.encode("12345678"))
                      .roles("MEMBER");
          }
      };
}
 
Example #10
Source File: AuthSvrApplication.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfig() {
      return new WebSecurityConfigurerAdapter() {
          @Override
          protected void configure(AuthenticationManagerBuilder builder) throws Exception {
              builder.inMemoryAuthentication()
                     .passwordEncoder(passwordEncoder)
                     .withUser("caterpillar")
                      .password(passwordEncoder.encode("12345678"))
                      .roles("MEMBER");
          }
      };
}
 
Example #11
Source File: MultiFrameIntegrationTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
  return new RoadWebSecurityConfigurerAdapter() {
    @SuppressWarnings("deprecation")
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.inMemoryAuthentication().withUser(
          User.withDefaultPasswordEncoder().username("user").password("pass").authorities("ROLE_USER"));
    }
  };
}
 
Example #12
Source File: OfframpIntegrationTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
  return new RoadWebSecurityConfigurerAdapter() {
    @SuppressWarnings("deprecation")
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.inMemoryAuthentication().withUser(
          User.withDefaultPasswordEncoder().username("user").password("pass").authorities("ROLE_USER"));
    }
  };
}
 
Example #13
Source File: RoadEndpointsIntegrationTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
  return new RoadWebSecurityConfigurerAdapter() {
    @SuppressWarnings("deprecation")
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.inMemoryAuthentication().withUser(
          User.withDefaultPasswordEncoder().username("user").password("pass").authorities("ROLE_USER"));
    }
  };
}
 
Example #14
Source File: TestDriveApp.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
  return new RoadWebSecurityConfigurerAdapter() {
    @SuppressWarnings("deprecation")
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.inMemoryAuthentication().withUser(
          User.withDefaultPasswordEncoder().username("user").password("pass").authorities("ROLE_USER"));
    }
  };
}
 
Example #15
Source File: OfframpConsoleIntegrationTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
  return new RoadWebSecurityConfigurerAdapter() {
    @SuppressWarnings("deprecation")
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.inMemoryAuthentication().withUser(
          User.withDefaultPasswordEncoder().username("user").password("pass").authorities("ROLE_USER"));
    }
  };
}
 
Example #16
Source File: RestConfig.java    From mirrorgate with Apache License 2.0 4 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter secureConfigurer() {
    return new WebSecurityConfigurerAdapterImpl();
}
 
Example #17
Source File: Application.java    From secure-rest-spring-tut with MIT License 4 votes vote down vote up
@Bean
public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
	return new ApplicationSecurity();
}
 
Example #18
Source File: ServletContainerConfiguration.java    From haven-platform with Apache License 2.0 2 votes vote down vote up
/**
 * Disable csrf
 * Allows anonymous request
 *
 * @return
 */
@Bean
@Autowired
WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
    return new WebSecurityConfigurerAdapterImpl();
}