Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

#951 Replace AuthMode.OFF by AuthMode.NONE #978

Closed
Closed
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 @@ -210,7 +210,7 @@ private static Status fromStatusCode(final int code) throws UnknownStatusCodeExc
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(final WebSecurity web) throws Exception {
if (settings.getAuthMode() == SecuritySettings.AuthMode.OFF) {
if (settings.getAuthMode().isNoAuthentication()) {
web.ignoring().anyRequest();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/zalando/nakadi/config/SecuritySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ public class SecuritySettings {

public enum AuthMode {
OFF, // no authentication at all
NONE, // same as OFF
BASIC, // only checks that the token is valid (has "uid" scope)
REALM, // checks that the token is valid and contains at least one required realm
FULL // full authentication and authorization using oauth2 scopes
;

public boolean isNoAuthentication() {
return AuthMode.OFF == this || AuthMode.NONE == this;
}
}

private final String tokenInfoUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.Map;
import java.util.Optional;

import static org.zalando.nakadi.config.SecuritySettings.AuthMode.OFF;

@Component
public class ClientResolver implements HandlerMethodArgumentResolver {

Expand Down Expand Up @@ -49,7 +47,7 @@ public Client resolveArgument(final MethodParameter parameter,
final String clientId = authorizationService.getSubject().map(Subject::getName)
.orElse(SecuritySettings.UNAUTHENTICATED_CLIENT_ID);

if(settings.getAuthMode() == OFF) {
if(settings.getAuthMode().isNoAuthentication()) {
return new FullAccessClient(clientId);
} else {
if (clientId.equals(settings.getAdminClientId())) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/zalando/nakadi/config/SecuritySettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.zalando.nakadi.config;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class SecuritySettingsTest {

@Test
public void doesNotRequireAuthentication() {
Assert.assertTrue(SecuritySettings.AuthMode.NONE.isNoAuthentication());
Assert.assertTrue(SecuritySettings.AuthMode.OFF.isNoAuthentication());
}

@Test
public void mustRequireAuthentication() {
final List<SecuritySettings.AuthMode> authModesWithoutAuthentication =
new LinkedList<>(Arrays.asList(SecuritySettings.AuthMode.values()));
authModesWithoutAuthentication.remove(SecuritySettings.AuthMode.NONE);
authModesWithoutAuthentication.remove(SecuritySettings.AuthMode.OFF);
authModesWithoutAuthentication.forEach(authMode ->
Assert.assertFalse(authMode.isNoAuthentication()));
}

}