Skip to content

Commit

Permalink
feat: adds preauth external provider header
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Jun 24, 2024
1 parent acc22ce commit bcee8dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class PreauthAuthenticationManager implements ReactiveAuthenticationManag
public static final String PREAUTH_LASTNAME = "preauth-lastname";
public static final String PREAUTH_ORG = "preauth-org";
public static final String PREAUTH_ROLES = "preauth-roles";
public static final String PREAUTH_PROVIDER = "preauth-provider";
public static final String PREAUTH_PROVIDER_ID = "preauth-provider-id";

/**
* @return {@code Mono.empty()} if the pre-auth request headers are not
Expand Down Expand Up @@ -93,6 +95,9 @@ public static GeorchestraUser map(Map<String, String> requestHeaders) {
String lastName = SecurityHeaders.decode(requestHeaders.get(PREAUTH_LASTNAME));
String org = SecurityHeaders.decode(requestHeaders.get(PREAUTH_ORG));
String rolesValue = SecurityHeaders.decode(requestHeaders.get(PREAUTH_ROLES));
String provider = SecurityHeaders.decode(requestHeaders.get(PREAUTH_PROVIDER));
String providerId = SecurityHeaders.decode(requestHeaders.get(PREAUTH_PROVIDER_ID));

List<String> roleNames = Optional.ofNullable(rolesValue)
.map(roles -> Stream
.concat(Stream.of("ROLE_USER"), Stream.of(roles.split(";")).filter(StringUtils::hasText))
Expand All @@ -106,6 +111,8 @@ public static GeorchestraUser map(Map<String, String> requestHeaders) {
user.setLastName(lastName);
user.setOrganization(org);
user.setRoles(roleNames);
user.setOAuth2Provider(provider);
user.setOAuth2Uid(providerId);
return user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public class CreateAccountUserCustomizerIT {
"preauth-email", "[email protected]", //
"preauth-firstname", "Pierre-Jean-Pierre", //
"preauth-lastname", "Martin", //
"preauth-org", "NEWORG");
"preauth-org", "NEWORG",
"preauth-provider", "georchestra",
"preauth-provider-id", "georchestra12"
);

private static final Map<String, String> ANOTHER_NOT_EXISTING_ACCOUNT_HEADERS_EXISTING_ORG = Map.of( //
"sec-georchestra-preauthenticated", "true", //
Expand Down Expand Up @@ -113,7 +116,9 @@ private WebTestClient.RequestHeadersUriSpec<?> prepareWebTestClientHeaders(
.is2xxSuccessful()//
.expectBody()//
.jsonPath("$.GeorchestraUser").isNotEmpty()//
.jsonPath("$.GeorchestraUser.organization").isEqualTo("NEWORG");
.jsonPath("$.GeorchestraUser.organization").isEqualTo("NEWORG")
.jsonPath("$.GeorchestraUser.oauth2Provider").isEqualTo("georchestra")
.jsonPath("$.GeorchestraUser.oauth2Uid").isEqualTo("georchestra12");

// Make sure the account has been created
assertNotNull(accountDao.findByUID("pmartin2"));
Expand Down

0 comments on commit bcee8dd

Please sign in to comment.