Permalink
Browse files

indention fixed

  • Loading branch information...
1 parent 43bd28b commit c75b0c95289abfe2844095dd21777faf5fc3a91f @anfeng anfeng committed Feb 17, 2013
@@ -2,114 +2,140 @@
import java.io.IOException;
import java.util.Map;
-
import javax.security.auth.callback.CallbackHandler;
import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslClientFactory;
import javax.security.sasl.SaslServerFactory;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-
import com.google.common.annotations.VisibleForTesting;
public class AnonymousAuthenticationProvider extends java.security.Provider {
- public AnonymousAuthenticationProvider() {
- super("ThriftSaslAnonymous", 1.0, "Thrift Anonymous SASL provider");
- put("SaslClientFactory.ANONYMOUS", SaslAnonymousFactory.class.getName());
- put("SaslServerFactory.ANONYMOUS", SaslAnonymousFactory.class.getName());
- }
-
- public static class SaslAnonymousFactory implements SaslClientFactory, SaslServerFactory {
-
- @Override
- public SaslClient createSaslClient(
- String[] mechanisms, String authorizationId, String protocol,
- String serverName, Map<String,?> props, CallbackHandler cbh)
- {
- for (String mech : mechanisms) {
- if ("ANONYMOUS".equals(mech)) {
- return new AnonymousClient(authorizationId);
- }
- }
- return null;
+ public AnonymousAuthenticationProvider() {
+ super("ThriftSaslAnonymous", 1.0, "Thrift Anonymous SASL provider");
+ put("SaslClientFactory.ANONYMOUS", SaslAnonymousFactory.class.getName());
+ put("SaslServerFactory.ANONYMOUS", SaslAnonymousFactory.class.getName());
+ }
+
+ public static class SaslAnonymousFactory implements SaslClientFactory, SaslServerFactory {
+ @Override
+ public SaslClient createSaslClient(String[] mechanisms, String authorizationId, String protocol,
+ String serverName, Map<String,?> props, CallbackHandler cbh)
+ {
+ for (String mech : mechanisms) {
+ if ("ANONYMOUS".equals(mech)) {
+ return new AnonymousClient(authorizationId);
}
+ }
+ return null;
+ }
- @Override
- public SaslServer createSaslServer(
- String mechanism, String protocol, String serverName, Map<String,?> props, CallbackHandler cbh)
- {
- if ("ANONYMOUS".equals(mechanism)) {
- return new AnonymousServer();
- }
- return null;
- }
- public String[] getMechanismNames(Map<String, ?> props) {
- return new String[] { "ANONYMOUS" };
- }
+ @Override
+ public SaslServer createSaslServer(String mechanism, String protocol,
+ String serverName, Map<String,?> props, CallbackHandler cbh)
+ {
+ if ("ANONYMOUS".equals(mechanism)) {
+ return new AnonymousServer();
+ }
+ return null;
+ }
+ public String[] getMechanismNames(Map<String, ?> props) {
+ return new String[] { "ANONYMOUS" };
}
+ }
}
class AnonymousClient implements SaslClient {
- @VisibleForTesting
- final String username;
- private boolean hasProvidedInitialResponse;
-
- public AnonymousClient(String username) {
- if (username == null) {
- this.username = "anonymous";
- } else {
- this.username = username;
- }
+ @VisibleForTesting
+ final String username;
+ private boolean hasProvidedInitialResponse;
+
+ public AnonymousClient(String username) {
+ if (username == null) {
+ this.username = "anonymous";
+ } else {
+ this.username = username;
}
+ }
- public String getMechanismName() { return "ANONYMOUS"; }
- public boolean hasInitialResponse() { return true; }
- public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
- if (hasProvidedInitialResponse) {
- throw new SaslException("Already complete!");
- }
+ public String getMechanismName() {
+ return "ANONYMOUS";
+ }
- try {
- hasProvidedInitialResponse = true;
- return username.getBytes("UTF-8");
- } catch (IOException e) {
- throw new SaslException(e.toString());
- }
- }
- public boolean isComplete() { return hasProvidedInitialResponse; }
- public byte[] unwrap(byte[] incoming, int offset, int len) {
- throw new UnsupportedOperationException();
+ public boolean hasInitialResponse() {
+ return true;
+ }
+
+ public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
+ if (hasProvidedInitialResponse) {
+ throw new SaslException("Already complete!");
}
- public byte[] wrap(byte[] outgoing, int offset, int len) {
- throw new UnsupportedOperationException();
+
+ try {
+ hasProvidedInitialResponse = true;
+ return username.getBytes("UTF-8");
+ } catch (IOException e) {
+ throw new SaslException(e.toString());
}
- public Object getNegotiatedProperty(String propName) { return null; }
- public void dispose() {}
+ }
+
+ public boolean isComplete() {
+ return hasProvidedInitialResponse;
+ }
+
+ public byte[] unwrap(byte[] incoming, int offset, int len) {
+ throw new UnsupportedOperationException();
+ }
+
+ public byte[] wrap(byte[] outgoing, int offset, int len) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getNegotiatedProperty(String propName) {
+ return null;
+ }
+
+ public void dispose() {}
}
class AnonymousServer implements SaslServer {
- private String user;
- public String getMechanismName() { return "ANONYMOUS"; }
- public byte[] evaluateResponse(byte[] response) throws SaslException {
- try {
- this.user = new String(response, "UTF-8");
- } catch (IOException e) {
- throw new SaslException(e.toString());
- }
- return null;
- }
- public boolean isComplete() { return user != null; }
- public String getAuthorizationID() { return user; }
- public byte[] unwrap(byte[] incoming, int offset, int len) {
- throw new UnsupportedOperationException();
- }
- public byte[] wrap(byte[] outgoing, int offset, int len) {
- throw new UnsupportedOperationException();
+ private String user;
+
+ public String getMechanismName() {
+ return "ANONYMOUS";
+ }
+
+ public byte[] evaluateResponse(byte[] response) throws SaslException {
+ try {
+ this.user = new String(response, "UTF-8");
+ } catch (IOException e) {
+ throw new SaslException(e.toString());
}
- public Object getNegotiatedProperty(String propName) { return null; }
- public void dispose() {}
+ return null;
+ }
+
+ public boolean isComplete() {
+ return user != null;
+ }
+
+ public String getAuthorizationID() {
+ return user;
+ }
+
+ public byte[] unwrap(byte[] incoming, int offset, int len) {
+ throw new UnsupportedOperationException();
+ }
+
+ public byte[] wrap(byte[] outgoing, int offset, int len) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getNegotiatedProperty(String propName) {
+ return null;
+ }
+ public void dispose() {}
}
@@ -2,38 +2,34 @@
import javax.security.auth.login.Configuration;
import javax.security.auth.login.AppConfigurationEntry;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-
import java.io.IOException;
public class AuthUtils {
- public static String LoginContextServer = "StormServer";
- public static String LoginContextClient = "StormClient";
-
- static public final String DIGEST = "DIGEST-MD5";
- static public final String ANONYMOUS = "ANONYMOUS";
- static public final String KERBEROS = "GSSAPI";
- static public final String SERVICE = "storm_thrift_server";
-
- private static final Logger LOG = LoggerFactory.getLogger(AuthUtils.class);
-
- public static String get(Configuration configuration, String section, String key) throws IOException {
- AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(section);
- if (configurationEntries == null) {
- String errorMessage = "Could not find a '"+ section + "' entry in this configuration.";
- LOG.error(errorMessage);
- throw new IOException(errorMessage);
- }
+ public static String LoginContextServer = "StormServer";
+ public static String LoginContextClient = "StormClient";
+ public static final String DIGEST = "DIGEST-MD5";
+ public static final String ANONYMOUS = "ANONYMOUS";
+ public static final String KERBEROS = "GSSAPI";
+ public static final String SERVICE = "storm_thrift_server";
+ private static final Logger LOG = LoggerFactory.getLogger(AuthUtils.class);
+
+
+ public static String get(Configuration configuration, String section, String key) throws IOException {
+ AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(section);
+ if (configurationEntries == null) {
+ String errorMessage = "Could not find a '"+ section + "' entry in this configuration.";
+ LOG.error(errorMessage);
+ throw new IOException(errorMessage);
+ }
- for(AppConfigurationEntry entry: configurationEntries) {
- Object val = entry.getOptions().get(key);
- if (val != null)
- return (String)val;
- }
- return null;
+ for(AppConfigurationEntry entry: configurationEntries) {
+ Object val = entry.getOptions().get(key);
+ if (val != null)
+ return (String)val;
}
+ return null;
+ }
}
@@ -1,35 +1,32 @@
package backtype.storm.security.auth;
import backtype.storm.Config;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An authorization implementation that denies everything, for testing purposes
*/
public class DenyAuthorizer implements IAuthorization {
- private static final Logger LOG =
- LoggerFactory.getLogger(DenyAuthorizer.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DenyAuthorizer.class);
- /**
- * permit() method is invoked for each incoming Thrift request
- * @param contrext request context includes info about
- * (1) remote address/subject,
- * (2) operation
- * (3) configuration of targeted topology
- * @return true if the request is authorized, false if reject
- */
- public boolean permit(ReqContext context) {
- LOG.info("Access "
- + " from: " +
- (context.remoteAddress() == null
- ? "null" : context.remoteAddress().toString())
- + " principal:"+ (context.principal() == null
- ? "null" : context.principal())
- +" op:"+context.operation()
- + " topoology:"+context.topologyConf().get(Config.TOPOLOGY_NAME)
- );
- return false;
- }
+ /**
+ * permit() method is invoked for each incoming Thrift request
+ * @param contrext request context includes info about
+ * (1) remote address/subject,
+ * (2) operation
+ * (3) configuration of targeted topology
+ * @return true if the request is authorized, false if reject
+ */
+ public boolean permit(ReqContext context) {
+ LOG.info("Access "
+ + " from: " +
+ (context.remoteAddress() == null
+ ? "null" : context.remoteAddress().toString())
+ + " principal:"+ (context.principal() == null
+ ? "null" : context.principal())
+ +" op:"+context.operation()
+ + " topoology:"+context.topologyConf().get(Config.TOPOLOGY_NAME));
+ return false;
+ }
}
@@ -11,13 +11,13 @@
* nimbus.authorization.classname: backtype.storm.security.auth.DefaultAuthorizer
*/
public interface IAuthorization {
- /**
- * permit() method is invoked for each incoming Thrift request.
- * @param contrext request context includes info about
- * (1) remote address/subject,
- * (2) operation
- * (3) configuration of targeted topology
- * @return true if the request is authorized, false if reject
- */
- public boolean permit(ReqContext context);
+ /**
+ * permit() method is invoked for each incoming Thrift request.
+ * @param contrext request context includes info about
+ * (1) remote address/subject,
+ * (2) operation
+ * (3) configuration of targeted topology
+ * @return true if the request is authorized, false if reject
+ */
+ public boolean permit(ReqContext context);
}
Oops, something went wrong.

0 comments on commit c75b0c9

Please sign in to comment.