Exemplo n.º 1
0
 @Override
 public String getMessage() {
   String message = null;
   if (!StringUtils.isEmpty(code)) {
     message = MessageUtils.message(code, args);
   }
   if (message == null) {
     message = defaultMessage;
   }
   return message;
 }
Exemplo n.º 2
0
 public void assertHasPermission(String permission, String errorCode) {
   if (StringUtils.isEmpty(errorCode)) {
     errorCode = getDefaultErrorCode();
   }
   String resourcePermission = resourcePermissions.get(permission);
   if (resourcePermission == null) {
     resourcePermission = this.resourceIdentity + ":" + permission;
   }
   if (!SecurityUtils.getSubject().isPermitted(resourcePermission)) {
     throw new UnauthorizedException(MessageUtils.message(errorCode, resourcePermission));
   }
 }
Exemplo n.º 3
0
  public void assertHasAllPermission(String[] permissions, String errorCode) {
    if (StringUtils.isEmpty(errorCode)) {
      errorCode = getDefaultErrorCode();
    }

    if (permissions == null || permissions.length == 0) {
      throw new UnauthorizedException(
          MessageUtils.message(errorCode, resourceIdentity + ":" + Arrays.toString(permissions)));
    }

    Subject subject = SecurityUtils.getSubject();

    for (String permission : permissions) {
      String resourcePermission = resourcePermissions.get(permission);
      if (resourcePermission == null) {
        resourcePermission = this.resourceIdentity + ":" + permission;
      }
      if (!subject.isPermitted(resourcePermission)) {
        throw new UnauthorizedException(
            MessageUtils.message(errorCode, resourceIdentity + ":" + Arrays.toString(permissions)));
      }
    }
  }