}
return resp;
}
public Response doLogin(Stage.Handler stage) {
Request request = stage.getRequest();
Login loginAnnotation = request.getHandler().getMethod().getAnnotation(Login.class);
Subject subject = SecurityUtils.getSubject();
boolean remember = request.getParameterArguments().get(loginAnnotation.rememberMe()) != null ? true : false;
String username = null;
String password = null;
try {
username = request.getParameterArguments().get(loginAnnotation.username()).getValue();
password = request.getParameterArguments().get(loginAnnotation.password()).getValue();
} catch (NullPointerException e) {
List<ControlParameter> parameters = request.getHandler().getParameters();
for (ControlParameter parameter : parameters) {
if (parameter instanceof ContextualParameter) {
if (AuthenticationException.class.isAssignableFrom(parameter.getType())) {
request.getContextualArguments().put((ContextualParameter)parameter, new AuthenticationException(e.getCause()));
return stage.invoke();
}
}
}
//
return new Response.Error(e);
}
try {
subject.login(new UsernamePasswordToken(username, password.toCharArray(), remember));
//
Response resp = stage.invoke();
if (remember && rememberMeSupported) {
RememberMeUtil.forgetIdentity();
RememberMeUtil.rememberSerialized();
}
return resp;
} catch (AuthenticationException e) {
List<ControlParameter> parameters = request.getHandler().getParameters();
for (ControlParameter parameter : parameters) {
if (parameter instanceof ContextualParameter) {
if (AuthenticationException.class.isAssignableFrom(parameter.getType())) {
request.getContextualArguments().put((ContextualParameter)parameter, e);
Response resp = stage.invoke();
if (remember) {
RememberMeUtil.forgetIdentity();
}
return resp;