本文整理匯總了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());
}
示例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();
}
示例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());
}
示例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";
}
示例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;
}
示例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());
}
示例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();
}
示例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;
}
示例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;
}
示例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:/";
}
示例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";
}
示例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";
}
示例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();
}
示例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);
}
示例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;
}