Я уже реализовал аутентификацию пользователей через Ajax, используя AuthenticationEntryPoint и SimpleUrlAuthenticationSuccessHandler.Весенняя безопасность с Ajax - зарегистрировавшаяся информация пользователя
Теперь мне нужно получить зарегистрированное имя пользователя в моей переменной скрипта.
Может ли кто-нибудь помочь мне в этом?
MyAuthenticationSuccessHandler функция
public class MyAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
private Log log = LogFactory.getLog(MyAuthenticationSuccessHandler.class);
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
log.info("point-2-->"+authentication.getName()); //this prints what I need.
// This is actually not an error, but an OK message. It is sent to avoid redirects.
response.sendError(HttpServletResponse.SC_OK);
}
}
Мои JavaScript
$("#login").on('click', function(e) {
e.preventDefault();
$.ajax({url: getHost() + "/j_spring_security_check",
type: "POST",
beforeSend: function(xhr) {
xhr.withCredentials = true;
},
data: $("#loginForm").serialize(),
success: function(response, options) {
// We get a success from the server
//I need to get user name here
},
error: function(result, options) {
// We get a failure from the server...
$(".error").remove();
$('#j_username').before('<div class="error">Login failed, please try again.</div>');
}
});
});
Я уже прилагается все необходимые файлы для другой вопрос. Чтобы проверить их, перейдите по ссылке ниже.
Spring Security; custom-filter and user-service-ref not working together