forked from usdot-jpo-ode/jpo-cvmanager
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests, fix handling of security.enabled flag, clean up and organi…
…ze new classes
- Loading branch information
Showing
16 changed files
with
261 additions
and
254 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
207 changes: 0 additions & 207 deletions
207
jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/keycloak/KeycloakConfig.java
This file was deleted.
Oops, something went wrong.
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
45 changes: 45 additions & 0 deletions
45
...ualizer-api/src/main/java/us/dot/its/jpo/ode/api/keycloak/config/KeycloakAdminConfig.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,45 @@ | ||
package us.dot.its.jpo.ode.api.keycloak.config; | ||
|
||
import org.keycloak.admin.client.Keycloak; | ||
import org.keycloak.admin.client.KeycloakBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class KeycloakAdminConfig { | ||
|
||
@Value("${security.enabled:true}") | ||
private boolean securityEnabled; | ||
|
||
@Value("${keycloak.realm}") | ||
private String realm; | ||
|
||
@Value("${keycloak.resource}") | ||
private String resource; | ||
|
||
@Value("${keycloak.auth-server-url}") | ||
private String authServer; | ||
|
||
@Value("${keycloak_username}") | ||
private String username; | ||
|
||
@Value("${keycloak_password}") | ||
private String password; | ||
|
||
// Keycloak admin client used for email | ||
@Bean | ||
public Keycloak keyCloakBuilder() { | ||
System.out.println("Auth Server: " + authServer); | ||
System.out.println("Realm: " + realm); | ||
System.out.println("Resource: " + resource); | ||
return KeycloakBuilder.builder() | ||
.serverUrl(authServer) | ||
.grantType("password") | ||
.realm("master") | ||
.clientId("admin-cli") | ||
.username(username) | ||
.password(password) | ||
.build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...er-api/src/main/java/us/dot/its/jpo/ode/api/keycloak/config/KeycloakNoSecurityConfig.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,48 @@ | ||
package us.dot.its.jpo.ode.api.keycloak.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
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.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties; | ||
import us.dot.its.jpo.ode.api.keycloak.support.CorsUtil; | ||
|
||
import static org.springframework.security.config.Customizer.withDefaults; | ||
|
||
/** | ||
* Alternative keycloack configuration for when security is disabled | ||
*/ | ||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
@ConditionalOnProperty(prefix = "security", | ||
name = "enabled", | ||
havingValue = "false") // Allow disabling security | ||
public class KeycloakNoSecurityConfig { | ||
|
||
final ConflictMonitorApiProperties properties; | ||
|
||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { | ||
|
||
System.out.println("Running without KeyCloak Authentication"); | ||
return httpSecurity | ||
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
.cors(corsConfigurer -> CorsUtil.configureCors(corsConfigurer, properties)) | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests( | ||
request -> request.anyRequest().permitAll() | ||
) | ||
.anonymous(withDefaults()) | ||
.build(); | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.