Skip to content

Commit

Permalink
fix(auth): use micronaut only for detect if ldap is enabled (#735)
Browse files Browse the repository at this point in the history
changed condition to display Login Form to be visible when LDAP is enabled within Micronaut instead of "LDAP to Akhq mapping" class 
Co-authored-by: Julien Chanaud <[email protected]>
  • Loading branch information
twobeeb authored Jun 14, 2021
1 parent 717ba81 commit 0a02ee4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/main/java/org/akhq/configs/Ldap.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ public class Ldap {
private String defaultGroup;
private List<GroupMapping> groups = new ArrayList<>();
private List<UserMapping> users = new ArrayList<>();

public boolean isEnabled() {
return StringUtils.hasText(defaultGroup) || !getGroups().isEmpty() || !getUsers().isEmpty();
}
}
8 changes: 4 additions & 4 deletions src/main/java/org/akhq/controllers/AkhqController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.akhq.controllers;

import io.micronaut.configuration.security.ldap.configuration.LdapConfiguration;
import io.micronaut.context.ApplicationContext;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.http.HttpResponse;
Expand Down Expand Up @@ -31,9 +32,6 @@ public class AkhqController extends AbstractController {
@Inject
private ApplicationContext applicationContext;

@Inject
private Ldap ldap;

@Inject
private SecurityProperties securityProperties;

Expand Down Expand Up @@ -69,7 +67,9 @@ public AuthDefinition auths() {

if (applicationContext.containsBean(SecurityService.class)) {
authDefinition.loginEnabled = true;
authDefinition.formEnabled = securityProperties.getBasicAuth().size() > 0 || ldap.isEnabled();
// Display login form if there are LocalUsers OR Ldap is enabled
authDefinition.formEnabled = securityProperties.getBasicAuth().size() > 0 ||
applicationContext.containsBean(LdapConfiguration.class);
}

if (oidc.isEnabled()) {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/akhq/controllers/AkhqControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void auth() {
);

assertTrue(result.isLoginEnabled());
assertTrue(result.isFormEnabled());
}

@Test
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/akhq/modules/OidcAuthenticationProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import io.reactivex.Flowable;
import lombok.extern.slf4j.Slf4j;
import org.akhq.controllers.AkhqController;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
Expand Down Expand Up @@ -46,6 +47,9 @@ public class OidcAuthenticationProviderTest {
@Inject
DefaultOpenIdProviderMetadata defaultOpenIdProviderMetadata;

@Inject
AkhqController akhqController;

@Named("oidc")
@MockBean(TokenEndpointClient.class)
TokenEndpointClient tokenEndpointClient() {
Expand Down Expand Up @@ -230,4 +234,13 @@ public void failure() {
assertThat(authenticationException.getResponse(), instanceOf(AuthenticationFailed.class));
assertFalse(authenticationException.getResponse().isAuthenticated());
}

@Test
void noLoginForm(){
AkhqController.AuthDefinition actual = akhqController.auths();

assertTrue(actual.isLoginEnabled(), "Login must be enabled with OIDC");
assertFalse(actual.isFormEnabled(), "Login Form must not be active if only OIDC is enabled");
assertFalse(actual.getOidcAuths().isEmpty());
}
}

0 comments on commit 0a02ee4

Please sign in to comment.