本文整理汇总了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;
}