use of org.forgerock.openam.radius.server.spi.AccessRequestHandler in project OpenAM by OpenRock.
the class RadiusRequestHandler method run.
@Override
public void run() {
try {
LOG.message("Entering RadiusRequestHandler.run();");
final Packet requestPacket = getValidPacket(buffer);
if (requestPacket == null) {
LOG.message("Leaving RadiusRequestHandler.run(); no requestPacket");
return;
}
// grab the items from the request that we'll need in the RadiusResponseHandler at send time
requestContext.setRequestId(requestPacket.getIdentifier());
requestContext.setRequestAuthenticator(requestPacket.getAuthenticator());
final AccessRequest accessRequest = createAccessRequest(requestPacket);
if (accessRequest == null) {
LOG.message("Leaving RadiusRequestHandler.run(); Packet received was not an AccessRequest packet.");
return;
}
// Instantiate an instance of the AccessRequestHandler class specified in the configuration for this
// client.
final AccessRequestHandler accessRequestHandler = accessRequestHandlerFactory.getAccessRequestHandler(requestContext);
if (accessRequestHandler == null) {
LOG.message("Leaving RadiusRequestHandler.run(); Could not obtain Access Request Handler.");
return;
}
final RadiusRequest request = new RadiusRequest(accessRequest);
final RadiusResponse response = new RadiusResponse();
try {
// The handler will form the response.
accessRequestHandler.handle(request, response, requestContext);
postHandledEvent(request, response, requestContext);
// Send the response to the client.
Packet responsePacket = response.getResponsePacket();
requestContext.send(responsePacket);
resultHandler.handleResult(response);
} catch (final RadiusProcessingException rre) {
// So the processing of the request failed. Is the error recoverable or does the RADIUS server
// need to shutdown?
handleResponseException(rre, requestContext);
}
} catch (final Exception t) {
final StringBuilder sb = new StringBuilder("Exception occured while handling radius request for RADIUS client '").append(getClientName()).append("'. Rejecting access.");
LOG.error(sb.toString(), t);
this.sendAccessReject(requestContext);
return;
}
}
use of org.forgerock.openam.radius.server.spi.AccessRequestHandler in project OpenAM by OpenRock.
the class ConfigLoader method validateClass.
/**
* Validates that the specified class can be loaded and implements the proper interface so that we don't have to do
* that for every request.
*
* @param cfg
* @return the class of the RequestHandler to be used for this client config, or null if the class is invalid.
*/
@SuppressWarnings("unchecked")
private Class validateClass(ClientConfig cfg) {
Class clazz = null;
try {
clazz = Class.forName(cfg.getAccessRequestHandlerClassname());
} catch (final ClassNotFoundException e) {
LOG.error("Unable to load Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
Object inst = null;
try {
inst = InjectorHolder.getInstance(clazz);
} catch (ConfigurationException | ProvisionException e) {
LOG.error("Unable to instantiate Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
AccessRequestHandler handler = null;
try {
handler = (AccessRequestHandler) inst;
} catch (final ClassCastException e) {
LOG.error("Unable to use Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
return clazz;
}
use of org.forgerock.openam.radius.server.spi.AccessRequestHandler in project OpenAM by OpenRock.
the class AccessRequestHandlerFactory method getAccessRequestHandler.
/**
* Factory that creates and returns and instance of the AccessRequestHandler class defined in the config for a
* specific radius client. If the class could not be created then a log message is made.
*
* @param reqCtx - the request context that holds information about the configuration of the RADIUS server at the
* point at which the request was received.
* @return an instance of an <code>AccessRequestHandler</code> object or null if it could not be created.
*/
public AccessRequestHandler getAccessRequestHandler(RadiusRequestContext reqCtx) {
LOG.message("Entering RadiusRequestHandler.getAccessRequestHandler()");
AccessRequestHandler accessRequestHandler = null;
final Class<? extends AccessRequestHandler> accessRequestHandlerClass = reqCtx.getClientConfig().getAccessRequestHandlerClass();
try {
accessRequestHandler = InjectorHolder.getInstance(accessRequestHandlerClass);
} catch (final Exception e) {
final StringBuilder sb = new StringBuilder("Unable to instantiate declared handler class '").append(accessRequestHandlerClass.getName()).append("' for RADIUS client '").append("'. Rejecting access.");
LOG.error(sb.toString(), e);
}
try {
accessRequestHandler.init(reqCtx.getClientConfig().getHandlerConfig());
} catch (final Exception e) {
final StringBuilder sb = new StringBuilder("Unable to initialize declared handler class '").append(accessRequestHandlerClass.getName()).append("' for RADIUS client '").append("'. Rejecting access.");
LOG.error(sb.toString(), e);
accessRequestHandler = null;
}
LOG.message("Leaving RadiusRequestHandler.getAccessRequestHandler()");
return accessRequestHandler;
}
Aggregations