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
@Configuration | |
@EnableWebSecurity | |
public class SecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.authorizeRequests(authorizeRequests -> | |
authorizeRequests | |
.antMatchers(HttpMethod.GET, "/hello").hasAuthority("SCOPE_hello") | |
.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
@RestController | |
public class HelloController { | |
@GetMapping("/hello") | |
public ResponseEntity<String> hello() { | |
return ResponseEntity.ok().body("hello"); | |
} | |
} |
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
## spring security resource server configuration | |
spring: | |
security: | |
oauth2: | |
resourceserver: | |
jwt: | |
issuer-uri: ${KEYCLOAK_ISSUER_URI:http://localhost:18080/auth/realms/hello} | |
jwk-set-uri: ${KEYCLOAK_JWKS_URI:http://localhost:18080/auth/realms/hello/protocol/openid-connect/certs} |
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
version: '3' | |
services: | |
postgres: | |
image: 'postgres:alpine' | |
volumes: | |
- postgres-volume:/var/lib/postgresql/data | |
ports: | |
- 5432:5432 | |
environment: |
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
@AllArgsConstructor | |
public class MonthlyExpensesRule implements Rule { | |
private Rule nextRule; | |
@Override | |
public boolean validate(Client client) { | |
BigDecimal expensesAmount = client.getExpenses().stream().filter(this::validatePeriod) | |
.map(Expense::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
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
@AllArgsConstructor | |
public class TimeAsClientRule implements Rule { | |
@Override | |
public boolean validate(Client client) { | |
return client.getClientSince().plusYears(CashbackParams.TIME_AS_CLIENT) | |
.isBefore(LocalDateTime.now()); | |
} | |
} |
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
@AllArgsConstructor | |
public class SegmentRule implements Rule { | |
private Rule nextRule; | |
@Override | |
public boolean validate(Client client) { | |
if (client.getSegment().equals(CashbackParams.SEGMENT)) { | |
return nextRule.validate(client); | |
} |
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
public interface Rule { | |
void validate(Client client); | |
} |