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