Package org.odata4j.exceptions

Examples of org.odata4j.exceptions.NotAuthorizedException


  }

  public static void checkAccess(DatastoreService datastore, Entity e, AccessType accessType) {
    UserService userService = UserServiceFactory.getUserService();
    if (!userService.isUserLoggedIn()) {
      throw new NotAuthorizedException();
    }
    if (e == null) {
      return;
    }
    if (userService.isUserAdmin()) {
      return;
    }

    // Check read access by kind
    if (accessType == AccessType.READ) {
      Query q = new Query(KIND_ACCESS_CONTROL_KIND);
      Filter filter = new FilterPredicate("Kind", FilterOperator.EQUAL, e.getKind());
      q.setFilter(filter);
      Entity kac = datastore.prepare(q).asSingleEntity();
      if (kac != null) {
        Long access = (Long) kac.getProperty("Access");
        if (access.equals(UserGroup.USER.groupId)) {
          return;
        }
      }
    }
    // Check write access by entity
    else if (accessType == AccessType.WRITE) {
      Query q = new Query(ENTITY_ACCESS_CONTROL_KIND);
      Filter filter = new FilterPredicate("Entity", FilterOperator.EQUAL, e);
      q.setFilter(filter);
      Entity eac = datastore.prepare(q).asSingleEntity();

      User owner = (User) eac.getProperty("owner");
      if (owner.compareTo(userService.getCurrentUser()) == 0) {
        return;
      }
    }
    throw new NotAuthorizedException();
  }
View Full Code Here

TOP

Related Classes of org.odata4j.exceptions.NotAuthorizedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.