Example usage for org.apache.shiro.subject.support DelegatingSubject DelegatingSubject

List of usage examples for org.apache.shiro.subject.support DelegatingSubject DelegatingSubject

Introduction

In this page you can find the example usage for org.apache.shiro.subject.support DelegatingSubject DelegatingSubject.

Prototype

public DelegatingSubject(PrincipalCollection principals, boolean authenticated, String host, Session session,
            SecurityManager securityManager) 

Source Link

Usage

From source file:com.app.test.BaseTestCase.java

License:Open Source License

protected static void setUpSecurityUtils(boolean authenticated) throws Exception {

    PowerMockito.spy(SecurityUtils.class);

    DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();

    Subject subject = new DelegatingSubject(null, authenticated, null, null, defaultSecurityManager);

    PowerMockito.doReturn(subject).when(SecurityUtils.class, "getSubject");
}

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  v  a  2 s  . c o  m*/

    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);
}