I'm writing an very simple authorization system. I doesn't want to use Spring Security. I want to write very simple auth, based on sessions, cookie and MySQL.
Now, for remember me functionality I want that every time that an page loads, an method will check cookies.
I create init-bean, it works. But when I try read cookie, it fails.
For cookies I need HttpServletRequest. So this is what I do in init-bean:
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("Init-Bean started");
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
// Cookie cookies[] = request.getCookies();
//
// for (Cookie c : cookies) {
// System.out.println(c.toString());
// }
}
I fails on getRequest
I get: Error creating bean with name 'auth': Invocation of init method failed; nested exception is java.lang.NullPointerException
Is there any way get HttpServletRequest from init-bean? Is there any other way to this?
What I want is: Page load, read cookies, if cookie exists -> check if user exists in DB -> start session
Tnx.
P.S I feel lost after mooving from PHP to Spring (in PHP it just global array, 1 row of code). iN asp.net MVC I did it in MvcApplication. But in Java SPRING 3 I has no luck...