[opencms-dev] OPENCMS 9.5 listener Class
allanbsantos
allanbsantos at hotmail.com
Thu Feb 25 16:11:57 CET 2016
Hi guys.
I need to get user IP when session is create. But work only when acess
OpenCMS Admin noto in site. Any Ideal? have OpenCMS any method to get ip on
sessioncreate? Need i extend OpenCmsListener?
I try it:
<listener>
<description>sessionListener</description>
<listener-class>com.site.listener.SessionListener</listener-class>
</listener>
My classe:
public class SessionListener implements HttpSessionListener,
ServletRequestListener {
private int sessionCount =0;
private String sourceIp;
private String clienteIp;
HttpServletRequest request;
@Override
public void sessionCreated(HttpSessionEvent event) {
System.out.println("Session Criada.....000000000000");
//synchronized (this) {
sessionCount++;
sourceIp = request.getRemoteAddr();
clienteIp = request.getLocalAddr();
Date today;
String dataHora;
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
today = new Date();
dataHora = formatter.format(today);
System.out.println("sessionCount=" + sessionCount);
System.out.println("sourceIp=" + sourceIp );
System.out.println("sessionCount= " + clienteIp);
System.out.println("dataHora" + dataHora);
//}
}
@Override
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("Session destruida.....000000000000");
synchronized (this) {
sessionCount--;
sourceIp = request.getRemoteAddr();
clienteIp = request.getLocalAddr();
Date today;
String dataHora;
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
today = new Date();
dataHora = formatter.format(today);
}
}
@Override
public void requestDestroyed(ServletRequestEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void requestInitialized(ServletRequestEvent event) {
request = (HttpServletRequest) event.getServletRequest();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20160225/4611259d/attachment.htm>
More information about the opencms-dev
mailing list