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();
}
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;
}
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;
}
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;
}
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();
}
Aggregations