Search in sources :

Example 1 with Attr_NASIPAddress

use of net.jradius.dictionary.Attr_NASIPAddress in project cas by apereo.

the class JRadiusServerImpl method authenticate.

@Override
public RadiusResponse authenticate(final String username, final String password) throws Exception {
    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 (StringUtils.isNotBlank(this.nasIdentifier)) {
        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 List<RadiusAttribute> attributes = response.getAttributes().getAttributeList();
            LOGGER.debug("Radius response code [{}] accepted with attributes [{}] and identifier [{}]", response.getCode(), attributes, response.getIdentifier());
            return new RadiusResponse(response.getCode(), response.getIdentifier(), attributes);
        }
        LOGGER.debug("Response is not recognized");
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return null;
}
Also used : Attr_NASRealPort(net.jradius.dictionary.vsa_redback.Attr_NASRealPort) RadiusClient(net.jradius.client.RadiusClient) AccessRequest(net.jradius.packet.AccessRequest) AttributeList(net.jradius.packet.attribute.AttributeList) Attr_NASPort(net.jradius.dictionary.Attr_NASPort) Attr_NASIPAddress(net.jradius.dictionary.Attr_NASIPAddress) Attr_NASPortId(net.jradius.dictionary.Attr_NASPortId) Attr_UserPassword(net.jradius.dictionary.Attr_UserPassword) Attr_NASPortType(net.jradius.dictionary.Attr_NASPortType) RadiusAttribute(net.jradius.packet.attribute.RadiusAttribute) RadiusPacket(net.jradius.packet.RadiusPacket) Attr_UserName(net.jradius.dictionary.Attr_UserName) Attr_NASIPv6Address(net.jradius.dictionary.Attr_NASIPv6Address) Attr_NASIdentifier(net.jradius.dictionary.Attr_NASIdentifier) AccessAccept(net.jradius.packet.AccessAccept)

Example 2 with Attr_NASIPAddress

use of net.jradius.dictionary.Attr_NASIPAddress in project cas by apereo.

the class AbstractRadiusServer method authenticate.

@Override
public final CasRadiusResponse authenticate(final String username, final String password, final Optional state) throws Exception {
    val attributeList = new AttributeList();
    if (StringUtils.isNotBlank(username)) {
        attributeList.add(new Attr_UserName(username));
    }
    if (StringUtils.isNotBlank(password)) {
        attributeList.add(new Attr_UserPassword(password));
    }
    val clientInfo = ClientInfoHolder.getClientInfo();
    if (clientInfo != null) {
        val clientIpAddress = clientInfo.getClientIpAddress();
        val clientIpAttribute = new Attr_ClientIPAddress(clientIpAddress);
        LOGGER.debug("Adding client IP address attribute [{}]", clientIpAttribute);
        attributeList.add(clientIpAttribute);
    }
    state.ifPresent(value -> attributeList.add(new Attr_State(Serializable.class.cast(value))));
    if (StringUtils.isNotBlank(configurationContext.getNasIpAddress())) {
        attributeList.add(new Attr_NASIPAddress(configurationContext.getNasIpAddress()));
    }
    if (StringUtils.isNotBlank(configurationContext.getNasIpv6Address())) {
        attributeList.add(new Attr_NASIPv6Address(configurationContext.getNasIpv6Address()));
    }
    if (configurationContext.getNasPort() != -1) {
        attributeList.add(new Attr_NASPort(configurationContext.getNasPort()));
    }
    if (configurationContext.getNasPortId() != -1) {
        attributeList.add(new Attr_NASPortId(configurationContext.getNasPortId()));
    }
    if (StringUtils.isNotBlank(configurationContext.getNasIdentifier())) {
        attributeList.add(new Attr_NASIdentifier(configurationContext.getNasIdentifier()));
    }
    if (configurationContext.getNasRealPort() != -1) {
        attributeList.add(new Attr_NASRealPort(configurationContext.getNasRealPort()));
    }
    if (configurationContext.getNasPortType() != -1) {
        attributeList.add(new Attr_NASPortType(configurationContext.getNasPortType()));
    }
    val client = configurationContext.getRadiusClientFactory().newInstance();
    try {
        val request = new AccessRequest(client, attributeList);
        LOGGER.debug("RADIUS access request prepared as [{}]", request.toString(true, true));
        val response = authenticateRequest(client, request);
        LOGGER.debug("RADIUS response from [{}]: [{}] as [{}]", client.getRemoteInetAddress().getCanonicalHostName(), response.getClass().getName(), response.toString(true, true));
        if (response instanceof AccessAccept || response instanceof AccessChallenge) {
            val attributes = response.getAttributes().getAttributeList();
            LOGGER.debug("Radius response code [{}] accepted with attributes [{}] and identifier [{}]", response.getCode(), attributes, response.getIdentifier());
            return new CasRadiusResponse(response.getCode(), response.getIdentifier(), attributes);
        }
        LOGGER.warn("Response [{}] is not recognized", response);
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return null;
}
Also used : lombok.val(lombok.val) Serializable(java.io.Serializable) Attr_NASRealPort(net.jradius.dictionary.vsa_redback.Attr_NASRealPort) CasRadiusResponse(org.apereo.cas.adaptors.radius.CasRadiusResponse) AccessRequest(net.jradius.packet.AccessRequest) AttributeList(net.jradius.packet.attribute.AttributeList) Attr_NASPort(net.jradius.dictionary.Attr_NASPort) Attr_NASIPAddress(net.jradius.dictionary.Attr_NASIPAddress) Attr_ClientIPAddress(net.jradius.dictionary.Attr_ClientIPAddress) Attr_NASPortId(net.jradius.dictionary.Attr_NASPortId) Attr_UserPassword(net.jradius.dictionary.Attr_UserPassword) Attr_NASPortType(net.jradius.dictionary.Attr_NASPortType) Attr_UserName(net.jradius.dictionary.Attr_UserName) Attr_NASIPv6Address(net.jradius.dictionary.Attr_NASIPv6Address) Attr_State(net.jradius.dictionary.Attr_State) AccessChallenge(net.jradius.packet.AccessChallenge) Attr_NASIdentifier(net.jradius.dictionary.Attr_NASIdentifier) AccessAccept(net.jradius.packet.AccessAccept)

Aggregations

Attr_NASIPAddress (net.jradius.dictionary.Attr_NASIPAddress)2 Attr_NASIPv6Address (net.jradius.dictionary.Attr_NASIPv6Address)2 Attr_NASIdentifier (net.jradius.dictionary.Attr_NASIdentifier)2 Attr_NASPort (net.jradius.dictionary.Attr_NASPort)2 Attr_NASPortId (net.jradius.dictionary.Attr_NASPortId)2 Attr_NASPortType (net.jradius.dictionary.Attr_NASPortType)2 Attr_UserName (net.jradius.dictionary.Attr_UserName)2 Attr_UserPassword (net.jradius.dictionary.Attr_UserPassword)2 Attr_NASRealPort (net.jradius.dictionary.vsa_redback.Attr_NASRealPort)2 AccessAccept (net.jradius.packet.AccessAccept)2 AccessRequest (net.jradius.packet.AccessRequest)2 AttributeList (net.jradius.packet.attribute.AttributeList)2 Serializable (java.io.Serializable)1 lombok.val (lombok.val)1 RadiusClient (net.jradius.client.RadiusClient)1 Attr_ClientIPAddress (net.jradius.dictionary.Attr_ClientIPAddress)1 Attr_State (net.jradius.dictionary.Attr_State)1 AccessChallenge (net.jradius.packet.AccessChallenge)1 RadiusPacket (net.jradius.packet.RadiusPacket)1 RadiusAttribute (net.jradius.packet.attribute.RadiusAttribute)1