當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。