Example usage for org.apache.shiro.subject Subject releaseRunAs

List of usage examples for org.apache.shiro.subject Subject releaseRunAs

Introduction

In this page you can find the example usage for org.apache.shiro.subject Subject releaseRunAs.

Prototype

PrincipalCollection releaseRunAs();

Source Link

Document

Releases the current 'run as' (assumed) identity and reverts back to the previous 'pre run as' identity that existed before #runAs runAs was called.

Usage

From source file:com.wegas.core.security.rest.UserController.java

License:MIT License

/**
 * See like an other user specified by it's jpaAccount id. Administrators
 * only./*from   w w  w. j  a  va 2s  .  co  m*/
 *
 * @param accountId jpaAccount id
 */
@POST
@Path("Be/{accountId: [1-9][0-9]*}")
public void runAs(@PathParam("accountId") Long accountId) {
    Subject oSubject = SecurityUtils.getSubject();

    if (oSubject.isRunAs()) {
        oSubject.releaseRunAs(); //@TODO: check shiro version > 1.2.1 (SHIRO-380)
    }
    oSubject.checkRole("Administrator");
    SimplePrincipalCollection subject = new SimplePrincipalCollection(accountId, "jpaRealm");
    oSubject.runAs(subject);
}