* @see org.apache.lenya.ac.AccessController#setupIdentity(org.apache.cocoon.environment.Request)
*/
public void setupIdentity(Request request) throws AccessControlException {
Session session = request.getSession(true);
if (!hasValidIdentity(session)) {
Identity identity = new Identity();
identity.enableLogging(getLogger());
identity.initialize();
String remoteAddress = request.getRemoteAddr();
String clientAddress = request.getHeader("x-forwarded-for");
if (clientAddress != null) {
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(clientAddress);
if (m.find()) {
remoteAddress = m.group();
}
}
getLogger().info("Remote Address to use: [" + remoteAddress + "]");
Machine machine = new Machine(remoteAddress);
IPRange[] ranges = this.accreditableManager.getIPRangeManager().getIPRanges();
for (int i = 0; i < ranges.length; i++) {
if (ranges[i].contains(machine)) {
machine.addIPRange(ranges[i]);
}
}
identity.addIdentifiable(machine);
session.setAttribute(Identity.class.getName(), identity);
}
}