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


Java Subject.logout方法代码示例

本文整理汇总了Java中org.apache.shiro.subject.Subject.logout方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.logout方法的具体用法?Java Subject.logout怎么用?Java Subject.logout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.subject.Subject的用法示例。


在下文中一共展示了Subject.logout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: responseApprovalDeny

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
protected void responseApprovalDeny() throws IOException, OAuthSystemException {

        final OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND)
                .setError(OAuthError.CodeResponse.ACCESS_DENIED)
                .setErrorDescription("User denied access")
                .location(clientDetails().getRedirectUri())
                .setState(oauthRequest.getState())
                .buildQueryMessage();
        LOG.debug("'ACCESS_DENIED' response: {}", oAuthResponse);

        WebUtils.writeOAuthQueryResponse(response, oAuthResponse);

        //user logout when deny
        final Subject subject = SecurityUtils.getSubject();
        subject.logout();
        LOG.debug("After 'ACCESS_DENIED' call logout. user: {}", subject.getPrincipal());
    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:18,代码来源:AbstractAuthorizeHandler.java

示例2: testHelloWorld

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Test
public void testHelloWorld() {
    //1、获取 SecurityManager 工厂,此处使用 Ini 配置文件初始化 SecurityManager
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    //2、得到 SecurityManager 实例 并绑定给 SecurityUtils

    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    //3、得到 Subject 及创建用户名/密码身份验证 Token(即用户身份/凭证)
    Subject subject = SecurityUtils.getSubject();

    UsernamePasswordToken token = new UsernamePasswordToken("test", "234");

    try {
        //4、登录,即身份验证
        subject.login(token);
    } catch (AuthenticationException e) {
        //5、身份验证失败
    }
    Assert.assertEquals(true, subject.isAuthenticated()); //断言用户已经登录
    //6、退出
    subject.logout();
}
 
开发者ID:easymall,项目名称:easymall,代码行数:25,代码来源:LoginTest.java

示例3: responseApprovalDeny

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
protected void responseApprovalDeny() throws IOException, OAuthSystemException {

        final OAuthResponse oAuthResponse = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND)
                .setError(OAuthError.CodeResponse.ACCESS_DENIED)
                .setErrorDescription("User denied access")
                .location(clientDetails().redirectUri())
                .setState(oauthRequest.getState())
                .buildQueryMessage();
        LOG.debug("'ACCESS_DENIED' response: {}", oAuthResponse);

        WebUtils.writeOAuthQueryResponse(response, oAuthResponse);

        //user logout when deny
        final Subject subject = SecurityUtils.getSubject();
        subject.logout();
        LOG.debug("After 'ACCESS_DENIED' call logout. user: {}", subject.getPrincipal());
    }
 
开发者ID:monkeyk,项目名称:oauth2-shiro-redis,代码行数:18,代码来源:AbstractAuthorizeHandler.java

示例4: hello

import org.apache.shiro.subject.Subject; //导入方法依赖的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

示例5: onAccessDenied

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
		ServletResponse response) throws Exception {
	//先退出
	Subject subject = getSubject(request, response);
	subject.logout();
	/**
	 * shiro保存上次请求地址:
	 * WebUtils.getSavedRequest(request);
	 * 然后在需要使用的地方:String url = WebUtils.getSavedRequest(request).getRequestUrl();
	 */
	//判断是不是Ajax请求
	if (ShiroUtils.isAjax(request) ) {
		Map<String, Object> result = new HashMap<String, Object>();
		logger.debug("当前用户已经被踢出,并且是Ajax请求!");
		result.put("status", "403");
		result.put("message", "您已经被踢出,请重新登录!");
		result.put("url", ShiroUtils.LOGIN_URL);
		ShiroUtils.writeJson(response, result);
	}else
	{
		WebUtils.getSavedRequest(request);
		//再重定向
		WebUtils.issueRedirect(request, response, ShiroUtils.LOGIN_URL);
	}
	return false;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:28,代码来源:KickoutAuthFilter.java

示例6: testCustomRealm

import org.apache.shiro.subject.Subject; //导入方法依赖的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

示例7: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
public void logout() {
  Subject currentUser = getSubject();
  if (currentUser == null) {
    return;
  }

  try {
    logger.info("Logging out " + currentUser.getPrincipal());
    currentUser.logout();
  } catch (ShiroException e) {
    logger.info(e.getMessage(), e);
    throw new GemFireSecurityException(e.getMessage(), e);
  }
  // clean out Shiro's thread local content
  ThreadContext.remove();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:IntegratedSecurityService.java

示例8: onPreHandle

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
	Subject subject = SecurityUtils.getSubject();
	try {
		subject.logout();
	} catch (SessionException ise) {
		LOGGER.info("Encountered session exception during logout.  This can generally safely be ignored.", ise);
	}
	HTTP.writeAsJSON(response,
			MessageBean.STATUS, HTTP.Status.OK.toInt(),
			MessageBean.MESSAGE, Messages.Status.OK.toString()) ;
	return false;
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:14,代码来源:BearerTokenRevokeFilter.java

示例9: preHandle

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
    Subject subject = getSubject(request, response);
    String redirectUrl = getRedirectUrl(request, response, subject);
    //try/catch added for SHIRO-298:
    try {
        subject.logout();
    } catch (SessionException ise) {
        log.debug("Encountered session exception during logout.  This can generally safely be ignored.", ise);
    }
    issueRedirect(request, response, redirectUrl);
    return false;
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:14,代码来源:ForceLogoutFilter.java

示例10: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 用户退出操作
 *
 * @return
 */
@RequestMapping(value = "logout", method = RequestMethod.GET)
public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
	session.removeAttribute(Principal.PRINCIPAL_ATTRIBUTE_NAME);
	CookieUtils.removeCookie(request, response, COOKIE_USERNAME);
	Subject subject = SecurityUtils.getSubject();
	subject.logout();
	return "redirect:/";
}
 
开发者ID:wenjian-li,项目名称:spring_mybatis_shiro,代码行数:14,代码来源:LoginController.java

示例11: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@RequestMapping("/logout")
public String logout() {
    Subject subject = SecurityUtils.getSubject();
    if (subject != null) {
        subject.logout();
    }
    return "login";
}
 
开发者ID:fuyunwang,项目名称:SpringBootShiro,代码行数:9,代码来源:IndexController.java

示例12: loginOut

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@RequestMapping("/login_out")
public String loginOut(HttpServletRequest request){
	
	Subject subject = SecurityUtils.getSubject();
	subject.logout();
	
	return "redirect:/login";
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:9,代码来源:LoginController.java

示例13: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 退出
 * @return {Result}
 */
@PostMapping("/logout")
@ResponseBody
public Object logout() {
    logger.info("登出");
    Subject subject = SecurityUtils.getSubject();
    subject.logout();
    return renderSuccess();
}
 
开发者ID:TomChen001,项目名称:xmanager,代码行数:13,代码来源:LoginController.java

示例14: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@RequestMapping(value = "/user/logout",method = RequestMethod.GET)
@ApiOperation(value = "退出登录")
public Result<Object> logout(){

    Subject subject = SecurityUtils.getSubject();
    subject.logout();
    return new ResultUtil<Object>().setData(null);
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:9,代码来源:UserController.java

示例15: onAccessDenied

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
  protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
  	//退出
Subject subject = getSubject(request, response);
subject.logout();
return  Boolean.FALSE;
  }
 
开发者ID:wjggwm,项目名称:webside,代码行数:8,代码来源:KickoutSessionFilter.java


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