net.optionfactory.spring.authentication.bearer.token.package-info Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of authentication-bearer-token Show documentation
Show all versions of authentication-bearer-token Show documentation
optionfactory-spring authentication-bearer-token
/**
* 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