Skip to content

Commit

Permalink
Adapt to route authn to keycloak
Browse files Browse the repository at this point in the history
  • Loading branch information
flawmop committed Jan 17, 2024
1 parent bae3014 commit eb7470a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public class SecurityConfig {

@Bean
SecurityWebFilterChain securityFilterChain(ServerHttpSecurity http) {
return http.authorizeExchange(exchange -> exchange.anyExchange().authenticated())
return http.authorizeExchange(exchange -> exchange.pathMatchers("/", "/css/*", "/js/*", "/icon/*", "/img/*", "/auth/*").permitAll()
.anyExchange().authenticated())
.oauth2Login(Customizer.withDefaults())
.build();
}

}
}
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ spring:
uri: ${ROUTE_DEFAULT:http://localhost:9001}/
predicates:
- Path=/
- id: auth-route
uri: ${KEYCLOAK_ISSUER_URI:http://localhost:8080/realms/Portal}/
predicates:
- Path=/auth/
security:
oauth2:
client:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.insilicosoft.portal.edgesvr.config;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
import org.springframework.test.web.reactive.server.WebTestClient;

@WebFluxTest
@Import(SecurityConfig.class)
class SecurityConfigTests {

@Autowired
WebTestClient webClient;

@MockBean
ReactiveClientRegistrationRepository mockReactiveClientRegistrationRepository;

@Test
void whenNotLoggedInAndAccessingUnsecuredButUnavailableThen404() {
webClient.get().uri("/favicon.ico").exchange().expectStatus().isNotFound();
}

@Test
void whenNotLoggedInAndAccessingNonPermitAllThen302() {
webClient.get().uri("/nonPermitAll.html").exchange().expectStatus().isFound();
}

}

0 comments on commit eb7470a

Please sign in to comment.