Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SpringBootApplication
- @EnableEurekaClient
- @EnableResourceServer
- @SessionAttributes("authorizationRequest")
- public class AuthApplication extends WebMvcConfigurerAdapter {
- public static void main(String[] args) {
- SpringApplication.run(AuthApplication.class, args);
- }
- @Override
- public void addViewControllers(ViewControllerRegistry registry) {
- registry.addViewController("/login")
- .setViewName("forward:/index.html");
- registry.addViewController("/oauth/confirm_access")
- .setViewName("authorize");
- }
- @Configuration
- @Order(-20)
- protected static class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- private AuthenticationManager authenticationManager;
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .formLogin().loginPage("/login").permitAll()
- .and().authorizeRequests()
- .anyRequest().authenticated();
- }
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.parentAuthenticationManager(authenticationManager);
- }
- }
- @Configuration
- @EnableAuthorizationServer
- protected static class OAuth2AuthorizationConfig extends
- AuthorizationServerConfigurerAdapter {
- @Autowired
- private AuthenticationManager authenticationManager;
- @Bean
- public JwtAccessTokenConverter jwtAccessTokenConverter() {
- JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
- KeyPair keyPair = new KeyStoreKeyFactory(
- new ClassPathResource("keystore.jks"),
- "foobar".toCharArray())
- .getKeyPair("test");
- converter.setKeyPair(keyPair);
- return converter;
- }
- @Override
- public void configure(ClientDetailsServiceConfigurer clients) throws
- Exception {
- clients.inMemory()
- .withClient("acme")
- .secret("acmesecret")
- .authorizedGrantTypes("authorization_code", "refresh_token",
- "password").scopes("openid").autoApprove(true);
- }
- @Override
- public void configure(AuthorizationServerEndpointsConfigurer endpoints)
- throws Exception {
- endpoints.authenticationManager(authenticationManager)
- .accessTokenConverter(
- jwtAccessTokenConverter());
- }
- @Override
- public void configure(AuthorizationServerSecurityConfigurer oauthServer)
- throws Exception {
- oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess(
- "isAuthenticated()");
- }
- }
- }
- <body>
- <div class="container">
- <form role="form" action="login" method="post">
- <div class="form-group">
- <label for="username">Username:</label>
- <input type="text" class="form-control" id="username"
- name="username"/>
- </div>
- <div class="form-group">
- <label for="password">Password:</label>
- <input type="password" class="form-control" id="password"
- name="password"/>
- </div>
- <input type="hidden" id="csrf_token" name="${_csrf.parameterName}"
- value="${_csrf.token}"/>
- <button type="submit" class="btn btn-primary">Submit</button>
- </form>
- </div>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement