-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Dovchiproeng/feature/update-spring
Feature/update spring
- Loading branch information
Showing
50 changed files
with
450 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 2 additions & 51 deletions
53
account-service/src/main/java/com/piggymetrics/account/AccountApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,21 @@ | ||
package com.piggymetrics.account; | ||
|
||
import com.piggymetrics.account.service.security.CustomUserInfoTokenServices; | ||
import feign.RequestInterceptor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.feign.EnableFeignClients; | ||
import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; | ||
import org.springframework.security.oauth2.client.OAuth2RestTemplate; | ||
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; | ||
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; | ||
|
||
@SpringBootApplication | ||
@EnableResourceServer | ||
@EnableDiscoveryClient | ||
@EnableOAuth2Client | ||
@EnableFeignClients | ||
@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
@EnableConfigurationProperties | ||
@Configuration | ||
public class AccountApplication extends ResourceServerConfigurerAdapter { | ||
|
||
@Autowired | ||
private ResourceServerProperties sso; | ||
public class AccountApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AccountApplication.class, args); | ||
} | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "security.oauth2.client") | ||
public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { | ||
return new ClientCredentialsResourceDetails(); | ||
} | ||
|
||
@Bean | ||
public RequestInterceptor oauth2FeignRequestInterceptor(){ | ||
return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); | ||
} | ||
|
||
@Bean | ||
public OAuth2RestTemplate clientCredentialsRestTemplate() { | ||
return new OAuth2RestTemplate(clientCredentialsResourceDetails()); | ||
} | ||
|
||
@Bean | ||
public ResourceServerTokenServices tokenServices() { | ||
return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); | ||
} | ||
|
||
@Override | ||
public void configure(HttpSecurity http) throws Exception { | ||
http.authorizeRequests() | ||
.antMatchers("/" , "/demo").permitAll() | ||
.anyRequest().authenticated(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
account-service/src/main/java/com/piggymetrics/account/config/ResourceServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.piggymetrics.account.config; | ||
|
||
import com.piggymetrics.account.service.security.CustomUserInfoTokenServices; | ||
import feign.RequestInterceptor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; | ||
import org.springframework.security.oauth2.client.OAuth2RestTemplate; | ||
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; | ||
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; | ||
|
||
/** | ||
* @author cdov | ||
*/ | ||
@Configuration | ||
@EnableResourceServer | ||
public class ResourceServerConfig extends ResourceServerConfigurerAdapter { | ||
|
||
private final ResourceServerProperties sso; | ||
|
||
@Autowired | ||
public ResourceServerConfig(ResourceServerProperties sso) { | ||
this.sso = sso; | ||
} | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "security.oauth2.client") | ||
public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { | ||
return new ClientCredentialsResourceDetails(); | ||
} | ||
|
||
@Bean | ||
public RequestInterceptor oauth2FeignRequestInterceptor(){ | ||
return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); | ||
} | ||
|
||
@Bean | ||
public OAuth2RestTemplate clientCredentialsRestTemplate() { | ||
return new OAuth2RestTemplate(clientCredentialsResourceDetails()); | ||
} | ||
|
||
@Bean | ||
public ResourceServerTokenServices tokenServices() { | ||
return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); | ||
} | ||
|
||
@Override | ||
public void configure(HttpSecurity http) throws Exception { | ||
http.authorizeRequests() | ||
.antMatchers("/" , "/demo").permitAll() | ||
.anyRequest().authenticated(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.