コード例 #1
0
  /**
   * Create a new user
   *
   * @param message containing the new user
   * @return userCreatedMessage with the appropiate data or an error otherwise
   */
  @RequestMapping(
      value = "/approve/{membershipId}",
      method = RequestMethod.PUT,
      consumes = "application/json")
  @ResponseBody
  public ResponseEntity<Object> approveMembership(
      @RequestHeader("Authorization") String token,
      @RequestHeader("If-Unmodified-Since") String since,
      @PathVariable(value = "membershipId") String uid,
      UriComponentsBuilder builder,
      HttpServletRequest req) {

    HttpHeaders headers = new HttpHeaders();
    Collection<String> cred = new LinkedList<String>();
    cred.add(token);
    try {
      // This method just authenticates... it doesn't do access control
      Collection<IPrincipal> principals = authenticator.authenticatePrincipals(LOG, cred);
      MembershipResponseMessage res =
          (MembershipResponseMessage)
              membershipService.updateEntity(new ApproveMembershipEvent(uid, principals, since));

      return new ResponseEntity<Object>(res, headers, HttpStatus.OK);
    } catch (IdManagementException idm) {
      // since the creation of the exception generated the log entries for the stacktrace, we don't
      // do it again here
      return new ResponseEntity<Object>(
          idm.getErrorAsMap(), headers, HttpStatus.valueOf(idm.getHTTPErrorCode()));
    } catch (Exception e) {
      String s = IdManagementException.getStackTrace(e);
      LOG.error(s);
      return new ResponseEntity<Object>(null, headers, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }
コード例 #2
0
  @RequestMapping(value = "/{membershipId}", method = RequestMethod.DELETE)
  @ResponseStatus(HttpStatus.OK)
  @ResponseBody
  public ResponseEntity<Object> DeteMembership(
      @RequestHeader("Authorization") String token,
      @RequestHeader("If-Unmodified-Since") long lastKnownUpdate,
      @PathVariable(value = "membershipId") String uid) {

    HttpHeaders headers = new HttpHeaders();
    Collection<String> cred = new LinkedList<String>();
    cred.add(token);
    try {

      Collection<IPrincipal> principals = authenticator.authenticatePrincipals(LOG, cred);
      membershipService.deleteEntity(
          new DeleteUserMembershipEvent(uid, principals, lastKnownUpdate));
      return new ResponseEntity<Object>(null, headers, HttpStatus.OK);

    } catch (IdManagementException idm) {
      // since the creation of the exception generated the log entries for the stacktrace, we don't
      // do it again here
      return new ResponseEntity<Object>(
          idm.getErrorAsMap(), headers, HttpStatus.valueOf(idm.getHTTPErrorCode()));
    } catch (Exception e) {
      String s = IdManagementException.getStackTrace(e);
      LOG.error(s);
      return new ResponseEntity<Object>(null, headers, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }