{
if (_required) {
String pathinfo = context.getPathinfo();
Session session = context.getSession();
if (session != null) {
return true;
}
boolean hascookie = false;
if (_use_cookies) {
Cookie cookies[] = context.getRequest().getCookies();
if (cookies != null) {
int n = cookies.length;
for(int i=0; i<n; i++) {
Cookie c = cookies[i];
if (c.getName().equals(_cookie_name)) {
String s = c.getValue();
session = context.getSession(s);
if (session != null) {
context.setSession(session);
hascookie = true;
break;
}
}
}
}
}
if (session == null) {
session = context.createSession();
context.setSession(session);
}
if (_use_cookies && !hascookie) {
Cookie c = new Cookie(_cookie_name, session.getId());
c.setMaxAge(_cookie_lifetime);
c.setSecure(_cookie_secured);
if (_cookie_domain != null) {
c.setDomain(_cookie_domain);
}
if (_cookie_path != null) {
c.setPath(_cookie_path);
}
context.getResponse().addCookie(c);
}
if (_auto_redirect) {
throw new RedirectException(session.getId(), context.getOriginalPathinfo());
} else {
return true;
}
}