net.jradius.client.RadiusClient Java Examples

The following examples show how to use net.jradius.client.RadiusClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JRadiusServerImpl.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Override
public RadiusResponse authenticate(final String username, final String password) throws PreventedException {

    final AttributeList attributeList = new AttributeList();
    
    attributeList.add(new Attr_UserName(username));
    attributeList.add(new Attr_UserPassword(password));

    if (StringUtils.isNotBlank(this.nasIpAddress)) {
        attributeList.add(new Attr_NASIPAddress(this.nasIpAddress));
    }
    if (StringUtils.isNotBlank(this.nasIpv6Address)) {
        attributeList.add(new Attr_NASIPv6Address(this.nasIpv6Address));
    }

    if (this.nasPort != -1) {
        attributeList.add(new Attr_NASPort(this.nasPort));
    }
    if (this.nasPortId != -1) {
        attributeList.add(new Attr_NASPortId(this.nasPortId));
    }
    if (this.nasIdentifier != -1) {
        attributeList.add(new Attr_NASIdentifier(this.nasIdentifier));
    }
    if (this.nasRealPort != -1) {
        attributeList.add(new Attr_NASRealPort(this.nasRealPort));
    }
    if (this.nasPortType != -1) {
        attributeList.add(new Attr_NASPortType(this.nasPortType));
    }
    
    RadiusClient client = null;
    try {
        client = this.radiusClientFactory.newInstance();
        final AccessRequest request = new AccessRequest(client, attributeList);
        final RadiusPacket response = client.authenticate(
                request,
                RadiusClient.getAuthProtocol(this.protocol.getName()),
                this.retries);

        LOGGER.debug("RADIUS response from {}: {}",
                client.getRemoteInetAddress().getCanonicalHostName(),
                response.getClass().getName());

        if (response instanceof AccessAccept) {
            final AccessAccept acceptedResponse = (AccessAccept) response;
           
            return new RadiusResponse(acceptedResponse.getCode(),
                    acceptedResponse.getIdentifier(),
                    acceptedResponse.getAttributes().getAttributeList());
        }
    } catch (final Exception e) {
        throw new PreventedException(e);            
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return null;
}
 
Example #2
Source File: JRadiusServerImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Override
public boolean authenticate(final String username, final String password) throws PreventedException {

    final AttributeList attributeList = new AttributeList();
    attributeList.add(new Attr_UserName(username));
    attributeList.add(new Attr_UserPassword(password));

    RadiusClient client = null;
    try {
        client = this.radiusClientFactory.newInstance();
        LOGGER.debug("Created RADIUS client instance {}", client);

        final AccessRequest request = new AccessRequest(client, attributeList);
        final RadiusPacket response = client.authenticate(
                request,
                RadiusClient.getAuthProtocol(this.protocol.getName()),
                this.retries);

        LOGGER.debug("RADIUS response from {}: {}",
                client.getRemoteInetAddress().getCanonicalHostName(),
                response.getClass().getName());

        if (response instanceof AccessAccept) {
            return true;
        }
    } catch (final Exception e) {
        throw new PreventedException(e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return false;
}
 
Example #3
Source File: RadiusConnectionService.java    From guacamole-client with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of RadiusAuthentictor, configured with
 * parameters specified within guacamole.properties.
 *
 * @param radiusClient
 *     A RadiusClient instance that has been initialized to
 *     communicate with a RADIUS server.
 *
 * @return
 *     A new RadiusAuthenticator instance which has been configured
 *     with parameters from guacamole.properties, or null if
 *     configuration fails.
 *
 * @throws GuacamoleException
 *     If the configuration cannot be read or the inner protocol is
 *     not configured when the client is set up for a tunneled
 *     RADIUS connection.
 */
private RadiusAuthenticator setupRadiusAuthenticator(
        RadiusClient radiusClient) throws GuacamoleException {

    // If we don't have a radiusClient object, yet, don't go any further.
    if (radiusClient == null) {
        logger.error("RADIUS client hasn't been set up, yet.");
        logger.debug("We can't run this method until the RADIUS client has been set up.");
        return null;
    }

    RadiusAuthenticator radAuth = radiusClient.getAuthProtocol(
            confService.getRadiusAuthProtocol().toString());
    
    if (radAuth == null)
        throw new GuacamoleException("Could not get a valid RadiusAuthenticator for specified protocol: " + confService.getRadiusAuthProtocol());

    // If we're using any of the TLS protocols, we need to configure them
    if (radAuth instanceof PEAPAuthenticator || 
        radAuth instanceof EAPTLSAuthenticator || 
        radAuth instanceof EAPTTLSAuthenticator) {

        // Pull TLS configuration parameters from guacamole.properties
        File caFile = confService.getRadiusCAFile();
        String caPassword = confService.getRadiusCAPassword();
        File keyFile = confService.getRadiusKeyFile();
        String keyPassword = confService.getRadiusKeyPassword();

        if (caFile != null) {
            ((EAPTLSAuthenticator)radAuth).setCaFile(caFile.toString());
            ((EAPTLSAuthenticator)radAuth).setCaFileType(confService.getRadiusCAType());
            if (caPassword != null)
                ((EAPTLSAuthenticator)radAuth).setCaPassword(caPassword);
        }

        if (keyPassword != null)
            ((EAPTLSAuthenticator)radAuth).setKeyPassword(keyPassword);

        ((EAPTLSAuthenticator)radAuth).setKeyFile(keyFile.toString());
        ((EAPTLSAuthenticator)radAuth).setKeyFileType(confService.getRadiusKeyType());
        ((EAPTLSAuthenticator)radAuth).setTrustAll(confService.getRadiusTrustAll());
    }

    // If we're using EAP-TTLS, we need to define tunneled protocol
    if (radAuth instanceof EAPTTLSAuthenticator) {
        RadiusAuthenticationProtocol innerProtocol =
                confService.getRadiusEAPTTLSInnerProtocol();
        
        if (innerProtocol == null)
            throw new GuacamoleException("Missing or invalid inner protocol for EAP-TTLS.");

        ((EAPTTLSAuthenticator)radAuth).setInnerProtocol(innerProtocol.toString());
    }

    return radAuth;

}
 
Example #4
Source File: RadiusClientFactory.java    From springboot-shiro-cas-mybatis with MIT License 2 votes vote down vote up
/**
 * Creates a new RADIUS client instance using factory configuration settings.
 *
 * @return New radius client instance.
 * @throws IOException In case the transport method encounters an error.
 */
public RadiusClient newInstance() throws IOException {
    return new RadiusClient(
            this.inetAddress, this.sharedSecret, this.authenticationPort, this.accountingPort, this.socketTimeout);
}
 
Example #5
Source File: RadiusClientFactory.java    From cas4.0.x-server-wechat with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new RADIUS client instance using factory configuration settings.
 *
 * @return New radius client instance.
 * @throws IOException the iO exception
 */
public RadiusClient newInstance() throws IOException {
    return new RadiusClient(
            this.inetAddress, this.sharedSecret, this.authenticationPort, this.accountingPort, this.socketTimeout);
}