Skip to content

Commit

Permalink
Fix the settings of roles_seperator (#1618)
Browse files Browse the repository at this point in the history
* Fix the settings of roles_seperator

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied authored Feb 16, 2022
1 parent f916e04 commit 5b994af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class AuthTokenProcessorHandler {

this.samlRolesKey = settings.get("roles_key");
this.samlSubjectKey = settings.get("subject_key");
String samlRolesSeparator = settings.get("roles_seperator");
// Originally release with a typo, prioritize correct spelling over typo'ed version
String samlRolesSeparator = settings.get("roles_separator", settings.get("roles_seperator"));
this.kibanaRootUrl = settings.get("kibana_url");
if (samlRolesSeparator != null) {
this.samlRolesSeparatorPattern = Pattern.compile(samlRolesSeparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,20 +567,30 @@ public void idpEndpointWithQueryStringTest() throws Exception {
Assert.assertEquals("horst", jwt.getClaim("sub"));
}

@SuppressWarnings("unchecked")
@Test
public void commaSeparatedRolesTest() throws Exception {
final Settings.Builder settingsBuilder = Settings.builder().put("roles_seperator", ";").put("roles_separator", ",");
commaSeparatedRoles("a,b", settingsBuilder);
}

@Test
public void legacyCommaSeparatedRolesTest() throws Exception {
final Settings.Builder settingsBuilder = Settings.builder().put("roles_seperator", ";");
commaSeparatedRoles("a;b", settingsBuilder);
}

@SuppressWarnings("unchecked")
private void commaSeparatedRoles(final String rolesAsString, final Settings.Builder settingsBuilder) throws Exception {
mockSamlIdpServer.setAuthenticateUser("horst");
mockSamlIdpServer.setSignResponses(true);
mockSamlIdpServer.loadSigningKeys("saml/kirk-keystore.jks", "kirk");
mockSamlIdpServer.setAuthenticateUserRoles(Arrays.asList("a,b"));
mockSamlIdpServer.setAuthenticateUserRoles(Arrays.asList(rolesAsString));
mockSamlIdpServer.setEndpointQueryString(null);

Settings settings = Settings.builder().put(IDP_METADATA_URL, mockSamlIdpServer.getMetadataUri())
Settings settings = settingsBuilder.put(IDP_METADATA_URL, mockSamlIdpServer.getMetadataUri())
.put("kibana_url", "http://wherever").put("idp.entity_id", mockSamlIdpServer.getIdpEntityId())
.put("exchange_key", "abc").put("roles_key", "roles").put("roles_seperator", ",").put("path.home", ".")
.put("exchange_key", "abc").put("roles_key", "roles").put("path.home", ".")
.build();

HTTPSamlAuthenticator samlAuthenticator = new HTTPSamlAuthenticator(settings, null);

AuthenticateHeaders authenticateHeaders = getAutenticateHeaders(samlAuthenticator);
Expand Down

0 comments on commit 5b994af

Please sign in to comment.