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

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

Introduction

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

Prototype

PrincipalCollection getPreviousPrincipals();

Source Link

Document

Returns the previous 'pre run as' identity of this Subject before assuming the current #runAs runAs identity, or null if this Subject is not operating under an assumed identity (normal state).

Usage

From source file:net.echinopsii.ariane.community.core.directory.wat.rest.organisational.TeamEndpoint.java

License:Open Source License

@GET
public Response displayAllTeams() {
    Subject subject = SecurityUtils.getSubject();
    log.debug("[{}-{}] get teams",
            new Object[] { Thread.currentThread().getId(), subject.getPreviousPrincipals() });
    if (subject.hasRole("orgadmin") || subject.hasRole("orgreviewer")
            || subject.isPermitted("dirComOrgTeam:display") || subject.hasRole("Jedi")
            || subject.isPermitted("universe:zeone")) {
        em = DirectoryJPAProviderConsumer.getInstance().getDirectoryJpaProvider().createEM();
        final HashSet<Team> results = new HashSet(
                em.createQuery("SELECT DISTINCT t FROM Team t LEFT JOIN FETCH t.osInstances ORDER BY t.id",
                        Team.class).getResultList());
        String result;//from  ww  w .j a v a  2  s .  c  o  m
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        Response ret = null;
        try {
            TeamJSON.manyTeams2JSON(results, outStream);
            result = ToolBox.getOuputStreamContent(outStream, "UTF-8");
            ret = Response.status(Status.OK).entity(result).build();
        } catch (Exception e) {
            log.error(e.getMessage());
            e.printStackTrace();
            result = e.getMessage();
            ret = Response.status(Status.INTERNAL_SERVER_ERROR).entity(result).build();
        } finally {
            em.close();
            return ret;
        }
    } else {
        return Response.status(Status.UNAUTHORIZED)
                .entity("You're not authorized to display teams. Contact your administrator.").build();
    }
}