Cleanup: Incorporating findbugs/pmd findings

Original commit: elastic/x-pack-elasticsearch@5567fae416
This commit is contained in:
Alexander Reelsen 2014-08-29 10:05:03 +02:00
parent 25d2480e78
commit c6b7be5596
22 changed files with 31 additions and 65 deletions

View File

@ -15,7 +15,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.shield.audit.AuditTrailModule; import org.elasticsearch.shield.audit.AuditTrailModule;
import org.elasticsearch.shield.authc.AuthenticationModule; import org.elasticsearch.shield.authc.AuthenticationModule;
import org.elasticsearch.shield.authz.AuthorizationModule; import org.elasticsearch.shield.authz.AuthorizationModule;
import org.elasticsearch.shield.n2n.N2NModule; import org.elasticsearch.shield.n2n.N2NAuthModule;
import org.elasticsearch.shield.transport.SecuredTransportModule; import org.elasticsearch.shield.transport.SecuredTransportModule;
import org.elasticsearch.shield.transport.netty.NettySecuredHttpServerTransportModule; import org.elasticsearch.shield.transport.netty.NettySecuredHttpServerTransportModule;
import org.elasticsearch.shield.transport.netty.NettySecuredTransportModule; import org.elasticsearch.shield.transport.netty.NettySecuredTransportModule;
@ -52,7 +52,7 @@ public class SecurityModule extends AbstractModule implements SpawnModules, PreP
// spawn needed parts in client mode // spawn needed parts in client mode
if (isClient) { if (isClient) {
return ImmutableList.of( return ImmutableList.of(
new N2NModule(), new N2NAuthModule(),
new SecuredTransportModule() new SecuredTransportModule()
); );
} }
@ -61,7 +61,7 @@ public class SecurityModule extends AbstractModule implements SpawnModules, PreP
new AuthenticationModule(settings), new AuthenticationModule(settings),
new AuthorizationModule(), new AuthorizationModule(),
new AuditTrailModule(settings), new AuditTrailModule(settings),
new N2NModule(), new N2NAuthModule(),
new NettySecuredHttpServerTransportModule(), new NettySecuredHttpServerTransportModule(),
new NettySecuredTransportModule(), new NettySecuredTransportModule(),
new SecuredTransportModule()); new SecuredTransportModule());

View File

@ -14,7 +14,7 @@ import org.elasticsearch.transport.TransportMessage;
*/ */
public interface AuditTrail { public interface AuditTrail {
public static final AuditTrail NOOP = new AuditTrail() { static final AuditTrail NOOP = new AuditTrail() {
static final String NAME = "noop"; static final String NAME = "noop";

View File

@ -146,18 +146,16 @@ public class FileUserPasswdStore extends AbstractComponent implements UserPasswd
@Override @Override
public void onFileChanged(File file) { public void onFileChanged(File file) {
if (file.equals(FileUserPasswdStore.this.file.toFile())) {
if (file.equals(FileUserPasswdStore.this.file.toFile())) { if (file.equals(FileUserPasswdStore.this.file.toFile())) {
esUsers = ImmutableMap.copyOf(parseFile(file.toPath(), logger)); esUsers = ImmutableMap.copyOf(parseFile(file.toPath(), logger));
listener.onRefresh(); listener.onRefresh();
} }
} }
} }
}
public static interface Listener { public static interface Listener {
static final Listener NOOP = new Listener() { final Listener NOOP = new Listener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
} }

View File

@ -158,14 +158,12 @@ public class FileUserRolesStore extends AbstractComponent implements UserRolesSt
@Override @Override
public void onFileChanged(File file) { public void onFileChanged(File file) {
if (file.equals(FileUserRolesStore.this.file.toFile())) {
if (file.equals(FileUserRolesStore.this.file.toFile())) { if (file.equals(FileUserRolesStore.this.file.toFile())) {
userRoles = ImmutableMap.copyOf(parseFile(file.toPath(), logger)); userRoles = ImmutableMap.copyOf(parseFile(file.toPath(), logger));
listener.onRefresh(); listener.onRefresh();
} }
} }
} }
}
public static interface Listener { public static interface Listener {

View File

@ -327,7 +327,7 @@ public class ESUsersTool extends CliTool {
private static final CliToolConfig.Cmd CMD = cmd(NAME, Useradd.class).build(); private static final CliToolConfig.Cmd CMD = cmd(NAME, Useradd.class).build();
public static Command parse(Terminal terminal, CommandLine cli) { public static Command parse(Terminal terminal, CommandLine cli) {
String username = (cli.getArgs().length > 0) ? cli.getArgs()[0] : null; String username = cli.getArgs().length > 0 ? cli.getArgs()[0] : null;
return new ListUsersAndRoles(terminal, username); return new ListUsersAndRoles(terminal, username);
} }

View File

@ -65,7 +65,7 @@ public class ActiveDirectoryConnectionFactory extends AbstractComponent implemen
public LdapConnection bind(String userName, char[] password) { public LdapConnection bind(String userName, char[] password) {
String userPrincipal = userName + "@" + this.domainName; String userPrincipal = userName + "@" + this.domainName;
Hashtable<String, java.io.Serializable> ldapEnv = new Hashtable<>(this.sharedLdapEnv); Hashtable<String, Serializable> ldapEnv = new Hashtable<>(this.sharedLdapEnv);
ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
ldapEnv.put(Context.SECURITY_PRINCIPAL, userPrincipal); ldapEnv.put(Context.SECURITY_PRINCIPAL, userPrincipal);
ldapEnv.put(Context.SECURITY_CREDENTIALS, password); ldapEnv.put(Context.SECURITY_CREDENTIALS, password);

View File

@ -18,12 +18,12 @@ package org.elasticsearch.shield.authc.ldap;
*/ */
public interface LdapConnectionFactory { public interface LdapConnectionFactory {
public static final String URLS_SETTING = "urls"; //comma separated static final String URLS_SETTING = "urls"; //comma separated
/** /**
* Password authenticated bind * Password authenticated bind
* @param user name of the user to authenticate the connection with. * @param user name of the user to authenticate the connection with.
*/ */
public LdapConnection bind(String user, char[] password) ; LdapConnection bind(String user, char[] password) ;
} }

View File

@ -140,9 +140,9 @@ public class LdapGroupToRoleMapper extends AbstractComponent {
} }
} }
public static interface Listener { static interface Listener {
static final Listener NOOP = new Listener() { final Listener NOOP = new Listener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
} }

View File

@ -69,7 +69,7 @@ public class StandardLdapConnectionFactory extends AbstractComponent implements
@Override @Override
public LdapConnection bind(String username, char[] password) { public LdapConnection bind(String username, char[] password) {
//SASL, MD5, etc. all options here stink, we really need to go over ssl + simple authentication //SASL, MD5, etc. all options here stink, we really need to go over ssl + simple authentication
Hashtable<String, java.io.Serializable> ldapEnv = new Hashtable<>(this.sharedLdapEnv); Hashtable<String, Serializable> ldapEnv = new Hashtable<>(this.sharedLdapEnv);
ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
ldapEnv.put(Context.SECURITY_CREDENTIALS, password); ldapEnv.put(Context.SECURITY_CREDENTIALS, password);

View File

@ -746,6 +746,6 @@ public class BCrypt {
* @return true if the passwords match, false otherwise * @return true if the passwords match, false otherwise
*/ */
public static boolean checkpw(String plaintext, String hashed) { public static boolean checkpw(String plaintext, String hashed) {
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0); return hashed.compareTo(hashpw(plaintext, hashed)) == 0;
} }
} }

View File

@ -111,7 +111,7 @@ public abstract class CachingUserPasswdStore extends AbstractComponent implement
/** /**
* Represents a hash of a password. * Represents a hash of a password.
*/ */
protected static interface PasswordHash { static interface PasswordHash {
boolean verify(char[] password); boolean verify(char[] password);

View File

@ -12,7 +12,7 @@ public interface UserPasswdStore {
boolean verifyPassword(String username, char[] password); boolean verifyPassword(String username, char[] password);
public static interface Writable extends UserPasswdStore { static interface Writable extends UserPasswdStore {
void store(String username, char[] password); void store(String username, char[] password);

View File

@ -12,7 +12,7 @@ public interface UserRolesStore {
String[] roles(String username); String[] roles(String username);
public static interface Writable extends UserRolesStore { static interface Writable extends UserRolesStore {
void setRoles(String username, String... roles); void setRoles(String username, String... roles);

View File

@ -38,7 +38,7 @@ public interface Permission {
boolean check(String action, TransportRequest request, MetaData metaData); boolean check(String action, TransportRequest request, MetaData metaData);
public static class Global implements Permission { static class Global implements Permission {
private final Cluster cluster; private final Cluster cluster;
private final Indices indices; private final Indices indices;
@ -102,7 +102,7 @@ public interface Permission {
} }
} }
public static class Cluster implements Permission { static class Cluster implements Permission {
public static final Cluster NONE = new Cluster(Privilege.Cluster.NONE) { public static final Cluster NONE = new Cluster(Privilege.Cluster.NONE) {
@Override @Override
@ -129,7 +129,7 @@ public interface Permission {
} }
} }
public static class Indices implements Permission { static class Indices implements Permission {
public static final Indices NONE = new Indices() { public static final Indices NONE = new Indices() {
@Override @Override
@ -138,7 +138,7 @@ public interface Permission {
} }
}; };
public static IndicesResolver[] indicesResolvers = new IndicesResolver[] { static final IndicesResolver[] indicesResolvers = new IndicesResolver[] {
// add special resolvers here // add special resolvers here
new DefaultIndicesResolver() new DefaultIndicesResolver()
}; };

View File

@ -12,7 +12,6 @@ import org.elasticsearch.common.collect.ImmutableSet;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.jackson.dataformat.yaml.snakeyaml.error.YAMLException; import org.elasticsearch.common.jackson.dataformat.yaml.snakeyaml.error.YAMLException;
import org.elasticsearch.common.jackson.dataformat.yaml.snakeyaml.scanner.ScannerException;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -194,9 +193,9 @@ public class FileRolesStore extends AbstractComponent implements RolesStore {
} }
} }
public static interface Listener { static interface Listener {
public static final Listener NOOP = new Listener() { static final Listener NOOP = new Listener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
} }

View File

@ -15,7 +15,7 @@ public interface RolesStore {
Permission.Global permission(String role); Permission.Global permission(String role);
public static interface Writable extends RolesStore { static interface Writable extends RolesStore {
void set(String role, Privilege.Index privilege, String... indices); void set(String role, Privilege.Index privilege, String... indices);

View File

@ -13,14 +13,9 @@ import org.elasticsearch.common.settings.Settings;
*/ */
public class N2NAuthModule extends AbstractModule { public class N2NAuthModule extends AbstractModule {
private final Settings settings;
public N2NAuthModule(Settings settings) {
this.settings = settings;
}
@Override @Override
protected void configure() { protected void configure() {
bind(IPFilteringN2NAuthenticator.class).asEagerSingleton();
bind(N2NNettyUpstreamHandler.class).asEagerSingleton(); bind(N2NNettyUpstreamHandler.class).asEagerSingleton();
} }
} }

View File

@ -1,19 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.shield.n2n;
import org.elasticsearch.common.inject.AbstractModule;
/**
*
*/
public class N2NModule extends AbstractModule {
@Override
protected void configure() {
bind(IPFilteringN2NAuthenticator.class).asEagerSingleton();
}
}

View File

@ -7,12 +7,8 @@ package org.elasticsearch.shield.plugin;
import org.elasticsearch.common.collect.ImmutableList; import org.elasticsearch.common.collect.ImmutableList;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.http.HttpServerModule;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.shield.SecurityModule; import org.elasticsearch.shield.SecurityModule;
import org.elasticsearch.shield.transport.netty.NettySecuredHttpServerTransport;
import org.elasticsearch.shield.transport.netty.NettySecuredTransport;
import org.elasticsearch.transport.TransportModule;
import java.util.Collection; import java.util.Collection;

View File

@ -40,7 +40,7 @@ public interface TransportFilter {
*/ */
void inboundResponse(TransportResponse response); void inboundResponse(TransportResponse response);
public static class Base implements TransportFilter { static class Base implements TransportFilter {
@Override @Override
public void outboundRequest(String action, TransportRequest request) { public void outboundRequest(String action, TransportRequest request) {

View File

@ -23,7 +23,7 @@ public class SSLConfig {
private static final ESLogger logger = Loggers.getLogger(SSLConfig.class); private static final ESLogger logger = Loggers.getLogger(SSLConfig.class);
// TODO removing the second one results in fails, need to verify the differences, maybe per JVM? // TODO removing the second one results in fails, need to verify the differences, maybe per JVM?
public static final String[] DEFAULT_CIPHERS = new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA" }; static final String[] DEFAULT_CIPHERS = new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_RSA_WITH_AES_128_CBC_SHA" };
private final boolean clientAuth; private final boolean clientAuth;
private SSLContext sslContext; private SSLContext sslContext;

View File

@ -8,7 +8,6 @@ package org.elasticsearch.shield.n2n;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.shield.n2n.N2NModule;
import java.util.Collection; import java.util.Collection;
@ -28,6 +27,6 @@ public class N2NPlugin extends AbstractPlugin {
@Override @Override
public Collection<Class<? extends Module>> modules() { public Collection<Class<? extends Module>> modules() {
return ImmutableSet.<Class<? extends Module>>of(N2NModule.class); return ImmutableSet.<Class<? extends Module>>of(N2NAuthModule.class);
} }
} }