Now using Auth and Resource servers from Baeldung/spring-security-oauth (#6128)

This commit is contained in:
Ger Roza
2019-01-12 18:57:19 -02:00
committed by maibin
parent 469e36f07a
commit b395dc1d41
21 changed files with 48 additions and 174 deletions

View File

@@ -1,17 +0,0 @@
package com.baeldung.webclient.authorizationserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
@EnableAuthorizationServer
@PropertySource("classpath:webclient-authorization-application.properties")
@SpringBootApplication
public class AuthorizationServerApplication {
public static void main(String[] args) {
SpringApplication.run(AuthorizationServerApplication.class, args);
}
}

View File

@@ -1,26 +0,0 @@
package com.baeldung.webclient.authorizationserver.configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login", "/user")
.permitAll()
.and()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.and()
.httpBasic();
}
}

View File

@@ -1,17 +0,0 @@
package com.baeldung.webclient.resourceserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@EnableResourceServer
@PropertySource("webclient-resources-application.properties")
@SpringBootApplication
public class ResourceServerApplication {
public static void main(String[] args) {
SpringApplication.run(ResourceServerApplication.class, args);
}
}

View File

@@ -1,29 +0,0 @@
package com.baeldung.webclient.resourceserver.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
@Configuration
public class AuthorizationConfigs {
@Value("${oauth.authserver.client-id}")
String clientId;
@Value("${oauth.authserver.client-secret}")
String clientSecret;
@Value("${oauth.authserver.check-token-endpoint}")
String checkTokenEndpoint;
@Bean
public ResourceServerTokenServices tokenSvc() {
RemoteTokenServices remoteService = new RemoteTokenServices();
remoteService.setCheckTokenEndpointUrl(checkTokenEndpoint);
remoteService.setClientId(clientId);
remoteService.setClientSecret(clientSecret);
return remoteService;
}
}

View File

@@ -1,23 +0,0 @@
package com.baeldung.webclient.resourceserver.web;
import java.security.Principal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ResourceRestController {
@GetMapping("/retrieve-resource")
public String retrieveResource() {
return "This is the resource!";
}
@GetMapping("/user")
@ResponseBody
public Principal user(Principal user) {
return user;
}
}

View File

@@ -1,13 +0,0 @@
server.port=8085
security.oauth2.client.client-id=bael-client-id
security.oauth2.client.client-secret=bael-secret
security.oauth2.client.scope=read,write
security.oauth2.authorization.check-token-access=isAuthenticated()
spring.security.user.name=bael-user
spring.security.user.password=bael-password
security.oauth2.client.registered-redirect-uri=http://localhost:8080/login/oauth2/code/bael, http://localhost:8080/authorize/oauth2/code/bael
security.oauth2.client.use-current-uri=false

View File

@@ -1,6 +0,0 @@
server.port=8084
#spring.security.oauth2.resourceserver.jwt.issuer-uri=localhost:8085
oauth.authserver.client-id=bael-client-id
oauth.authserver.client-secret=bael-secret
oauth.authserver.check-token-endpoint=http://localhost:8085/oauth/check_token