use of org.apache.shiro.authz.AuthorizationException in project mica2 by obiba.
the class DataAccessRequestResource method updateStartDate.
@PUT
@Path("/_start-date")
@Timed
public Response updateStartDate(@PathParam("id") String id, @QueryParam("date") String date) {
if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
throw new AuthorizationException();
}
DataAccessRequest request = dataAccessRequestService.findById(id);
if (request.isArchived())
throw new BadRequestException("Data access request is archived");
if (Strings.isNullOrEmpty(date))
request.setStartDate(null);
else {
try {
request.setStartDate(DataAccessRequestUtilService.ISO_8601.parse(date));
} catch (ParseException e) {
e.printStackTrace();
}
}
dataAccessRequestService.save(request);
return Response.noContent().build();
}
use of org.apache.shiro.authz.AuthorizationException in project mica2 by obiba.
the class DataAccessRequestResource method updateActionLogs.
@PUT
@Path("/_log-actions")
@Timed
public Response updateActionLogs(@PathParam("id") String id, Mica.DataAccessRequestDto dto) {
if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
throw new AuthorizationException();
}
if (!id.equals(dto.getId()))
throw new BadRequestException();
DataAccessRequest originalRequest = dataAccessRequestService.findById(id);
if (originalRequest.isArchived())
throw new BadRequestException("Data access request is archived");
DataAccessRequest request = dtos.fromDto(dto);
dataAccessRequestService.saveActionsLogs(request);
return Response.noContent().build();
}
use of org.apache.shiro.authz.AuthorizationException in project mica2 by obiba.
the class PublishedDatasetVariablesSetsResource method compose.
@POST
@Path("operations")
public Response compose(@Context UriInfo uriInfo, @QueryParam("s1") String set1, @QueryParam("s2") String set2, @QueryParam("s3") String set3) {
if (!subjectAclService.hasMicaRole())
throw new AuthorizationException();
List<DocumentSet> sets = Lists.newArrayList();
sets.add(variableSetService.get(set1));
sets.add(variableSetService.get(set2));
if (!Strings.isNullOrEmpty(set3))
sets.add(variableSetService.get(set3));
SetOperation setOperation = variableSetOperationService.create(sets);
return Response.created(uriInfo.getBaseUriBuilder().segment("variables", "sets", "operation", setOperation.getId()).build()).build();
}
use of org.apache.shiro.authz.AuthorizationException in project mica2 by obiba.
the class PublishedDatasetVariablesSetResource method createOpalViewsGet.
@GET
@Path("/documents/_opal")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response createOpalViewsGet(@PathParam("id") String id, @QueryParam("ids") String identifiers) {
DocumentSet set = getSecuredDocumentSet(id);
if (!subjectAclService.isAdministrator() && !subjectAclService.isDataAccessOfficer())
throw new AuthorizationException();
StreamingOutput streamingOutput;
if (!Strings.isNullOrEmpty(identifiers)) {
streamingOutput = stream -> variableSetService.createOpalViewsZip(variableSetService.getVariables(Sets.newHashSet(identifiers.split(","))), micaConfigService.getConfig().getOpalViewsGrouping(), new BufferedOutputStream(stream));
} else {
streamingOutput = stream -> variableSetService.createOpalViewsZip(variableSetService.getVariables(set), micaConfigService.getConfig().getOpalViewsGrouping(), new BufferedOutputStream(stream));
}
return Response.ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=\"opal-views-" + id + ".zip\"").build();
}
use of org.apache.shiro.authz.AuthorizationException in project airpal by airbnb.
the class ExampleLDAPRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Set<String> roles = Sets.newHashSet("user");
Set<Permission> permissions = Sets.newHashSet();
Collection<AllowAllUser> principalsCollection = principals.byType(AllowAllUser.class);
if (principalsCollection.isEmpty()) {
throw new AuthorizationException("No principals!");
}
for (AllowAllUser user : principalsCollection) {
for (UserGroup userGroup : groups) {
if (userGroup.representedByGroupStrings(user.getGroups())) {
permissions.addAll(userGroup.getPermissions());
break;
}
}
}
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(roles);
authorizationInfo.setObjectPermissions(permissions);
return authorizationInfo;
}
Aggregations