use of org.apache.shiro.session.Session in project neo4j by neo4j.
the class ShiroSubjectFactory method createSubject.
@Override
public Subject createSubject(SubjectContext context) {
SecurityManager securityManager = context.resolveSecurityManager();
Session session = context.resolveSession();
boolean sessionCreationEnabled = context.isSessionCreationEnabled();
PrincipalCollection principals = context.resolvePrincipals();
boolean authenticated = context.resolveAuthenticated();
String host = context.resolveHost();
ShiroAuthenticationInfo authcInfo = (ShiroAuthenticationInfo) context.getAuthenticationInfo();
return new ShiroSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager, authcInfo.getAuthenticationResult());
}
use of org.apache.shiro.session.Session in project tesla by linking12.
the class SessionService method list.
public List<UserOnline> list() {
List<UserOnline> list = new ArrayList<>();
Collection<Session> sessions = sessionDAO.getActiveSessions();
for (Session session : sessions) {
UserOnline userOnline = new UserOnline();
if (session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY) == null) {
continue;
} else {
SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
String userName = principalCollection.getRealmNames().iterator().next();
userOnline.setUsername(userName);
}
userOnline.setId((String) session.getId());
userOnline.setHost(session.getHost());
userOnline.setStartTimestamp(session.getStartTimestamp());
userOnline.setLastAccessTime(session.getLastAccessTime());
userOnline.setTimeout(session.getTimeout());
list.add(userOnline);
}
return list;
}
use of org.apache.shiro.session.Session in project moon by gentoo111.
the class UserUtil method getSession.
public static Session getSession() {
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
return session;
}
use of org.apache.shiro.session.Session in project fruit-manage by liuzhaozhao.
the class LoginController method auth.
/**
* 登录操作
*/
public void auth() {
Object uid = getSessionAttr(Constant.SESSION_UID);
if (uid != null) {
renderJson(new DataResult<>(DataResult.CODE_SUCCESS, "登录成功"));
}
String userName = getPara("username");
String password = StringUtils.isNotBlank(getPara("password")) ? HashKit.md5(getPara("password")) : getPara("password");
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
try {
subject.login(token);
Session session = subject.getSession();
session.setAttribute(Constant.SESSION_UID, User.dao.getUser(userName).getId());
renderNull();
} catch (Exception e) {
if (StringUtils.isAllBlank(userName, password)) {
renderLogin("身份认证失败");
} else {
renderErrorText("用户名或密码错误");
}
}
}
use of org.apache.shiro.session.Session in project spring-boot-starter-samples by vindell.
the class AuthzLoginController method switchRole.
@ApiOperation(value = "switchRole", notes = "切换角色")
@ApiImplicitParams({ @ApiImplicitParam(name = "roleid", value = "角色ID", dataType = "String") })
// @BusinessLog(module = Constants.Module.LOGIN, business = "切换角色", opt = BusinessType.LOGIN)
@RequestMapping(value = "switchRole", method = { RequestMethod.POST, RequestMethod.GET })
public String switchRole(String roleid) {
try {
AuthzLoginModel principal = SubjectUtils.getPrincipal(AuthzLoginModel.class);
Session session = SubjectUtils.getSession();
if (StringUtils.isNotBlank(roleid) && (!StringUtils.equals(roleid, principal.getRoleid()))) {
/*// 切换当前的角色信息
getUser().setJsdm(jsdm);
// 刷新shiro缓存
AccountRealm shiroRealm = ServiceFactory.getService(DefaultAccountRealm.class);
shiroRealm.clearAuthorizationCache();*/
// 刷新shiro缓存
// 删除用户数据范围标识
session.removeAttribute("");
}
} catch (Exception e) {
logException(this, e);
}
return "redirect:/index";
}
Aggregations