On 24/10/2013 18:13, Nathan Kopp wrote:
Thanks for your quick response! I tried to connect to the REST services as the administrator, but I still get a 404 error when trying to POST an update:

Hi Nathan,
see my reply below.

Regards.

Client client1 = Client.create(config);
client1.addFilter(newHTTPBasicAuthFilter("admin", "<adminpwd>"));
WebResource service1 = client1.resource(baseUri);

ClientResponse response1 = service1.path("users").path("100")
.accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
System.out.println("response1:"+response1.getStatus());
System.out.println("response1:"+response1.getEntity(String.class));

String s = "{\"password\":\"newpwd\"}";
ClientResponse response2 = service1.path("users").path("100")
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.post(ClientResponse.class,s);
System.out.println("response2:"+response2.getStatus());
System.out.println("response2:"+response2.getEntity(String.class));

The output is:

response1:200
response1:{"attributes":[],"id":100,"derivedAttributes":[],"virtualAtt ... "failedLogins":0}
response2:404
response2:

Strangely, the first request, which is "GET /cxf/users/100" works. It returns the JSON for the user.

The second request, which is "POST /cxf/users/100" (note that it is the exact same path) returns 404. This seems strange.

Syncope version is 1.1.2.


I have just replicated your test with Syncope 1.1.4 and everything went fine: the problem in your case is that the provided JSON string passed to the POST request does not explicitly contain the id of user to be updated. I know that this is redundant, but it is due to the fact that Syncope 1.1.X supports both Spring MVC and CXF and such conformation is required for the former to work.

In order to fix your issue, just provide a JSON string like as follows:

{"id":100,"password":"newpwd"}

Regards.

On Thu, Oct 24, 2013 at 1:19 AM, Francesco Chicchiriccò <[email protected] <mailto:[email protected]>> wrote:

    On 23/10/2013 19:36, Nathan Kopp wrote:
    I'm trying to use CXF REST services to allow the user to change
    their own password.  I'm using the Jersey REST client.  Using GET
    with "/users/self" works.  However, I'm getting a either a 404 or
    500 error from Syncope when I try to POST to "/users/100" or
    "/users/self". (In this case, the user's ID is "100".)

    What am I doing wrong?

    Hi Nathan,
    as recently discussed [1], there is currently no option for
    letting a plain user to updated his own data without admin
    approval (this is going to change with SYNCOPE-145 [2]).

    The operation flow looks then as following:

    1. plain user updates his own data (possibly including password)
    2. admin user sees the incoming user request and possibly executes
    it, then deletes it
    3. plain user gets his data effectively changed

    (1) is performed via UserRequest's POST /requests/user [1]
    (2) is performed via UserRequest's POST update/execute/{requestId}
    (if the requestId is known from (1), otherwise you will need to
    find it via other methods of UserRequest service) and finally via
    DELETE /requests/user/{requestId}

    Things are different when performing user update as administrator,
    e.g. when admin user updates plain user's data: POST
    /users/{userId} with a JSON or XML UserMod [4] payload.

    Naturally, things are much easier when working via admin console
    or using the Syncope client library.

    Regards.

    [1] http://markmail.org/message/v4dorbvybhugz3wo
    [2] https://issues.apache.org/jira/browse/SYNCOPE-145
    [3]
    
https://cwiki.apache.org/confluence/display/SYNCOPE/REST+API+upgrade#RESTAPIupgrade-UserRequestService
    [4]
    
https://svn.apache.org/repos/asf/syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/mod/UserMod.java



    URI baseUri=
    UriBuilder.fromUri("https://my-server/syncope/cxf";).build()
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    client.addFilter(new HTTPBasicAuthFilter(username, oldPassword));
    WebResource service = client.resource(baseUri);

    // this part works
    ClientResponse response =
    
service.path("users").path("self").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);

    String s = "{\"password\":\""+newPassword+"\"}";

    // this gives a 404 error
    ClientResponse response2 = service.path("users").path("100")
                        .accept(MediaType.APPLICATION_JSON)
                        .type(MediaType.APPLICATION_JSON)
                       .post(ClientResponse.class,s);

    // this gives a 500 error
    ClientResponse response3 = service.path("users").path("self")
                        .accept(MediaType.APPLICATION_JSON)
                        .type(MediaType.APPLICATION_JSON)
                        .post(ClientResponse.class,s);

--
Francesco Chicchiriccò

ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/

Reply via email to