Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9830B200BAF for ; Mon, 17 Oct 2016 04:44:58 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 96A8E160AF8; Mon, 17 Oct 2016 02:44:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 622CF160AD0 for ; Mon, 17 Oct 2016 04:44:57 +0200 (CEST) Received: (qmail 89775 invoked by uid 500); 17 Oct 2016 02:44:56 -0000 Mailing-List: contact commits-help@eagle.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.incubator.apache.org Delivered-To: mailing list commits@eagle.incubator.apache.org Received: (qmail 89766 invoked by uid 99); 17 Oct 2016 02:44:56 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Oct 2016 02:44:56 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id C7348C14D7 for ; Mon, 17 Oct 2016 02:44:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id RoLEBzDAgNUm for ; Mon, 17 Oct 2016 02:44:50 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id C7C965FBF6 for ; Mon, 17 Oct 2016 02:44:49 +0000 (UTC) Received: (qmail 89730 invoked by uid 99); 17 Oct 2016 02:44:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Oct 2016 02:44:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8FA7CDFF8C; Mon, 17 Oct 2016 02:44:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mw@apache.org To: commits@eagle.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-eagle git commit: [EAGLE-621] set authentication disabled by default when no 'auth' is configured Date: Mon, 17 Oct 2016 02:44:48 +0000 (UTC) archived-at: Mon, 17 Oct 2016 02:44:58 -0000 Repository: incubator-eagle Updated Branches: refs/heads/master 33b972065 -> b103e201e [EAGLE-621] set authentication disabled by default when no 'auth' is configured Authentication settings are configured in configuration.yml file, starting with "auth" syntax. Now make the system see authentication as disabled when no auth related syntax is set. Also, do some refactoring to make the code clearer. Author: anyway1021 Closes #514 from anyway1021/EAGLE-621. Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/b103e201 Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/b103e201 Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/b103e201 Branch: refs/heads/master Commit: b103e201ebe7b1500ba3d0297bb7aa88e7aa811a Parents: 33b9720 Author: anyway1021 Authored: Mon Oct 17 10:44:36 2016 +0800 Committer: anyway1021 Committed: Mon Oct 17 10:44:36 2016 +0800 ---------------------------------------------------------------------- .../apache/eagle/server/ServerApplication.java | 8 +- .../authentication/AuthenticationMode.java | 51 --------- .../AuthenticationModeIdentifier.java | 105 ------------------- .../authentication/AuthenticationRegister.java | 41 -------- .../BasicAuthProviderBuilder.java | 66 ++++++++++++ .../SwitchableBasicAuthProvider.java | 50 --------- .../AbstractSwitchableAuthenticator.java | 48 --------- .../authenticator/LdapBasicAuthenticator.java | 11 +- .../authenticator/SimpleBasicAuthenticator.java | 12 +-- 9 files changed, 82 insertions(+), 310 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java b/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java index 2ae95a6..df1d7e7 100644 --- a/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java +++ b/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.eagle.server; + import com.google.inject.Injector; import com.hubspot.dropwizard.guice.GuiceBundle; import com.sun.jersey.api.core.PackagesResourceConfig; @@ -27,11 +28,10 @@ import io.swagger.jaxrs.config.BeanConfig; import io.swagger.jaxrs.listing.ApiListingResource; import org.apache.eagle.alert.coordinator.CoordinatorListener; import org.apache.eagle.alert.resource.SimpleCORSFiler; -import org.apache.eagle.common.authentication.User; import org.apache.eagle.log.base.taggedlog.EntityJsonModule; import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity; import org.apache.eagle.metadata.service.ApplicationStatusUpdateService; -import org.apache.eagle.server.authentication.AuthenticationRegister; +import org.apache.eagle.server.authentication.BasicAuthProviderBuilder; import org.apache.eagle.server.managedtask.ApplicationTask; import org.apache.eagle.server.module.GuiceBundleLoader; @@ -80,8 +80,8 @@ class ServerApplication extends Application { environment.servlets().addFilter(SimpleCORSFiler.class.getName(), new SimpleCORSFiler()) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); - // add authentication filters - new AuthenticationRegister<>(configuration, environment, User.class).register(); + // register authentication provider + environment.jersey().register(new BasicAuthProviderBuilder(configuration.getAuth(), environment).build()); // context listener environment.servlets().addServletListeners(new CoordinatorListener()); http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationMode.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationMode.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationMode.java deleted file mode 100644 index 8a7208f..0000000 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationMode.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.server.authentication; - -import io.dropwizard.auth.Authenticator; -import io.dropwizard.auth.CachingAuthenticator; -import io.dropwizard.auth.basic.BasicCredentials; - -public abstract class AuthenticationMode

{ - private static final String PREFIX_VALUE = "Basic"; - - protected AuthenticationModeIdentifier identifier = null; - - private Authenticator authenticator = null; - - public AuthenticationMode(AuthenticationModeIdentifier identifier) { - this.identifier = identifier; - this.authenticator = createAuthenticator(); - } - - abstract Authenticator createAuthenticator(); - - abstract String getRealm(); - - Authenticator getAuthenticator() { - return identifier.cacheRequired() ? cache(authenticator) : authenticator; - } - - private Authenticator cache(Authenticator authenticator) { - return new CachingAuthenticator(identifier.getMetricRegistry(), authenticator, identifier.getCacheBuilderSpec()); - } - - AuthenticationModeIdentifier getIdentifier() { - return identifier; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationModeIdentifier.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationModeIdentifier.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationModeIdentifier.java deleted file mode 100644 index 979bcbf..0000000 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationModeIdentifier.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.server.authentication; - -import com.codahale.metrics.MetricRegistry; -import com.google.common.cache.CacheBuilderSpec; -import io.dropwizard.auth.Authenticator; -import io.dropwizard.auth.basic.BasicCredentials; -import io.dropwizard.setup.Environment; -import org.apache.eagle.common.authentication.User; -import org.apache.eagle.server.authentication.authenticator.LdapBasicAuthenticator; -import org.apache.eagle.server.authentication.authenticator.SimpleBasicAuthenticator; -import org.apache.eagle.server.authentication.config.AuthenticationSettings; - -public class AuthenticationModeIdentifier { - private static final String SIMPLE_MODE_KEYWORD = "simple"; - private static final String SIMPLE_MODE_REALM = "SIMPLE_AUTHENTICATION"; - private static final String LDAP_MODE_KEYWORD = "ldap"; - private static final String LDAP_MODE_REALM = "LDAP_AUTHENTICATION"; - - private AuthenticationSettings settings = null; - private Environment environment = null; - - private AuthenticationModeIdentifier(AuthenticationSettings settings, Environment environment) { - this.settings = settings; - this.environment = environment; - } - - static AuthenticationModeIdentifier initiate(AuthenticationSettings config, Environment environment) { - return new AuthenticationModeIdentifier(config, environment); - } - - AuthenticationMode identify() { - String modeKeyword = getModeKeyword(); - if (SIMPLE_MODE_KEYWORD.equalsIgnoreCase(modeKeyword)) { - return new AuthenticationMode(this) { - public Authenticator createAuthenticator() { - return new SimpleBasicAuthenticator(getIdentifier().getSettings()); - } - - public String getRealm() { - return AuthenticationModeIdentifier.SIMPLE_MODE_REALM; - } - }; - } - if (LDAP_MODE_KEYWORD.equalsIgnoreCase(modeKeyword)) { - return new AuthenticationMode(this) { - public Authenticator createAuthenticator() { - return new LdapBasicAuthenticator(getIdentifier().getSettings()); - } - - public String getRealm() { - return AuthenticationModeIdentifier.LDAP_MODE_REALM; - } - }; - } - throw new RuntimeException(String.format("No matching mode can be found: %s", modeKeyword)); - } - - MetricRegistry getMetricRegistry() { - return environment.metrics(); - } - - boolean cacheRequired() { - return settings.needsCaching(); - } - - boolean authorizationRequired() { - return settings.needsAuthorization(); - } - - boolean parameterAnnotationEnabled() { - return settings.byAnnotated(); - } - - CacheBuilderSpec getCacheBuilderSpec() { - return CacheBuilderSpec.parse(settings.getCachePolicy()); - } - - AuthenticationSettings getSettings() { - return settings; - } - - private Environment getEnvironment() { - return environment; - } - - private String getModeKeyword() { - return settings.getMode(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationRegister.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationRegister.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationRegister.java deleted file mode 100644 index 65d2171..0000000 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/AuthenticationRegister.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.server.authentication; - -import io.dropwizard.setup.Environment; -import org.apache.eagle.common.authentication.User; -import org.apache.eagle.server.ServerConfig; - -import java.security.Principal; - -public class AuthenticationRegister

{ - private ServerConfig serverConfig = null; - private Environment environment = null; - private Class

principalClass = null; - - public AuthenticationRegister(ServerConfig serverConfig, Environment environment, Class

principalClass) { - this.serverConfig = serverConfig; - this.environment = environment; - this.principalClass = principalClass; - } - - public void register() { - AuthenticationMode mode = AuthenticationModeIdentifier.initiate(serverConfig.getAuth(), environment).identify(); - - environment.jersey().register(new SwitchableBasicAuthProvider(mode.getAuthenticator(), mode.getRealm())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/BasicAuthProviderBuilder.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/BasicAuthProviderBuilder.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/BasicAuthProviderBuilder.java new file mode 100644 index 0000000..e0bb4c1 --- /dev/null +++ b/eagle-server/src/main/java/org/apache/eagle/server/authentication/BasicAuthProviderBuilder.java @@ -0,0 +1,66 @@ +package org.apache.eagle.server.authentication; + +import com.google.common.cache.CacheBuilderSpec; +import com.sun.jersey.api.core.HttpContext; +import com.sun.jersey.api.model.Parameter; +import com.sun.jersey.core.spi.component.ComponentContext; +import com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable; +import com.sun.jersey.spi.inject.Injectable; +import io.dropwizard.auth.Auth; +import io.dropwizard.auth.Authenticator; +import io.dropwizard.auth.CachingAuthenticator; +import io.dropwizard.auth.basic.BasicAuthProvider; +import io.dropwizard.auth.basic.BasicCredentials; +import io.dropwizard.setup.Environment; +import org.apache.eagle.common.authentication.User; +import org.apache.eagle.server.authentication.authenticator.LdapBasicAuthenticator; +import org.apache.eagle.server.authentication.authenticator.SimpleBasicAuthenticator; +import org.apache.eagle.server.authentication.config.AuthenticationSettings; + +import java.util.HashMap; +import java.util.Map; + +public class BasicAuthProviderBuilder { + private static final String SIMPLE_MODE_REALM = "SIMPLE_AUTHENTICATION"; + private static final String LDAP_MODE_REALM = "LDAP_AUTHENTICATION"; + private static final Map> MAPPING = new HashMap<>(); + private AuthenticationSettings authSettings; + private Environment environment; + + public BasicAuthProviderBuilder(AuthenticationSettings authSettings, Environment environment) { + this.authSettings = authSettings; + this.environment = environment; + Authenticator simpleAuthenticator = new SimpleBasicAuthenticator(authSettings.getSimple()); + Authenticator ldapAuthenticator = new LdapBasicAuthenticator(authSettings.getLdap()); + boolean needsCaching = authSettings.needsCaching(); + MAPPING.put("simple", + new BasicAuthProvider<>(needsCaching ? cache(simpleAuthenticator) : simpleAuthenticator, SIMPLE_MODE_REALM)); + MAPPING.put("ldap", + new BasicAuthProvider<>(needsCaching ? cache(ldapAuthenticator) : ldapAuthenticator, LDAP_MODE_REALM)); + } + + public BasicAuthProvider build() { + if (authSettings.isEnabled()) { + String mode = authSettings.getMode(); + if (MAPPING.containsKey(mode)) { + return MAPPING.get(mode); + } else { + throw new RuntimeException(String.format("No matching mode found: %s", mode)); + } + } else { + return new BasicAuthProvider(null, "") { + public Injectable getInjectable(ComponentContext ic, Auth a, Parameter c) { + return new AbstractHttpContextInjectable() { + public User getValue(HttpContext c) { + return new User("non-auth"); + } + }; + } + }; + } + } + + private Authenticator cache(Authenticator authenticator) { + return new CachingAuthenticator<>(environment.metrics(), authenticator, CacheBuilderSpec.parse(authSettings.getCachePolicy())); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/SwitchableBasicAuthProvider.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/SwitchableBasicAuthProvider.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/SwitchableBasicAuthProvider.java deleted file mode 100644 index 74f286d..0000000 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/SwitchableBasicAuthProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.server.authentication; - -import com.sun.jersey.api.core.HttpContext; -import com.sun.jersey.api.model.Parameter; -import com.sun.jersey.core.spi.component.ComponentContext; -import com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable; -import com.sun.jersey.spi.inject.Injectable; -import io.dropwizard.auth.Auth; -import io.dropwizard.auth.Authenticator; -import io.dropwizard.auth.basic.BasicAuthProvider; -import io.dropwizard.auth.basic.BasicCredentials; -import org.apache.eagle.server.authentication.authenticator.AbstractSwitchableAuthenticator; - -public class SwitchableBasicAuthProvider

extends BasicAuthProvider

{ - private AbstractSwitchableAuthenticator switchableAuthenticator = null; - - public SwitchableBasicAuthProvider(Authenticator authenticator, String realm) { - super(authenticator, realm); - if (authenticator instanceof AbstractSwitchableAuthenticator) { - switchableAuthenticator = (AbstractSwitchableAuthenticator) authenticator; - } - } - - public Injectable getInjectable(ComponentContext ic, Auth a, Parameter c) { - if (switchableAuthenticator != null && !switchableAuthenticator.getSettings().isEnabled()) { - return new AbstractHttpContextInjectable

() { - public P getValue(HttpContext c) { - return switchableAuthenticator.getUnauthenticatedPrincipal(); - } - }; - } - return super.getInjectable(ic, a, c); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/AbstractSwitchableAuthenticator.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/AbstractSwitchableAuthenticator.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/AbstractSwitchableAuthenticator.java deleted file mode 100644 index 5ca12fb..0000000 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/AbstractSwitchableAuthenticator.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.server.authentication.authenticator; - -import io.dropwizard.auth.Authenticator; -import org.apache.eagle.server.authentication.config.AuthenticationSettings; - -public abstract class AbstractSwitchableAuthenticator implements Authenticator { - private AuthenticationSettings settings; - private Class

principalClass; - private P unauthenticatedPrincipal; - - public AbstractSwitchableAuthenticator(AuthenticationSettings settings, Class

principalClass) { - this.settings = settings; - this.principalClass = principalClass; - } - - public AuthenticationSettings getSettings() { - return settings; - } - - public P getUnauthenticatedPrincipal() { - try { - if (unauthenticatedPrincipal == null) { - unauthenticatedPrincipal = principalClass.newInstance(); - } - return unauthenticatedPrincipal; - } catch (InstantiationException e) { - throw new RuntimeException(String.format("Filed to instantiate %s", principalClass.getName()), e); - } catch (IllegalAccessException e) { - throw new RuntimeException(String.format("Illegal access to %s", principalClass.getName()), e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/LdapBasicAuthenticator.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/LdapBasicAuthenticator.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/LdapBasicAuthenticator.java index 59abc52..87ebb34 100644 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/LdapBasicAuthenticator.java +++ b/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/LdapBasicAuthenticator.java @@ -18,15 +18,16 @@ package org.apache.eagle.server.authentication.authenticator; import com.google.common.base.Optional; import io.dropwizard.auth.AuthenticationException; +import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.basic.BasicCredentials; import org.apache.eagle.common.authentication.User; -import org.apache.eagle.server.authentication.config.AuthenticationSettings; +import org.apache.eagle.server.authentication.config.LdapSettings; -public class LdapBasicAuthenticator extends AbstractSwitchableAuthenticator { - private AuthenticationSettings config = null; +public class LdapBasicAuthenticator implements Authenticator { + private LdapSettings settings = null; - public LdapBasicAuthenticator(AuthenticationSettings settings) { - super(settings, User.class); + public LdapBasicAuthenticator(LdapSettings settings) { + this.settings = settings; } public Optional authenticate(BasicCredentials credentials) throws AuthenticationException { http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/b103e201/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/SimpleBasicAuthenticator.java ---------------------------------------------------------------------- diff --git a/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/SimpleBasicAuthenticator.java b/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/SimpleBasicAuthenticator.java index 910bc92..ede3b06 100644 --- a/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/SimpleBasicAuthenticator.java +++ b/eagle-server/src/main/java/org/apache/eagle/server/authentication/authenticator/SimpleBasicAuthenticator.java @@ -18,18 +18,18 @@ package org.apache.eagle.server.authentication.authenticator; import com.google.common.base.Optional; import io.dropwizard.auth.AuthenticationException; +import io.dropwizard.auth.Authenticator; import io.dropwizard.auth.basic.BasicCredentials; import org.apache.eagle.common.authentication.User; -import org.apache.eagle.server.authentication.config.AuthenticationSettings; +import org.apache.eagle.server.authentication.config.SimpleSettings; -public class SimpleBasicAuthenticator extends AbstractSwitchableAuthenticator { +public class SimpleBasicAuthenticator implements Authenticator { private String acceptedUsername = null; private String acceptedPassword = null; - public SimpleBasicAuthenticator(AuthenticationSettings settings) { - super(settings, User.class); - acceptedUsername = settings.getSimple().getUsername(); - acceptedPassword = settings.getSimple().getPassword(); + public SimpleBasicAuthenticator(SimpleSettings settings) { + acceptedUsername = settings.getUsername(); + acceptedPassword = settings.getPassword(); } public Optional authenticate(BasicCredentials credentials) throws AuthenticationException {