當前位置: 首頁>>代碼示例>>Java>>正文


Java AuthenticationException.printStackTrace方法代碼示例

本文整理匯總了Java中org.apache.shiro.authc.AuthenticationException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java AuthenticationException.printStackTrace方法的具體用法?Java AuthenticationException.printStackTrace怎麽用?Java AuthenticationException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authc.AuthenticationException的用法示例。


在下文中一共展示了AuthenticationException.printStackTrace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hello

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
@RequestMapping(value ="/hello")
@ResponseBody
public String hello(){
	Subject subject = SecurityUtils.getSubject();
	UsernamePasswordToken token = new UsernamePasswordToken("zhansan", "123456");
	//--4. 登錄,即身份驗證
	try {
		subject.login(token);
	} catch (AuthenticationException e) {
		e.printStackTrace();
	}
	//System.out.println(subject.isAuthenticated());
	//System.out.println(subject.getPrincipal());
	//-- 6. 退出
	System.out.println(subject.isAuthenticated());
	subject.logout();
	return "hello";
}
 
開發者ID:ranji1221,項目名稱:clemon,代碼行數:19,代碼來源:OltuAuthorizeController.java

示例2: testIniRealm

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * testIniRealm
 * @Description: iniRealm的測試
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 上午11:41:43
 */
@Test
@Ignore
public void testIniRealm(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:inirealm-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	UsernamePasswordToken token=new UsernamePasswordToken("james_shu", "1997admin");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用戶認證狀態:"+subject.isAuthenticated());
	subject.logout();
	System.out.println("用戶當前認證狀態:"+subject.isAuthenticated());
}
 
開發者ID:fuyunwang,項目名稱:ShiroDemo,代碼行數:25,代碼來源:AuthenticationTest.java

示例3: testCustomRealm

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * testCustomRealm
 * @Description: CustomRealm的測試
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 上午11:41:53
 */
@Test
public void testCustomRealm(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:customrealm-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	
	
	UsernamePasswordToken token=new UsernamePasswordToken("BeautifulSoup", "1997admin");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用戶認證狀態:"+subject.isAuthenticated());
	subject.logout();
	System.out.println("用戶當前認證狀態:"+subject.isAuthenticated());
}
 
開發者ID:fuyunwang,項目名稱:ShiroDemo,代碼行數:26,代碼來源:AuthenticationTest.java

示例4: testIniAuthorization

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * testIniAuthorization
 * @Description: 使用inirealm完成授權
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 下午3:05:34
 */
@Test
@Ignore
public void testIniAuthorization(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:permission-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	//首先認證,認證通過之後才能授權
	UsernamePasswordToken token=new UsernamePasswordToken("beautifulsoup", "password");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用戶的認證狀態:"+subject.isAuthenticated());
	boolean isPermitted=subject.isPermittedAll("user:create:01","user:query");
	subject.checkPermissions("user:create:01","user:query");
	System.out.println(isPermitted);
}
 
開發者ID:fuyunwang,項目名稱:ShiroDemo,代碼行數:27,代碼來源:AuthorizationTest.java

示例5: testCustomRealmAuthorization

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * testCustomRealmAuthorization
 * @Description: 使用自定義realm完成授權
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 下午3:05:46
 */
@Test
public void testCustomRealmAuthorization(){
	Factory<SecurityManager> factory=new IniSecurityManagerFactory("classpath:customrealm-shiro.ini");
	SecurityManager securityManager = factory.getInstance();
	SecurityUtils.setSecurityManager(securityManager);
	Subject subject = SecurityUtils.getSubject();
	//首先認證,認證通過之後才能授權
	UsernamePasswordToken token=new UsernamePasswordToken("BeautifulSoup", "1997admin");
	try{
		subject.login(token);
	}catch(AuthenticationException e){
		e.printStackTrace();
	}
	System.out.println("用戶的認證狀態:"+subject.isAuthenticated());
	boolean isPermitted=subject.isPermittedAll("item:query");
	System.out.println(isPermitted);
}
 
開發者ID:fuyunwang,項目名稱:ShiroDemo,代碼行數:25,代碼來源:AuthorizationTest.java

示例6: onLoginFailure

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token,
                                    AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className)
			|| UnknownAccountException.class.getName().equals(className)){
		message = "用戶或密碼錯誤, 請重試.";
	}
	else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	}
	else{
		message = "係統出現點問題,請稍後再試!";
		e.printStackTrace(); // 輸出到控製台
	}
       request.setAttribute(getFailureKeyAttribute(), className);
       request.setAttribute(getMessageParam(), message);
       return true;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:23,代碼來源:FormAuthenticationFilter.java

示例7: onLoginFailure

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request,
                                 ServletResponse response) {
    String className = e.getClass().getName(), message = "";
    if (IncorrectCredentialsException.class.getName().equals(className)
            || UnknownAccountException.class.getName().equals(className)) {
        message = "用戶或密碼錯誤, 請重試.";
    } else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")) {
        message = StringUtils.replace(e.getMessage(), "msg:", "");
    } else {
        message = "係統出現點問題,請稍後再試!";
        e.printStackTrace(); // 輸出到控製台
    }
    request.setAttribute(getFailureKeyAttribute(), className);
    request.setAttribute(getMessageParam(), message);
    return true;
}
 
開發者ID:ansafari,項目名稱:melon,代碼行數:21,代碼來源:FormAuthenticationFilter.java

示例8: onLoginFailure

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token,
                                 AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className)
			|| UnknownAccountException.class.getName().equals(className)){
		message = "用戶或密碼錯誤, 請重試.";
	}
	else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	}
	else{
		message = "係統出現點問題,請稍後再試!";
		e.printStackTrace(); // 輸出到控製台
	}
       request.setAttribute(getFailureKeyAttribute(), className);
       request.setAttribute(getMessageParam(), message);
       return true;
}
 
開發者ID:whatlookingfor,項目名稱:spring-boot-sample,代碼行數:23,代碼來源:FormAuthenticationFilter.java

示例9: doGet

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	System.out.println("login doGet");
	String username = request.getParameter("username");
	if (StringUtils.isEmpty(username)) {
		request.setAttribute("msg", "請輸入賬號!");
		request.getRequestDispatcher("/login.jsp").forward(request, response);
		return;
	}
	String password = request.getParameter("password");
	if (StringUtils.isEmpty(password)) {
		request.setAttribute("msg", "請輸入密碼!");
		request.getRequestDispatcher("/login.jsp").forward(request, response);
		return;
	}
	Subject currentUser = SecurityUtils.getSubject();
	UsernamePasswordToken token = new UsernamePasswordToken(username, password);
	try {
		currentUser.login(token);
		System.out.println("認證成功");
		response.sendRedirect("cms");
	} catch (AuthenticationException e) {
		e.printStackTrace();
		System.out.println("認證失敗");
		request.setAttribute("msg", "賬號密碼錯誤!");
		request.getRequestDispatcher("/login.jsp").forward(request, response);
		return;
	}
}
 
開發者ID:gingerjiang,項目名稱:easycms,代碼行數:29,代碼來源:LoginServlet.java

示例10: main

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
public static void main(String[] args) {
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro-first.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    Subject subject = SecurityUtils.getSubject();

    UsernamePasswordToken token = new UsernamePasswordToken("zhangsan","111111");

    try {
        subject.login(token);
    }catch (AuthenticationException e){
        e.printStackTrace();
    }
    // 是否認證通過
    boolean isAuthenticated = subject.isAuthenticated();

    System.out.println("是否認證通過:" + isAuthenticated);

    // 退出操作
    subject.logout();

    // 是否認證通過
    isAuthenticated = subject.isAuthenticated();

    System.out.println("是否認證通過:" + isAuthenticated);
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:28,代碼來源:ShiroTest.java

示例11: login

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
@RequestMapping("/login")
public String login(@RequestParam("username") String username, @RequestParam("password") String password,
		Model model, RedirectAttributes redirectAttributes) {
	Subject subject = SecurityUtils.getSubject();
	UsernamePasswordToken token = new UsernamePasswordToken(username, password);
	try {
		subject.login(token);// 會交給MyRealm中的doGetAuthenticationInfo方法去驗證
		redirectAttributes.addFlashAttribute("username", username);
		return "redirect:/admin/main";// 重定向到此路徑,後台管理的主頁
	} catch (AuthenticationException e) {
		e.printStackTrace();
		model.addAttribute("message", "用戶名或密碼錯誤");
		return "login";// 返回登錄視圖
	}
}
 
開發者ID:shinyjunjun,項目名稱:myblog,代碼行數:16,代碼來源:BloggerController.java

示例12: logout

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
 * 退出登錄
 * 
 * @return
 */
@RequestMapping(value = "/logout")
public ModelAndView logout() {
	Subject currentUser = SecurityUtils.getSubject();
	try {
           CurrentUserUtil.clearUserCache();//清楚用戶緩存,避免重新授權之類的功能不能直接使用
		currentUser.logout();
	} catch (AuthenticationException e) {
		e.printStackTrace();

	}
       ModelAndView modelView = new ModelAndView();
       modelView.setViewName("redirect:login.html");//默認直接跳轉到登陸界麵
       return modelView;
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:20,代碼來源:MscLoginController.java

示例13: restlogin

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
	 * 前後端分離的情況之下rest風格登錄獲取TGT ST
	 * @Description:TODO
	 * @author:hsj qq:2356899074
	 * @time:2017年12月1日 下午2:49:40
	 * @param req
	 * @param respon
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/restlogin")
	public String restlogin(HttpServletRequest req,HttpServletResponse respon)throws Exception{
//		return RestFulLogin.validateFromCAS("hsjhsj", "hsjhsj");
		        //校驗有沒有username和password
                String username = "hsjhsj";
		        UsernamePasswordToken token = new UsernamePasswordToken("hsjhsj","hsjhsj");
		        //獲取當前的Subject  
		        Subject currentUser = SecurityUtils.getSubject();  
		        try {  
		            //在調用了login方法後,SecurityManager會收到AuthenticationToken,並將其發送給已配置的Realm執行必須的認證檢查  
		            //每個Realm都能在必要時對提交的AuthenticationTokens作出反應  
		            //所以這一步在調用login(token)方法時,它會走到MyRealm.doGetAuthenticationInfo()方法中,具體驗證方式詳見此方法  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證開始");  
		            currentUser.login(token);  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證通過");  
		        }catch(UnknownAccountException uae){  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,未知賬戶");  
		            return "403";
		        }catch(IncorrectCredentialsException ice){  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,錯誤的憑證");  
		            return "403";
		        }catch(LockedAccountException lae){  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,賬戶已鎖定");  
		            return "403";
		        }catch(ExcessiveAttemptsException eae){  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,錯誤次數過多"); 
		            return "403";
		        }catch(AuthenticationException ae){  
		            //通過處理Shiro的運行時AuthenticationException就可以控製用戶登錄失敗或密碼錯誤時的情景  
		            logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,堆棧軌跡如下");  
		            ae.printStackTrace();  
		            return "403";
		        }  
		        //驗證是否登錄成功  
		        if(currentUser.isAuthenticated()){  
		            logger.info("用戶[" + username + "]登錄認證通過(這裏可以進行一些認證通過後的一些係統參數初始化操作)");  
		            return "inde";
		        }else{  
		            token.clear();  
		            return "403";
		        }  
	}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:53,代碼來源:RestController.java

示例14: login

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
@RequestMapping(value="/login", method=RequestMethod.POST)
public String login(String username, String password, HttpServletRequest request){
    System.out.println("-------------------------------------------------------");
    String rand = (String)request.getSession().getAttribute("rand");
    String captcha = WebUtils.getCleanParam(request, "captcha");
    System.out.println("用戶["+username+"]登錄時輸入的驗證碼為["+captcha+"],HttpSession中的驗證碼為["+rand+"]");
    if(!StringUtils.equals(rand, captcha)){
        request.setAttribute("message_login", "驗證碼不正確");
        return InternalResourceViewResolver.FORWARD_URL_PREFIX + "/";
    }
    UsernamePasswordToken token = new UsernamePasswordToken(username, password);
    token.setRememberMe(true);
    System.out.print("為驗證登錄用戶而封裝的Token:");
    System.out.println(ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE));
    //獲取當前的Subject
    Subject currentUser = SecurityUtils.getSubject();
    try {
        //在調用了login方法後,SecurityManager會收到AuthenticationToken,並將其發送給已配置的Realm執行必須的認證檢查
        //每個Realm都能在必要時對提交的AuthenticationTokens作出反應
        //所以這一步在調用login(token)方法時,它會走到MyRealm.doGetAuthenticationInfo()方法中,具體驗證方式詳見此方法
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證開始");
        currentUser.login(token);
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證通過");
    }catch(UnknownAccountException uae){
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,未知賬戶");
        request.setAttribute("message_login", "未知賬戶");
    }catch(IncorrectCredentialsException ice){
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,錯誤的憑證");
        request.setAttribute("message_login", "密碼不正確");
    }catch(LockedAccountException lae){
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,賬戶已鎖定");
        request.setAttribute("message_login", "賬戶已鎖定");
    }catch(ExcessiveAttemptsException eae){
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,錯誤次數過多");
        request.setAttribute("message_login", "用戶名或密碼錯誤次數過多");
    }catch(AuthenticationException ae){
        //通過處理Shiro的運行時AuthenticationException就可以控製用戶登錄失敗或密碼錯誤時的情景
        System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,堆棧軌跡如下");
        ae.printStackTrace();
        request.setAttribute("message_login", "用戶名或密碼不正確");
    }
    //驗證是否登錄成功
    if(currentUser.isAuthenticated()){
        System.out.println("用戶[" + username + "]登錄認證通過(這裏可進行一些認證通過後的係統參數初始化操作)");
        return "main";
    }else{
        token.clear();
        return InternalResourceViewResolver.FORWARD_URL_PREFIX + "/";
    }
}
 
開發者ID:v5java,項目名稱:demo-springmvc-shiro,代碼行數:51,代碼來源:UserController.java

示例15: submitLogin

import org.apache.shiro.authc.AuthenticationException; //導入方法依賴的package包/類
/**
    * 提交登陸入口
    * @param user
    * @param session
    * @param request
    * @return
    */
   @ResponseBody
@RequestMapping(value = "/submitLogin")
public String submitLogin(UserModel user,HttpSession session, HttpServletRequest request,HttpServletResponse response) {

       JSONObject jsonObject =new JSONObject();
	Subject currentUser = SecurityUtils.getSubject();

       if(StringUtil.isNull(user.getUserName()) || StringUtil.isNull(user.getPwd())){//當用戶名或密碼為空時直接跳轉到登陸頁麵
           jsonObject.put("error","0");
           jsonObject.put("code","0");
           jsonObject.put("msg","請輸入用戶名和密碼");
           return jsonObject.toJSONString();
       }
       if(currentUser.isAuthenticated()){//當已經登陸
           jsonObject.put("error","1");
           jsonObject.put("code","2");
           jsonObject.put("msg","用戶已經登錄");
           jsonObject.put("url",redirectUrl(request));
           return jsonObject.toJSONString();
       }
       String encryptPwd= PasswordUtil.encrypt(user.getUserName(), user.getPwd(), PasswordUtil.getStaticSalt());
	UsernamePasswordToken token = new UsernamePasswordToken(user.getUserName(),encryptPwd);
	token.setRememberMe(true);
	try {
		currentUser.login(token);
	} catch (AuthenticationException e) {
		e.printStackTrace();
	}
	if(currentUser.isAuthenticated()){
           jsonObject.put("error","1");
           jsonObject.put("code","3");
           jsonObject.put("msg","登錄成功");
           jsonObject.put("url",redirectUrl(request));
           return jsonObject.toJSONString();
	}else{
           jsonObject.put("error","0");
           jsonObject.put("code","1");
           jsonObject.put("msg","用戶名或密碼錯誤");
           return jsonObject.toJSONString();
	}
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:49,代碼來源:MscLoginController.java


注:本文中的org.apache.shiro.authc.AuthenticationException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。