Example usage for org.apache.shiro.subject.support SubjectThreadState bind

List of usage examples for org.apache.shiro.subject.support SubjectThreadState bind

Introduction

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

Prototype

public void bind() 

Source Link

Document

Binds a Subject and org.apache.shiro.mgt.SecurityManager SecurityManager to the ThreadContext so they can be retrieved later by any SecurityUtils.

Usage

From source file:com.github.mizool.technology.web.MockitoExtensions.java

License:Apache License

public Subject mockSubject() {
    SecurityManager securityManager = mock(SecurityManager.class);
    SecurityUtils.setSecurityManager(securityManager);

    Subject subject = mock(Subject.class);
    SubjectThreadState subjectThreadState = new SubjectThreadState(subject);
    subjectThreadState.bind();
    return subject;
}

From source file:de.cosmocode.palava.ipc.security.IpcCallSecurityContext.java

License:Apache License

@Override
public void eventIpcCallCreate(IpcCall call) {
    final Session session = new IpcSessionAdapter(call.getConnection().getSession());
    final Subject subject = new Subject.Builder().session(session).buildSubject();

    final SubjectThreadState state = new SubjectThreadState(subject);
    call.set(CALL_KEY, state);/*  w ww  .  j  a v a 2 s .  c  o m*/

    LOG.trace("Switching thread to subject {} with session {}", subject, session);
    state.bind();

    if (LOG.isDebugEnabled()) {
        if (subject.getPrincipal() == null) {
            LOG.debug("Calling command anonymously");
        } else {
            LOG.debug("Calling command as \"{}\"", subject.getPrincipal());
        }
    }
}

From source file:org.ms123.common.permission.PermissionServiceImpl.java

License:Open Source License

private Subject newSubject(DefaultSecurityManager securityManager) {
    Subject subject = new Subject.Builder(securityManager).buildSubject();
    SubjectThreadState threadState = new SubjectThreadState(subject);
    threadState.bind();
    return subject;
}