Commit 4834a615 authored by gkhan's avatar gkhan

security code added

parent 43153221
...@@ -36,6 +36,9 @@ dependencies { ...@@ -36,6 +36,9 @@ dependencies {
compileOnly group: 'org.json', name: 'json', version: '20180813' compileOnly group: 'org.json', name: 'json', version: '20180813'
implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'de.codecentric:spring-boot-admin-starter-client' implementation 'de.codecentric:spring-boot-admin-starter-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
compileOnly 'org.springframework.boot:spring-boot-starter-tomcat'
} }
dependencyManagement { dependencyManagement {
......
package com.safeway.pricing.safeway.config;
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;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure( HttpSecurity http ) throws Exception {
http.authorizeRequests()
.antMatchers( "/oauth2/**", "/login/**" ).permitAll()
.anyRequest().authenticated()
.and()
.oauth2Login()
.defaultSuccessUrl( "/group1" );
}
}
...@@ -12,6 +12,8 @@ import com.safeway.pricing.safeway.service.PricingService; ...@@ -12,6 +12,8 @@ import com.safeway.pricing.safeway.service.PricingService;
import com.safeway.pricing.safeway.util.AppUtil; import com.safeway.pricing.safeway.util.AppUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
...@@ -67,6 +69,13 @@ public class PricingController { ...@@ -67,6 +69,13 @@ public class PricingController {
public Flux<SaleDetailsDTO> allSaleDetails() { public Flux<SaleDetailsDTO> allSaleDetails() {
return this.pricingService.getSalesDetails(); return this.pricingService.getSalesDetails();
} }
@GetMapping("/group1")
@PreAuthorize("hasRole('ROLE_group1')")
public String getDetails(@AuthenticationPrincipal(expression = "claims['name']") String name) {
return "Hellow User "+name;
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#Springboot Application #Springboot Application
spring.application.name=spring-boot-management spring.application.name=spring-boot-management
spring.main.allow-bean-definition-overriding=true
server.port=8789 server.port=8789
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
client.host=http://localhost:8789 client.host=http://localhost:8789
......
spring:
security:
oauth2:
client:
provider:
azure-ad:
authorization-uri: https://login.microsoftonline.com/common/oauth2/v2.0/authorize
token-uri: https://login.microsoftonline.com/common/oauth2/v2.0/token
jwk-set-uri: https://login.microsoftonline.com/common/discovery/v2.0/keys
registration:
azure-client:
provider: azure-ad
client-id: f4507396-c51a-4348-bb9f-9bcf56795357
client-secret: Q-Y8Q~K~Ocg-K-gxR9AjX9dAXYkEIH7BnQYuRcNs
authorization-grant-type: authorization_code
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
scope: openid,profile
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment