All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.optionfactory.spring.authentication.bearer.token.package-info Maven / Gradle / Ivy

There is a newer version: 21.2
Show newest version
/**
 * Configuration classes needed to setup a static Bearer token authentication mechanism.
 * Such components can be configured following the example below:
 * 

*

 * {@literal @}Configuration
 * {@literal @}EnableWebSecurity
 * public class SecurityConfig extends WebSecurityConfigurerAdapter {
 *
 *     {@literal @}Autowired
 *     private StaticBearerTokenAuthenticationProvider staticBearerTokenAuthenticationProvider;
 *
 *     {@literal @}Bean
 *     public StaticBearerTokenAuthenticationProvider staticBearerTokenAuthenticationProvider({@literal @}Value("${api.access.token}") String accessToken) {
 *         return new StaticBearerTokenAuthenticationProvider(accessToken, Collections.singleton(new SimpleGrantedAuthority("ROLE_USER")));
 *     }
 *
 *     {@literal @}Override
 *     protected void configure(HttpSecurity http) throws Exception {
 *         http
 *             .csrf().disable()
 *             .exceptionHandling().authenticationEntryPoint(new UnauthorizedStatusAuthenticationEntryPoint()).and()
 *             .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
 *         http
 *             .authenticationProvider(staticBearerTokenAuthenticationProvider)
 *             .authorizeRequests()
 *             .antMatchers("/api/**").hasRole("USER")
 *             .anyRequest().fullyAuthenticated();
 *         http
 *             .apply(new BearerTokenAuthenticationFilterConfigurer());
 *     }
 * }
 * 
*/ package net.optionfactory.spring.authentication.bearer.token;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy