use of org.apache.shiro.authz.AuthorizationException in project mica2 by obiba.
the class DataAccessRequestResource method addActionLog.
@POST
@Path("/_log-actions")
@Consumes("application/json")
public Response addActionLog(@PathParam("id") String id, Map<String, String> action) {
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(action.get("text")))
return Response.status(Response.Status.BAD_REQUEST).build();
try {
request.getActionLogHistory().add(ActionLog.newBuilder().action(action.get("text")).changedOn(DateTime.parse(action.get("date"))).author(SecurityUtils.getSubject().getPrincipal().toString()).build());
dataAccessRequestService.saveActionsLogs(request);
} catch (Exception e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.noContent().build();
}
use of org.apache.shiro.authz.AuthorizationException in project mica2 by obiba.
the class AbstractPublishedDocumentsSetResource method getSecuredDocumentSet.
protected DocumentSet getSecuredDocumentSet(String id) {
DocumentSet documentSet = getDocumentSetService().get(id);
if (!subjectAclService.isCurrentUser(documentSet.getUsername()) && !subjectAclService.isAdministrator() && !subjectAclService.isDataAccessOfficer())
throw new AuthorizationException();
boolean enabled = isCartEnabled(micaConfigService.getConfig());
// cart
if (!enabled && !documentSet.hasName())
throw new AuthorizationException();
if (enabled && !subjectAclService.hasMicaRole() && !documentSet.hasName())
// cart
throw new AuthorizationException();
if (documentSet.hasName() && !subjectAclService.hasMicaRole())
throw new AuthorizationException();
getDocumentSetService().touch(documentSet);
return documentSet;
}
use of org.apache.shiro.authz.AuthorizationException in project perry by ca-cwds.
the class AbacMethodInterceptor method filterResult.
@SuppressWarnings("unchecked")
private Collection filterResult(Authorize authorize, Collection results) throws ScriptException {
Collection out = initOutput(results);
for (Object result : results) {
try {
checkPermissions(authorize, result);
out.add(result);
} catch (AuthorizationException e) {
// ignore
}
}
return out;
}
use of org.apache.shiro.authz.AuthorizationException in project api-core by ca-cwds.
the class AbstractBaseAuthorizer method authorizeInstanceOperation.
protected boolean authorizeInstanceOperation(final T instance, List<Object> authorizationFacts) {
try {
final PerryAccount perryAccount = PerrySubject.getPerryAccount();
final Set<StaffPrivilegeType> staffPrivilegeTypes = toStaffPersonPrivilegeTypes(perryAccount);
if (staffPrivilegeTypes.isEmpty()) {
return false;
}
if (authorizationFacts == null) {
authorizationFacts = new ArrayList<>();
}
authorizationFacts.add(instance);
authorizationFacts.add(perryAccount);
final boolean authorizationResult = droolsAuthorizationService.authorizeObjectOperation(staffPrivilegeTypes, droolsConfiguration, authorizationFacts);
logAuthorization(perryAccount, staffPrivilegeTypes, instance, authorizationResult);
return authorizationResult;
} catch (DroolsException e) {
throw new AuthorizationException(e.getMessage(), e);
}
}
use of org.apache.shiro.authz.AuthorizationException in project fruit-manage by liuzhaozhao.
the class ShiroInterceptor method intercept.
public void intercept(Invocation ai) {
AuthzHandler ah = ShiroKit.getAuthzHandler(ai.getActionKey());
// 存在访问控制处理器。
if (ah != null) {
Controller c = ai.getController();
try {
// 执行权限检查。
ah.assertAuthorized();
} catch (UnauthenticatedException lae) {
// 如果没有进行身份验证,返回HTTP401状态码,或者跳转到默认登录页面
if (StrKit.notBlank(this.loginUrl)) {
// 保存登录前的页面信息,只保存GET请求。其他请求不处理。
if (c.getRequest().getMethod().equalsIgnoreCase("GET")) {
// SecurityUtils.getSubject().getSession().setAttribute(this.savedRequestKey, ai.getControllerKey()+"/" + ai.getMethodName() + this.extName);
if (c.getSessionAttr(this.savedRequestKey) == null) {
/*getRequestURL: http://localhost:10086/dafei/index.do
getRequestURI: /dafei/index.do
getQueryString: tt=121212&32323*/
HttpServletRequest req = c.getRequest();
String saveUrl = req.getRequestURI().substring(req.getContextPath().length());
String saveQs = req.getQueryString();
if (StrKit.notBlank(saveQs)) {
saveUrl = saveUrl + "?" + saveQs;
}
if (StrKit.notBlank(saveUrl)) {
c.setSessionAttr(this.savedRequestKey, saveUrl);
}
}
}
c.redirect(this.loginUrl);
} else {
ai.getController().renderError(401);
}
return;
} catch (AuthorizationException ae) {
// 如果没有权限访问对应的资源,返回HTTP状态码403,或者调转到为授权页面
if (StrKit.notBlank(this.unauthorizedUrl)) {
c.redirect(this.unauthorizedUrl);
} else {
c.renderError(403);
}
return;
}
}
// 执行正常逻辑
ai.invoke();
}
Aggregations