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

Changed condition to display Login Form #736

Merged
merged 2 commits into from
Jun 15, 2021
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
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());
}
}
3 changes: 3 additions & 0 deletions src/test/resources/application-oidc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ micronaut:
secret:
generator:
secret: d93YX6S7bukwTrmDLakBBWA3taHUkL4qkBqX2NYRJv5UQAjwCU4Kuey3mTTSgXAL
ldap:
enabled: false
oauth2:
enabled: true
clients:
Expand Down Expand Up @@ -62,6 +64,7 @@ akhq:

security:
default-group: no-filter
basic-auth: []
groups:
admin:
name: admin
Expand Down