사용자 인증에 스프링 보안을 사용하고 있습니다. 커스텀 인증 공급자를 만들었고 공급자로부터 에러 메시지를 어떻게 얻을 수 있는지 궁금합니다. 이것은 내 사용자 지정 인증 공급자에서 인증합니다() 방법 :스프링 로그인시 오류 메시지 표시
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UserProfile profile = userProfileService.findByEmail(authentication.getPrincipal().toString());
if(profile == null){
throw new UsernameNotFoundException(String.format("Invalid credentials", authentication.getPrincipal()));
}
String suppliedPasswordHash = DigestUtils.shaHex(authentication.getCredentials().toString());
if(!profile.getPasswordHash().equals(suppliedPasswordHash)){
throw new BadCredentialsException("Invalid credentials");
}
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(profile, null, profile.getAuthorities());
return token;
}
이 내 형태 :
<form name='f' action="<c:url value='j_spring_security_check' />" method='POST'>
<div id="data-entry-form">
<div class="form-entry">
<label><spring:message code="login.form.label.email"/></label>
<input type='text' name='j_username' value=''>
</div>
<div class="form-entry">
<label><spring:message code="login.form.label.password"/></label>
<input type='password' name='j_password'/>
</div>
<div class="form-entry">
<input type="submit" value="Verzenden"/>
</div>
</div>
어떻게 내 양식에 오류 메시지를받을까요? 로그인 버튼을 누르는 순간부터 스프링이 대신 처리하므로 오류 메시지를 생성 할 수있는 유일한 방법은 authenticate() 메서드입니다.
내가 역 참조했던 모든 변수에 대한 검사를 추가 한 후에도이 솔루션을 사용하여 JSP에서 'NullPointerException'을 많이 사용하고있었습니다. 그래서 더 좋은 솔루션을 발견하고 내 대답으로 게시했습니다. – vadipp