当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationException.getMessage方法代码示例

本文整理汇总了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);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:20,代码来源:CustomFailureHandler.java

示例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);
}
 
开发者ID:pandboy,项目名称:pingguopai,代码行数:22,代码来源:AuthenticationFailureHandler.java

示例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);
    }

}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:31,代码来源:KerberosIdentityProvider.java


注:本文中的org.springframework.security.core.AuthenticationException.getMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。