summaryrefslogtreecommitdiffstats
path: root/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2011-12-08 21:15:59 -0500
committerAde Lee <alee@redhat.com>2011-12-08 21:15:59 -0500
commit171aaece4f23709d33d180cf36eb3af5e454b0c9 (patch)
tree1485f9f0a7bd10de4ff25030db575dbb8dafae74 /pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java
parentadad2fcee8a29fdb82376fbce07dedb11fccc182 (diff)
downloadpki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.gz
pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.xz
pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.zip
Revert "Formatting"
This reverts commit 32150d3ee32f8ac27118af7c792794b538c78a2f.
Diffstat (limited to 'pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java')
-rw-r--r--pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java76
1 files changed, 41 insertions, 35 deletions
diff --git a/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java b/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java
index 56f620576..1c09ea2c4 100644
--- a/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java
+++ b/pki/base/util/src/com/netscape/cmsutil/radius/RadiusConn.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmsutil.radius;
+
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.DatagramPacket;
@@ -27,9 +28,10 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Properties;
+
/**
- * This class implements RFC2865 - Remote Authentication Dial In User Service
- * (RADIUS), June 2000.
+ * This class implements RFC2865 - Remote Authentication Dial In
+ * User Service (RADIUS), June 2000.
*/
public class RadiusConn {
public static int MAX_RETRIES = 10;
@@ -50,19 +52,20 @@ public class RadiusConn {
private int _maxRetries = MAX_RETRIES;
private SecureRandom _rand = null;
- public RadiusConn(String host1, String host2, int port, String secret,
- int timeout) throws SocketException {
+ public RadiusConn(String host1, String host2, int port, String secret,
+ int timeout) throws SocketException {
this(host1, port, host2, port, secret, timeout, null, null);
}
public RadiusConn(String host, int port, String secret, byte seed[],
- Properties options) throws SocketException {
+ Properties options)
+ throws SocketException {
this(host, port, host, port, secret, DEFAULT_TIMEOUT, seed, options);
}
- public RadiusConn(String host1, int port1, String host2, int port2,
- String secret, int timeout, byte seed[], Properties options)
- throws SocketException {
+ public RadiusConn(String host1, int port1, String host2, int port2,
+ String secret, int timeout, byte seed[], Properties options)
+ throws SocketException {
_host[0] = host1;
_port[0] = port1;
_host[1] = host2;
@@ -70,7 +73,7 @@ public class RadiusConn {
_selected = 0;
_secret = secret;
_options = options;
- _socket = new DatagramSocket();
+ _socket = new DatagramSocket();
_socket.setSoTimeout(timeout * 1000);
if (seed == null) {
_rand = new SecureRandom();
@@ -83,8 +86,9 @@ public class RadiusConn {
_socket.disconnect();
}
- public void authenticate(String name, String password) throws IOException,
- NoSuchAlgorithmException, RejectException, ChallengeException {
+ public void authenticate(String name, String password)
+ throws IOException, NoSuchAlgorithmException,
+ RejectException, ChallengeException {
int retries = 0;
Packet res = null;
@@ -94,14 +98,13 @@ public class RadiusConn {
req.addAttribute(new UserNameAttribute(name));
req.addAttribute(new UserPasswordAttribute(req.getAuthenticator(),
_secret, password));
- req.addAttribute(new NASIPAddressAttribute(InetAddress
- .getLocalHost()));
+ req.addAttribute(new NASIPAddressAttribute(InetAddress.getLocalHost()));
req.addAttribute(new NASPortAttribute(_socket.getLocalPort()));
send(req, _host[_selected], _port[_selected]);
try {
retries++;
- res = receive();
+ res = receive();
if (res instanceof AccessReject) {
throw new RejectException((AccessReject) res);
} else if (res instanceof AccessChallenge) {
@@ -118,22 +121,24 @@ public class RadiusConn {
}
// throw e;
}
-
+
}
- } while (res == null);
+ }
+ while (res == null);
}
public void replyChallenge(String password, ChallengeException ce)
- throws IOException, NoSuchAlgorithmException, RejectException,
- ChallengeException {
+ throws IOException, NoSuchAlgorithmException,
+ RejectException, ChallengeException {
replyChallenge(null, password, ce);
}
- public void replyChallenge(String name, String password,
- ChallengeException ce) throws IOException,
- NoSuchAlgorithmException, RejectException, ChallengeException {
- StateAttribute state = (StateAttribute) ce.getAttributeSet()
- .getAttributeByType(Attribute.STATE);
+ public void replyChallenge(String name, String password,
+ ChallengeException ce)
+ throws IOException, NoSuchAlgorithmException,
+ RejectException, ChallengeException {
+ StateAttribute state = (StateAttribute)
+ ce.getAttributeSet().getAttributeByType(Attribute.STATE);
if (state == null)
throw new IOException("State not found in challenge");
@@ -149,7 +154,7 @@ public class RadiusConn {
req.addAttribute(new NASPortAttribute(_socket.getLocalPort()));
send(req, _host[_selected], _port[_selected]);
- Packet res = receive();
+ Packet res = receive();
if (res instanceof AccessReject) {
throw new RejectException((AccessReject) res);
@@ -159,8 +164,8 @@ public class RadiusConn {
}
public void replyChallenge(String name, String password, String state)
- throws IOException, NoSuchAlgorithmException, RejectException,
- ChallengeException {
+ throws IOException, NoSuchAlgorithmException,
+ RejectException, ChallengeException {
if (state == null)
throw new IOException("State not found in challenge");
AccessRequest req = createAccessRequest();
@@ -173,7 +178,7 @@ public class RadiusConn {
req.addAttribute(new NASPortAttribute(_socket.getLocalPort()));
send(req, _host[_selected], _port[_selected]);
- Packet res = receive();
+ Packet res = receive();
if (res instanceof AccessReject) {
throw new RejectException((AccessReject) res);
@@ -187,12 +192,12 @@ public class RadiusConn {
}
private void send(NASPacket packet, String host, int port)
- throws IOException {
- DatagramPacket dp = new DatagramPacket(new byte[4096], 4096);
+ throws IOException {
+ DatagramPacket dp = new DatagramPacket(new byte[4096], 4096);
- dp.setPort(port);
- dp.setAddress(InetAddress.getByName(host));
- byte data[] = packet.getData();
+ dp.setPort(port);
+ dp.setAddress(InetAddress.getByName(host));
+ byte data[] = packet.getData();
dp.setLength(data.length);
dp.setData(data);
@@ -201,10 +206,11 @@ public class RadiusConn {
trace("Sent " + packet);
}
- private ServerPacket receive() throws IOException {
- DatagramPacket dp = new DatagramPacket(new byte[4096], 4096);
+ private ServerPacket receive()
+ throws IOException {
+ DatagramPacket dp = new DatagramPacket(new byte[4096], 4096);
- _socket.receive(dp);
+ _socket.receive(dp);
byte data[] = dp.getData();
ServerPacket p = PacketFactory.createServerPacket(data);