@Override
 public void authorize(ContainerRequestContext request) {
   logger.debug("ApplicationFilter.authorize");
   if (SubjectUtils.isAnonymous()) {
     ApplicationInfo application = null;
     try {
       // TODO not safe. could load arbitrary application
       application = management.getApplicationInfo(getApplicationIdentifier());
     } catch (Exception e) {
       e.printStackTrace();
     }
     EntityManager em = getEntityManagerFactory().getEntityManager(application.getId());
     Map<String, String> roles = null;
     try {
       roles = em.getRoles();
       logger.debug("found roles {}", roles);
     } catch (Exception e) {
       logger.error("Unable retrieve roles", e);
     }
     if ((roles != null) && roles.containsKey("guest")) {
       loginApplicationGuest(application);
     } else {
       throw mappableSecurityException("unauthorized", "No application guest access authorized");
     }
   }
   if (!isPermittedAccessToApplication(getApplicationIdentifier())) {
     throw mappableSecurityException("unauthorized", "No application access authorized");
   }
 }
示例#2
0
  @Path("{username}")
  public UserResource getUserByUsername(@Context UriInfo ui, @PathParam("username") String username)
      throws Exception {

    if ("me".equals(username)) {
      UserInfo user = SubjectUtils.getAdminUser();
      if ((user != null) && (user.getUuid() != null)) {
        return getSubResource(UserResource.class)
            .init(management.getAdminUserByUuid(user.getUuid()));
      }
      throw mappableSecurityException(
          "unauthorized", "No admin identity for access credentials provided");
    }

    return getSubResource(UserResource.class).init(management.getAdminUserByUsername(username));
  }