Ejemplo n.º 1
0
  /**
   * Update/change the password for the current user.
   *
   * @param oldPwd the old (current) password.
   * @param newPwd the new password
   * @return 200 OK on success @HTTP 404 if the current account could not be loaded @HTTP 403 if the
   *     old pasword did not match
   */
  @POST
  @Path("/me/passwd")
  public Response passwd(
      @FormParam("oldPasswd") String oldPwd, @FormParam("newPasswd") String newPwd) {
    final org.openrdf.model.URI currentUser = userService.getCurrentUser();
    final UserAccount a = accountService.getAccount(currentUser);

    if (a == null)
      return Response.status(Status.NOT_FOUND)
          .entity(String.format("No account found for <%s>", currentUser))
          .build();

    if (accountService.checkPassword(a, oldPwd)) {
      accountService.setPassword(a, newPwd);
      return Response.ok("Password changed").build();
    } else return Response.status(Status.FORBIDDEN).entity("password check failed").build();
  }
Ejemplo n.º 2
0
  private Response get(URI user) {
    if (userService.isAnonymous(user)) {
      AccountPoJo apj = new AccountPoJo(Namespaces.ANONYMOUS_LOGIN, user.stringValue());
      return Response.ok(apj, Namespaces.MIME_TYPE_JSON)
          .location(java.net.URI.create(user.stringValue()))
          .build();
    }
    try {
      RepositoryConnection conn = sesameService.getConnection();
      try {
        final UserAccount a = accountService.getAccount(user);
        if (a != null) {
          AccountPoJo apj = new AccountPoJo(a.getLogin(), a.getWebId());
          apj.setRoles(a.getRoles());

          for (Statement t :
              ResourceUtils.listOutgoing(conn, conn.getValueFactory().createURI(a.getWebId()))) {
            String prop = t.getPredicate().stringValue();
            if (prop.startsWith(Namespaces.NS_FOAF)) {
              Value object = t.getObject();
              if (object instanceof org.openrdf.model.URI) {
                apj.setFoaf(prop, String.format("<%s>", object));
              } else if (object instanceof Literal) {
                apj.setFoaf(prop, object.toString());
              }
            }
          }

          return Response.ok(apj, Namespaces.MIME_TYPE_JSON)
              .location(java.net.URI.create(user.stringValue()))
              .build();
        }
        return Response.status(Status.NOT_FOUND)
            .entity("Could not find account data of " + user)
            .build();
      } finally {
        conn.commit();
        conn.close();
      }
    } catch (RepositoryException e) {
      // This must not happen!
      return Response.serverError().entity(e).build();
    }
  }