Skip to content

Commit

Permalink
Allow the auth protocol to be set on RadiusClient.
Browse files Browse the repository at this point in the history
Pump version to 1.0.2
  • Loading branch information
ctran committed Jan 4, 2012
1 parent b387d90 commit 7ea6c47
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ doc/apidoc
target
.settings
.classpath
.project
.project
20 changes: 19 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.tinyradius</groupId>
<artifactId>tinyradius</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.2</version>
<packaging>jar</packaging>
<name>TinyRadius Java Radius Library</name>
<description>
Expand Down Expand Up @@ -37,4 +37,22 @@
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
40 changes: 27 additions & 13 deletions src/main/java/org/tinyradius/util/RadiusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public RadiusClient(RadiusEndpoint client) {
* retries)
*/
public synchronized boolean authenticate(String userName, String password) throws IOException, RadiusException {
return authenticate(userName, password, AccessRequest.AUTH_PAP);
return authenticate(userName, password, authProtocol);
}

/**
Expand All @@ -80,7 +80,7 @@ public synchronized boolean authenticate(String userName, String password) throw
* user name
* @param password
* password
* @param authProtocol
* @param protocol
* either {@link AccessRequest#AUTH_PAP} or {@link AccessRequest#AUTH_CHAP}
* @return true if authentication is successful, false otherwise
* @exception RadiusException
Expand All @@ -89,9 +89,9 @@ public synchronized boolean authenticate(String userName, String password) throw
* communication error (after getRetryCount()
* retries)
*/
public synchronized boolean authenticate(String userName, String password, String authProtocol) throws IOException, RadiusException {
public synchronized boolean authenticate(String userName, String password, String protocol) throws IOException, RadiusException {
AccessRequest request = new AccessRequest(userName, password);
request.setAuthProtocol(authProtocol);
request.setAuthProtocol(protocol);
RadiusPacket response = authenticate(request);
return response.getPacketType() == RadiusPacket.ACCESS_ACCEPT;
}
Expand Down Expand Up @@ -148,8 +148,8 @@ public synchronized RadiusPacket account(AccountingRequest request) throws IOExc
* Closes the socket of this client.
*/
public void close() {
if (socket != null)
socket.close();
if (serverSocket != null)
serverSocket.close();
}

/**
Expand Down Expand Up @@ -256,8 +256,8 @@ public void setSocketTimeout(int socketTimeout) throws SocketException {
if (socketTimeout < 1)
throw new IllegalArgumentException("socket tiemout must be positive");
this.socketTimeout = socketTimeout;
if (socket != null)
socket.setSoTimeout(socketTimeout);
if (serverSocket != null)
serverSocket.setSoTimeout(socketTimeout);
}

/**
Expand All @@ -281,6 +281,19 @@ public int getAcctPort() {
return acctPort;
}

/**
* Set the Radius authentication protocol.
*
* @see AccessRequest#AUTH_CHAP
* @see AccessRequest#AUTH_PAP
*
* @param protocol
* the protocol, PAP or CHAP
*/
public void setAuthProtocol(String protocol) {
this.authProtocol = protocol;
}

/**
* Sends a Radius packet to the server and awaits an answer.
*
Expand Down Expand Up @@ -353,11 +366,11 @@ public static RadiusPacket communicate(RadiusEndpoint remoteServer, RadiusPacket
* @throws SocketException
*/
protected DatagramSocket getSocket() throws SocketException {
if (socket == null) {
socket = new DatagramSocket();
socket.setSoTimeout(getSocketTimeout());
if (serverSocket == null) {
serverSocket = new DatagramSocket();
serverSocket.setSoTimeout(getSocketTimeout());
}
return socket;
return serverSocket;
}

/**
Expand Down Expand Up @@ -398,9 +411,10 @@ protected RadiusPacket makeRadiusPacket(DatagramPacket packet, RadiusPacket requ
private int acctPort = 1813;
private String hostName = null;
private String sharedSecret = null;
private DatagramSocket socket = null;
private DatagramSocket serverSocket = null;
private int retryCount = 3;
private int socketTimeout = 3000;
private String authProtocol = AccessRequest.AUTH_PAP;
private static Log logger = LogFactory.getLog(RadiusClient.class);

}

0 comments on commit 7ea6c47

Please sign in to comment.