@@ -0,0 +1,2384 @@
+package org.nanoframework.extension.shiro.util;%0A%0Aimport java.util.Collection;%0A%0Aimport org.apache.shiro.SecurityUtils;%0Aimport org.apache.shiro.mgt.DefaultSecurityManager;%0Aimport org.apache.shiro.session.Session;%0Aimport org.apache.shiro.session.mgt.DefaultSessionManager;%0Aimport org.apache.shiro.session.mgt.eis.SessionDAO;%0Aimport org.apache.shiro.subject.PrincipalCollection;%0Aimport org.apache.shiro.subject.Subject;%0Aimport org.apache.shiro.subject.support.DefaultSubjectContext;%0Aimport org.nanoframework.commons.support.logging.Logger;%0Aimport org.nanoframework.commons.support.logging.LoggerFactory;%0Aimport org.nanoframework.commons.util.StringUtils;%0A%0Apublic class ShiroSecurityHelper %7B%0A%09private final Logger LOG = LoggerFactory.getLogger(ShiroSecurityHelper.class);%0A%09private SessionDAO sessionDAO;%0A%09%0A%09public SessionDAO getSessionDAO() %7B%0A%09%09if(sessionDAO == null)%0A%09%09%09sessionDAO = ((DefaultSessionManager) ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getSessionManager()).getSessionDAO();%0A%09%09%0A%09%09return sessionDAO;%0A%09%7D%0A%09%0A%09public String getCurrentUsername() %7B%0A%09%09Subject subject = getSubject();%0A%09%09PrincipalCollection collection = subject.getPrincipals();%0A%09%09if (null != collection && !collection.isEmpty()) %7B%0A%09%09%09return (String) collection.iterator().next();%0A%09%09%7D%0A%09%09%0A%09%09return null;%0A%09%7D%0A%0A%09public Session getSession() %7B%0A%09%09return SecurityUtils.getSubject().getSession();%0A%09%7D%0A%0A%09public String getSessionId() %7B%0A%09%09Session session = getSession();%0A%09%09if (null == session) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return getSession().getId().toString();%0A%09%7D%0A%09%0A%09public Session getSessionByUsername(String username)%7B%0A%09%09Collection%3CSession%3E sessions = getSessionDAO().getActiveSessions();%0A%09%09for(Session session : sessions)%7B%0A%09%09%09if(null != session && StringUtils.equals(String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)), username))%7B%0A%09%09%09%09return session;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09return null;%0A%09%7D%0A%09%0A%09public boolean kickOutUser(String username)%7B%0A%09%09Session session = getSessionByUsername(username);%0A%09%09if(null != session && !StringUtils.equals(String.valueOf(session.getId()), getSessionId()))%7B%0A%09%09%09getSessionDAO().delete(session);%0A%09%09%09LOG.info(%22Success kick out user %7B%7D%22, new Object%5B%5D %7B username %7D);%0A%09%09%09return true;%0A%09%09%7D%0A%09%09%0A%09%09return false;%0A%09%7D%0A%0A%09public boolean hasAuthenticated() %7B%0A%09%09return getSubject().isAuthenticated();%0A%09%7D%0A%0A%09private Subject getSubject() %7B%0A%09%09return SecurityUtils.getSubject();%0A%09%7D%0A%7D%0A

add ShiroSecurityHelper