Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save grandadmiralmcb/d6b628cd1d5fd813be753dc92e921f0d to your computer and use it in GitHub Desktop.
Save grandadmiralmcb/d6b628cd1d5fd813be753dc92e921f0d to your computer and use it in GitHub Desktop.
OAuth2 Resource Server Config Spring Boot Framework Boilerplate
package com.falconcis.gist;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OAuth2ResourceServerConfig
extends GlobalMethodSecurityConfiguration {
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
return new OAuth2MethodSecurityExpressionHandler();
}
@Bean
public TokenStore tokenStore(DataSource datasource) {
return new JdbcTokenStore(datasource);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// TODO Auto-generated method stub
super.configure(auth);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment