Search in sources :

Example 1 with Roles

use of org.obiba.mica.security.Roles in project mica2 by obiba.

the class CurrentSessionResource method get.

@GET
public Mica.SessionDto get() {
    Subject subject = SecurityUtils.getSubject();
    Mica.SessionDto.Builder builder = // 
    Mica.SessionDto.newBuilder().setUsername(subject.getPrincipal().toString());
    // 
    List<String> roles = // 
    Arrays.asList(Roles.MICA_ADMIN, Roles.MICA_REVIEWER, Roles.MICA_EDITOR, Roles.MICA_DAO, Roles.MICA_USER);
    boolean[] result = subject.hasRoles(roles);
    IntStream.range(0, result.length).filter(i -> result[i]).forEach(i -> builder.addRoles(roles.get(i)));
    return builder.build();
}
Also used : IntStream(java.util.stream.IntStream) InvalidSessionException(org.apache.shiro.session.InvalidSessionException) Arrays(java.util.Arrays) GET(javax.ws.rs.GET) Roles(org.obiba.mica.security.Roles) Path(javax.ws.rs.Path) NewCookie(javax.ws.rs.core.NewCookie) Session(org.apache.shiro.session.Session) List(java.util.List) Component(org.springframework.stereotype.Component) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Subject(org.apache.shiro.subject.Subject) Mica(org.obiba.mica.web.model.Mica) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) SecurityUtils(org.apache.shiro.SecurityUtils) DELETE(javax.ws.rs.DELETE) Subject(org.apache.shiro.subject.Subject) GET(javax.ws.rs.GET)

Aggregations

Arrays (java.util.Arrays)1 List (java.util.List)1 IntStream (java.util.stream.IntStream)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 NewCookie (javax.ws.rs.core.NewCookie)1 Response (javax.ws.rs.core.Response)1 SecurityUtils (org.apache.shiro.SecurityUtils)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 InvalidSessionException (org.apache.shiro.session.InvalidSessionException)1 Session (org.apache.shiro.session.Session)1 Subject (org.apache.shiro.subject.Subject)1 Roles (org.obiba.mica.security.Roles)1 Mica (org.obiba.mica.web.model.Mica)1 Component (org.springframework.stereotype.Component)1