Example usage for org.apache.shiro.session.mgt DelegatingSession DelegatingSession

List of usage examples for org.apache.shiro.session.mgt DelegatingSession DelegatingSession

Introduction

In this page you can find the example usage for org.apache.shiro.session.mgt DelegatingSession DelegatingSession.

Prototype

public DelegatingSession(NativeSessionManager sessionManager, SessionKey key) 

Source Link

Usage

From source file:org.sonatype.nexus.security.NexusHttpAuthenticationFilterTest.java

License:Open Source License

@Before
public void bindSubjectToThread() {
    // setup a simple realm for authc
    SimpleAccountRealm simpleAccountRealm = new SimpleAccountRealm();
    simpleAccountRealm.addAccount("anonymous", "anonymous");
    DefaultSecurityManager securityManager = new DefaultSecurityManager();
    securityManager.setRealm(simpleAccountRealm);

    SecurityUtils.setSecurityManager(securityManager);

    DefaultSessionManager sessionManager = (DefaultSessionManager) securityManager.getSessionManager();
    sessionDAO = new EnterpriseCacheSessionDAO();
    sessionManager.setSessionDAO(sessionDAO);

    simpleSession = new SimpleSession();
    sessionDAO.create(simpleSession);// w ww .  j a va 2  s.c om

    List<PrincipalCollection> principalCollectionList = new ArrayList<PrincipalCollection>();
    principalCollectionList.add(new SimplePrincipalCollection("other Principal", "some-realm"));

    simpleSession.setAttribute(DelegatingSubject.class.getName() + ".RUN_AS_PRINCIPALS_SESSION_KEY",
            principalCollectionList);

    DelegatingSession delegatingSession = new DelegatingSession(sessionManager,
            new DefaultSessionKey(simpleSession.getId()));

    // set the user

    subject = new DelegatingSubject(new SimplePrincipalCollection("anonymous", "realmName"), true, null,
            delegatingSession, securityManager);
    ThreadContext.bind(subject);
}