@Override
public String intercept(ActionInvocation invocation) throws Exception {
createTempJSPFile(invocation);
String errormessage = null;
HibernateManagementAction action = ((HibernateManagementAction)invocation.getAction());
if (publicAccessEnabled) {
action.setPublicAccessEnabled(true);
return invocation.invoke();
}
else if ((httpAuthRoles!=null) || (validIpsHosts!=null)) {
if (httpAuthRoles!=null) {
HttpServletRequest request = ServletActionContext.getRequest();
String roles[] = httpAuthRoles.split(",");
Boolean isValidUser = false;
for (String role : roles) {
if (request.isUserInRole(role)) {
isValidUser = true;
break;
}
}
if (!isValidUser)
errormessage = action.getText("hibernateplugin.httpauth_error");
}
if (validIpsHosts!=null) {
String userIp = ServletActionContext.getRequest().getRemoteAddr();
if (ServletActionContext.getRequest().getHeader("X-Forwarded-For")!=null)
userIp = ServletActionContext.getRequest().getHeader("X-Forwarded-For");
String userHost = ServletActionContext.getRequest().getRemoteHost();
if (userHost.equals(userIp))
userHost = InetAddress.getByAddress(new byte[]{127,0,0,1}).getHostName();
String ipshosts[] = validIpsHosts.split(",");
Boolean isValidIp = ArrayUtils.contains(ipshosts, userIp);
Boolean isValidHost = ArrayUtils.contains(ipshosts, userHost);
if ( (!isValidIp) && (!isValidHost) )
errormessage = action.getText("hibernateplugin.iphost_error");
}
}
else {
errormessage = action.getText("hibernateplugin.public_access_disabled");
}
if (errormessage!=null) {
throw new SecurityException(errormessage);
} else {