use of net.jradius.dictionary.Attr_ClientIPAddress 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;
}
Aggregations