[jboss-remoting-commits] JBoss Remoting SVN: r3795 - in remoting3/trunk: jrpp/src/main/java/org/jboss/cx/remoting/jrpp and 1 other directory.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Thu Mar 27 01:50:00 EDT 2008
Author: david.lloyd at jboss.com
Date: 2008-03-27 01:50:00 -0400 (Thu, 27 Mar 2008)
New Revision: 3795
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CommonKeys.java
remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java
Log:
JBREM-907 - authentication retry counter
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CommonKeys.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CommonKeys.java 2008-03-27 05:09:50 UTC (rev 3794)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/CommonKeys.java 2008-03-27 05:50:00 UTC (rev 3795)
@@ -42,6 +42,10 @@
* the local endpoint is anonymous, defaults to {@code null}.
*/
public static final AttributeKey<String> AUTHORIZATION_ID = key("AUTHORIZATION_ID");
+ /**
+ * The maximum number of times to retry authentication before giving up and failing.
+ */
+ public static final AttributeKey<Integer> AUTH_MAX_RETRIES = key("AUTH_MAX_RETRIES");
// TODO: add keys for SSL/TLS
Modified: remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java
===================================================================
--- remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java 2008-03-27 05:09:50 UTC (rev 3794)
+++ remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java 2008-03-27 05:50:00 UTC (rev 3795)
@@ -94,6 +94,8 @@
private final Set<RequestIdentifier> liveRequestSet = CollectionUtil.synchronizedSet(new WeakHashSet<RequestIdentifier>());
private final Set<ServiceIdentifier> liveServiceSet = CollectionUtil.synchronizedSet(new WeakHashSet<ServiceIdentifier>());
+ private int authRetriesLeft = 2;
+
/**
* The negotiated protocol version. Value is set to {@code min(PROTOCOL_VERSION, remote PROTOCOL_VERSION)}.
*/
@@ -139,6 +141,14 @@
public JrppConnection(final AttributeMap attributeMap) {
this.attributeMap = attributeMap;
+ final Integer retries = attributeMap.get(CommonKeys.AUTH_MAX_RETRIES);
+ if (retries != null) {
+ final int actualRetries = retries.intValue();
+ if (actualRetries < 0) {
+ throw new IllegalArgumentException("Value of AUTH_MAX_RETRIES attribute must be greater than or equal to zero");
+ }
+ authRetriesLeft = actualRetries;
+ }
ioHandler = new IoHandlerImpl();
protocolHandler = new RemotingProtocolHandler();
}
@@ -403,6 +413,8 @@
if (state.transitionExclusive(State.FAILED)) {
failureReason = reason;
state.releaseExclusive();
+ ioSession.close();
+ protocolContext.closeSession();
}
}
@@ -792,6 +804,10 @@
write(output, MessageType.AUTH_FAILED);
output.writeUTF("Unable to initiate SASL authentication: " + ex.getMessage());
output.commit();
+ if (authRetriesLeft == 0) {
+ close();
+ }
+ authRetriesLeft--;
}
return;
}
@@ -849,6 +865,11 @@
log.debug("JRPP client failed to authenticate: %s", reason);
final SaslClientFilter oldClientFilter = getSaslClientFilter();
oldClientFilter.destroy();
+ if (authRetriesLeft == 0) {
+ close();
+ return;
+ }
+ authRetriesLeft--;
final CallbackHandler callbackHandler = getClientCallbackHandler(attributeMap);
final Map<String, ?> saslProps = getSaslProperties(attributeMap);
final String[] clientMechs = getClientMechanisms(attributeMap);
@@ -856,7 +877,6 @@
final SaslClient saslClient = Sasl.createSaslClient(clientMechs, authorizationId, "jrpp", remoteName, saslProps, callbackHandler);
final SaslClientFilter saslClientFilter = getSaslClientFilter();
saslClientFilter.setSaslClient(ioSession, saslClient);
- // todo - retry counter - JBREM-907
sendAuthRequest();
return;
}
More information about the jboss-remoting-commits
mailing list