Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop/google optional organisation #170

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ public interface AdministrationService {
*/
OrganisationData readOrganisation(TenantIdentifier identifier);



Optional<OrganisationData> readOrganisationDoesNotThrow(TenantIdentifier identifier);

/**
* Updates an organisation. Fails if organisation does not exist.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ public OrganisationData readOrganisation(TenantIdentifier identifier) {
.findAny()
.orElseThrow(NoSuchOrganisation::new);
}
@Override
public Optional<OrganisationData> readOrganisationDoesNotThrow(TenantIdentifier identifier) {
IMap<String, OrganisationData> orgMap = hazelcastInstance.getMap(hazelcastConf.getPrefix() + ORG_POSTFIX);
return orgMap.values()
.stream()
.filter(entry -> identifier.matches(entry.getProviderConfiguration()))
.findAny();
}


@Override
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- MITID_AUTHORITY_URL=https://brokertest.signaturgruppen.dk/op
- KEYSTORE_PASS=fafnir
- KEY_PASS=fafnir
- GOOGLE_VERSION2_ENABLED=true
volumes:
- ./fafnir-storage:/var/lib/fafnir

Expand Down
25 changes: 13 additions & 12 deletions sso/src/main/java/dk/acto/fafnir/sso/provider/GoogleProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public String authenticate() {

@Override
public AuthenticationResult callback(TokenCredentials data) {
boolean version2Enabled = Boolean.parseBoolean(System.getenv("GOOGLE_VERSION2_ENABLED"));

var token = Try.of(() -> googleOauth.getAccessToken(data.getCode()))
.onFailure(x -> log.error("Authentication failed", x))
.getOrNull();
Expand All @@ -50,26 +52,25 @@ public AuthenticationResult callback(TokenCredentials data) {
.name(displayName)
.build();

var orgOptional = administrationService.readOrganisationDoesNotThrow(
test -> getMetaData().getProviderId().equals(test.getProviderId()) &&
(providerValue.equals(test.getValues().get("Organisation Domain")) || "true".equals(test.getValues().get("Catchall Organisation")))
);

if (orgOptional.isPresent()) {
var orgActual = orgOptional.get();
var claimsActual = ClaimData.empty();
var jwt = tokenFactory.generateToken(subjectActual, orgActual, claimsActual, getMetaData(), providerValue);
return AuthenticationResult.success(jwt);
} else {
if (version2Enabled) {
var fafnirUser = FafnirUser.builder()
.data(subjectActual)
.organisationId(providerValue)
.organisationName(displayName)
.provider("google")
.build();

var jwt = tokenFactory.generateToken(fafnirUser);
return AuthenticationResult.success(jwt);

} else {
var orgActual = administrationService.readOrganisation(
test -> getMetaData().getProviderId().equals(test.getProviderId()) &&
(providerValue.equals(test.getValues().get("Organisation Domain")) || "true".equals(test.getValues().get("Catchall Organisation")))
);
var claimsActual = ClaimData.empty();
var jwt = tokenFactory.generateToken(subjectActual, orgActual, claimsActual, getMetaData(), providerValue);

return AuthenticationResult.success(jwt);
}
}

Expand Down
Loading