-
Notifications
You must be signed in to change notification settings - Fork 14
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 #629 from overture-stack/rc/5.1.0
5.1.0 use spring security oauth2 client replace OAuth2SsoFilter with OAuth2AuthorizationRequestResolver bean: - use oauth2 DSL in SecureServerConfig - add custom oauth2 and open id connect user info service - add oauth2 request resolver replace legacy spring oauth2 beans add docker compose to run ego stack locally update docker compose to update keycloak replace legacy oauth2 lib exceptions update tests with new changes
- Loading branch information
Showing
40 changed files
with
816 additions
and
963 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,45 @@ | ||
version: '3.7' | ||
services: | ||
ego-ui: | ||
image: overture/ego-ui:edge | ||
expose: | ||
- "8080" | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
REACT_APP_API: http://localhost:8081 | ||
REACT_APP_EGO_CLIENT_ID: ego-ui | ||
api: | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
restart: always | ||
# change the image tag to the target image as needed | ||
image: overture/ego:4c1969bf | ||
environment: | ||
SERVER_PORT: 8080 | ||
SERVER_PORT: 8081 | ||
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ego?stringtype=unspecified | ||
SPRING_DATASOURCE_USERNAME: postgres | ||
SPRING_DATASOURCE_PASSWORD: password | ||
SPRING_FLYWAY_ENABLED: "true" | ||
SPRING_FLYWAY_LOCATIONS: "classpath:flyway/sql,classpath:db/migration" | ||
SPRING_PROFILES: demo, auth | ||
SPRING_PROFILES_ACTIVE: auth | ||
google.client.clientId: $EGO_GOOGLE_CLIENT_ID | ||
google.client.clientSecret: $EGO_GOOGLE_SECRET | ||
default.user.firstUserAsAdmin: "true" | ||
logging.level.root: INFO | ||
expose: | ||
- "8080" | ||
- "8081" | ||
ports: | ||
- "$API_HOST_PORT:8080" | ||
- "8081:8081" | ||
depends_on: | ||
- postgres | ||
postgres: | ||
image: postgres:12.6 | ||
restart: always | ||
environment: | ||
- POSTGRES_DB=ego | ||
- POSTGRES_PASSWORD=password | ||
expose: | ||
- "5432" | ||
ports: | ||
- "8432:5432" | ||
- "5432:5432" | ||
volumes: | ||
- "ego_data:/var/lib/postgresql/data" | ||
volumes: | ||
ego_data: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
start: | ||
docker-compose -f docker-compose-all.yml up -d | ||
sleep 10; | ||
make init-db | ||
|
||
up: | ||
docker-compose -f docker-compose-all.yml up -d | ||
|
||
down: | ||
docker-compose -f docker-compose-all.yml down | ||
|
||
nuke: | ||
docker-compose -f docker-compose-all.yml down --volumes | ||
|
||
# needed to insert the ego ui client in ego db | ||
init-db: | ||
docker exec ego_postgres_1 psql -h localhost -p 5432 -U postgres -d ego --command "INSERT INTO EGOAPPLICATION (name, clientId, clientSecret, redirectUri, description, status, errorredirecturi) VALUES ('ego ui', 'ego-ui', 'secret', 'http://localhost:8080/', '...', 'APPROVED', 'http://localhost:8080/error') on conflict do nothing" |
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
73 changes: 73 additions & 0 deletions
73
src/main/java/bio/overture/ego/config/OAuth2AccessTokenResponseConverterWithDefaults.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,73 @@ | ||
package bio.overture.ego.config; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.security.oauth2.core.OAuth2AccessToken; | ||
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse; | ||
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.StringUtils; | ||
|
||
// needed for linked in since it doesn't return tokenType in the access token response violating | ||
// oauth2 spec. | ||
// https://github.com/spring-projects/spring-security/issues/5983 | ||
public class OAuth2AccessTokenResponseConverterWithDefaults | ||
implements Converter<Map<String, String>, OAuth2AccessTokenResponse> { | ||
private static final Set<String> TOKEN_RESPONSE_PARAMETER_NAMES = | ||
Stream.of( | ||
OAuth2ParameterNames.ACCESS_TOKEN, | ||
OAuth2ParameterNames.TOKEN_TYPE, | ||
OAuth2ParameterNames.EXPIRES_IN, | ||
OAuth2ParameterNames.REFRESH_TOKEN, | ||
OAuth2ParameterNames.SCOPE) | ||
.collect(Collectors.toSet()); | ||
|
||
private OAuth2AccessToken.TokenType defaultAccessTokenType = OAuth2AccessToken.TokenType.BEARER; | ||
|
||
@Override | ||
public OAuth2AccessTokenResponse convert(Map<String, String> tokenResponseParameters) { | ||
String accessToken = tokenResponseParameters.get(OAuth2ParameterNames.ACCESS_TOKEN); | ||
|
||
OAuth2AccessToken.TokenType accessTokenType = this.defaultAccessTokenType; | ||
if (OAuth2AccessToken.TokenType.BEARER | ||
.getValue() | ||
.equalsIgnoreCase(tokenResponseParameters.get(OAuth2ParameterNames.TOKEN_TYPE))) { | ||
accessTokenType = OAuth2AccessToken.TokenType.BEARER; | ||
} | ||
|
||
long expiresIn = 0; | ||
if (tokenResponseParameters.containsKey(OAuth2ParameterNames.EXPIRES_IN)) { | ||
try { | ||
expiresIn = Long.parseLong(tokenResponseParameters.get(OAuth2ParameterNames.EXPIRES_IN)); | ||
} catch (NumberFormatException ignored) { | ||
} | ||
} | ||
|
||
Set<String> scopes = Collections.emptySet(); | ||
if (tokenResponseParameters.containsKey(OAuth2ParameterNames.SCOPE)) { | ||
String scope = tokenResponseParameters.get(OAuth2ParameterNames.SCOPE); | ||
scopes = | ||
Arrays.stream(StringUtils.delimitedListToStringArray(scope, " ")) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
Map<String, Object> additionalParameters = new LinkedHashMap<>(); | ||
tokenResponseParameters.entrySet().stream() | ||
.filter(e -> !TOKEN_RESPONSE_PARAMETER_NAMES.contains(e.getKey())) | ||
.forEach(e -> additionalParameters.put(e.getKey(), e.getValue())); | ||
|
||
return OAuth2AccessTokenResponse.withToken(accessToken) | ||
.tokenType(accessTokenType) | ||
.expiresIn(expiresIn) | ||
.scopes(scopes) | ||
.additionalParameters(additionalParameters) | ||
.build(); | ||
} | ||
|
||
public final void setDefaultAccessTokenType(OAuth2AccessToken.TokenType defaultAccessTokenType) { | ||
Assert.notNull(defaultAccessTokenType, "defaultAccessTokenType cannot be null"); | ||
this.defaultAccessTokenType = defaultAccessTokenType; | ||
} | ||
} |
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.