Search in sources :

Example 1 with Subject

use of org.obiba.shiro.realm.ObibaRealm.Subject in project mica2 by obiba.

the class CommentDtos method asDto.

@NotNull
Mica.CommentDto asDto(@NotNull Comment comment) {
    Mica.CommentDto.Builder builder = // 
    Mica.CommentDto.newBuilder().setId(// 
    comment.getId()).setMessage(// 
    comment.getMessage()).setResourceId(// 
    comment.getResourceId()).setInstanceId(// 
    comment.getInstanceId()).setCreatedBy(// 
    comment.getCreatedBy()).setTimestamps(TimestampsDtos.asDto(comment));
    String modifiedBy = comment.getLastModifiedBy();
    if (!Strings.isNullOrEmpty(modifiedBy))
        builder.setModifiedBy(modifiedBy);
    if (subjectAclService.isPermitted(Paths.get(comment.getResourceId(), comment.getInstanceId(), "/comment").toString(), "EDIT", comment.getId())) {
        builder.addActions("EDIT");
    }
    if (subjectAclService.isPermitted(Paths.get(comment.getResourceId(), comment.getInstanceId(), "/comment").toString(), "DELETE", comment.getId())) {
        builder.addActions("DELETE");
    }
    Subject profile = userProfileService.getProfile(comment.getCreatedBy());
    if (profile != null) {
        builder.setCreatedByProfile(userProfileDtos.asDto(profile));
    }
    String lastModifiedBy = comment.getLastModifiedBy();
    if (!Strings.isNullOrEmpty(lastModifiedBy)) {
        profile = userProfileService.getProfile(lastModifiedBy);
        if (profile != null) {
            builder.setModifiedByProfile(userProfileDtos.asDto(profile));
        }
    }
    return builder.build();
}
Also used : Subject(org.obiba.shiro.realm.ObibaRealm.Subject) NotNull(javax.validation.constraints.NotNull)

Example 2 with Subject

use of org.obiba.shiro.realm.ObibaRealm.Subject in project mica2 by obiba.

the class UserProfileService method currentUserIs.

public boolean currentUserIs(@NotNull String role) {
    org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject();
    if (subject == null || subject.getPrincipal() == null) {
        return false;
    }
    String username = subject.getPrincipal().toString();
    if (username.equals("administrator")) {
        return true;
    }
    ObibaRealm.Subject profile = getProfile(username);
    return profile != null && profile.getGroups() != null && profile.getGroups().stream().filter(g -> g.equals(role)).count() > 0;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) ESAPI(org.owasp.esapi.ESAPI) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Subject(org.obiba.shiro.realm.ObibaRealm.Subject) Service(org.springframework.stereotype.Service) Map(java.util.Map) Nullable(javax.annotation.Nullable) DateTimeFormat(org.joda.time.format.DateTimeFormat) org.springframework.web.client(org.springframework.web.client) MailService(org.obiba.mica.core.service.MailService) Logger(org.slf4j.Logger) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) HttpHeaders(org.springframework.http.HttpHeaders) HttpMethod(org.springframework.http.HttpMethod) NotNull(javax.validation.constraints.NotNull) Maps(com.google.common.collect.Maps) ObibaRealm(org.obiba.shiro.realm.ObibaRealm) TimeUnit(java.util.concurrent.TimeUnit) HttpEntity(org.springframework.http.HttpEntity) URLEncoder(java.net.URLEncoder) List(java.util.List) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) ResponseEntity(org.springframework.http.ResponseEntity) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) SecurityUtils(org.apache.shiro.SecurityUtils) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AgateRestService(org.obiba.mica.core.service.AgateRestService) Assert(org.springframework.util.Assert) ObibaRealm(org.obiba.shiro.realm.ObibaRealm) Subject(org.obiba.shiro.realm.ObibaRealm.Subject)

Example 3 with Subject

use of org.obiba.shiro.realm.ObibaRealm.Subject in project mica2 by obiba.

the class UserProfileService method getProfile.

public synchronized Subject getProfile(@NotNull String username) {
    Assert.notNull(username, "Username cannot be null");
    Subject subject = getProfileInternal(getProfileServiceUrl(username));
    if (subject == null) {
        // return dummy Subject in case communication with Agate failed
        subject = new Subject();
        subject.setUsername(username);
    }
    return subject;
}
Also used : Subject(org.obiba.shiro.realm.ObibaRealm.Subject)

Example 4 with Subject

use of org.obiba.shiro.realm.ObibaRealm.Subject in project mica2 by obiba.

the class CommentDtos method asDtoBuilder.

private Mica.CommentDto.Builder asDtoBuilder(Comment comment) {
    Mica.CommentDto.Builder builder = // 
    Mica.CommentDto.newBuilder().setId(// 
    comment.getId()).setMessage(// 
    comment.getMessage()).setResourceId(// 
    comment.getResourceId()).setInstanceId(// 
    comment.getInstanceId()).setCreatedBy(// 
    comment.getCreatedBy()).setTimestamps(TimestampsDtos.asDto(comment));
    String modifiedBy = comment.getLastModifiedBy();
    if (!Strings.isNullOrEmpty(modifiedBy))
        builder.setModifiedBy(modifiedBy);
    Subject profile = userProfileService.getProfile(comment.getCreatedBy());
    if (profile != null) {
        builder.setCreatedByProfile(userProfileDtos.asDto(profile));
    }
    String lastModifiedBy = comment.getLastModifiedBy();
    if (!Strings.isNullOrEmpty(lastModifiedBy)) {
        profile = userProfileService.getProfile(lastModifiedBy);
        if (profile != null) {
            builder.setModifiedByProfile(userProfileDtos.asDto(profile));
        }
    }
    builder.setAdmin(comment.getAdmin());
    return builder;
}
Also used : Subject(org.obiba.shiro.realm.ObibaRealm.Subject)

Example 5 with Subject

use of org.obiba.shiro.realm.ObibaRealm.Subject in project mica2 by obiba.

the class ActionLogDtos method asDto.

ActionLogDto asDto(ActionLog actionLog) {
    ActionLogDto.Builder builder = // 
    ActionLogDto.newBuilder().setAuthor(// 
    actionLog.getAuthor()).setChangedOn(actionLog.getChangedOn().toString()).setAction(actionLog.getAction());
    Subject profile = userProfileService.getProfile(actionLog.getAuthor());
    if (profile != null) {
        builder.setProfile(userProfileDtos.asDto(profile));
    }
    return builder.build();
}
Also used : ActionLogDto(org.obiba.mica.web.model.Mica.DataAccessRequestDto.ActionLogDto) Subject(org.obiba.shiro.realm.ObibaRealm.Subject)

Aggregations

Subject (org.obiba.shiro.realm.ObibaRealm.Subject)6 NotNull (javax.validation.constraints.NotNull)2 ObibaRealm (org.obiba.shiro.realm.ObibaRealm)2 Strings (com.google.common.base.Strings)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URLEncoder (java.net.URLEncoder)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 SecurityUtils (org.apache.shiro.SecurityUtils)1 DateTimeFormat (org.joda.time.format.DateTimeFormat)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 AgateRestService (org.obiba.mica.core.service.AgateRestService)1