本文整理汇总了Java中org.springframework.security.core.AuthenticationException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException.getMessage方法的具体用法?Java AuthenticationException.getMessage怎么用?Java AuthenticationException.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.AuthenticationException
的用法示例。
在下文中一共展示了AuthenticationException.getMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAuthenticationFailure
import org.springframework.security.core.AuthenticationException; //导入方法依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
System.out.println("failure");
String targetUrl = "";
if(exception instanceof BadCredentialsException){
targetUrl = "/login.html?error=" + exception.getMessage();
}
else {
targetUrl = "/login.html?error=" + true;
}
if (response.isCommitted()) {
System.out.println("Internal problem in redirection");
return;
}
redirectStrategy.sendRedirect(request, response, targetUrl);
}
示例2: onAuthenticationFailure
import org.springframework.security.core.AuthenticationException; //导入方法依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
Result result = new Result();
result.setCode(ResultCode.UNAUTHORIZED);
String errorMesg = exception.getMessage();
if (exception instanceof BadCredentialsException) {
errorMesg = "用户名或密码错误";
}
result.setMessage(errorMesg);
//response.sendError(401, );
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
try {
response.getWriter().write(JSON.toJSONString(result));
} catch (IOException ex) {
logger.error(ex.getMessage());
}
//super.onAuthenticationFailure(request, response, exception);
}
示例3: authenticate
import org.springframework.security.core.AuthenticationException; //导入方法依赖的package包/类
@Override
public AuthenticationResponse authenticate(AuthenticationRequest authenticationRequest) throws InvalidCredentialsException, IdentityAccessException {
if (provider == null) {
throw new IdentityAccessException("The Kerberos authentication provider is not initialized.");
}
try {
// perform the authentication
final String username = authenticationRequest.getUsername();
final Object credentials = authenticationRequest.getCredentials();
final String password = credentials != null && credentials instanceof String ? (String) credentials : null;
// perform the authentication
final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, credentials);
logger.debug("Created authentication token " + token.toString());
final Authentication authentication = provider.authenticate(token);
logger.debug("Ran provider.authenticate(token) and returned authentication for " +
"principal={} with name={} and isAuthenticated={}",
authentication.getPrincipal(),
authentication.getName(),
authentication.isAuthenticated());
return new AuthenticationResponse(authentication.getName(), username, expiration, issuer);
} catch (final AuthenticationException e) {
throw new InvalidCredentialsException(e.getMessage(), e);
}
}