当前位置: 首页>>代码示例>>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;未经允许,请勿转载。