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

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

Introduction

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

Prototype

boolean isRunAs();

Source Link

Document

Returns true if this Subject is 'running as' another identity other than its original one or false otherwise (normal Subject state).

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.// w  w  w. j  ava2  s  . 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);
}