@DefaultValue("false") @FormParam("stayloggedin") final Boolean stayLoggedIn,
@Context final UriInfo uriInfo) {
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
GraphNode result = new GraphNode(new BNode(), new SimpleMGraph());
result.addProperty(RDF.type, LOGIN.LoginPage);
PlainLiteral failedMessage = new PlainLiteralImpl(
"Username name or password are wrong");
try {
if (authenticationService.authenticateUser(userName,password)) {
Set<LoginListener> tempLoginListenerSet = null;
synchronized(loginListenerSet) {
tempLoginListenerSet = new HashSet<LoginListener>(loginListenerSet);
}
for (Iterator<LoginListener> it = tempLoginListenerSet.iterator(); it.hasNext();) {
LoginListener listener = it.next();
listener.userLoggedIn(userName);
}
ResponseBuilder responseBuilder = Response.fromResponse(
RedirectUtil.createSeeOtherResponse(
referer, uriInfo));
responseBuilder.header(HttpHeaders.SET_COOKIE,
getLoginCookie(userName, password, stayLoggedIn));
return responseBuilder.build();
} else {
result.addProperty(LOGIN.message, failedMessage);
result.addProperty(LOGIN.refererUri, new UriRef(referer));
}
return result;
} catch (NoSuchAgent ex) {
result.addProperty(LOGIN.message, failedMessage);
result.addProperty(LOGIN.refererUri, new UriRef(referer));
return result;
}
}
});
}