Really thanks. Now works. The following is the java code. try { String identityServiceRestUrl = "http://localhost:9080/syncope/cxf"; String name = "admin"; String pwd = "password";
WebClient client = WebClient.create(identityServiceRestUrl, Collections.singletonList(new JacksonJsonProvider())); String authorizationHeader = "Basic " + Base64Utility.encode((name + ":" + pwd).getBytes()); client.header("Authorization", authorizationHeader); // client = client.path("/users/count"); client = client.path("/entitlements/own"); String appjson = "application/json"; // throw exception here if url or name or pwd is wrong. client.accept(appjson).getCollection(EntitlementTO.class); } catch (ServerWebApplicationException e) { e.printStackTrace(); if (401 == e.getStatus()){ //username or password is wrong } else { } } catch (ClientWebApplicationException e) { e.printStackTrace(); } Thanks again! From: Francesco Chicchiriccò [mailto:ilgro...@apache.org] Sent: Monday, April 08, 2013 5:25 PM To: user@syncope.apache.org Subject: Re: How to check if the syncope service url and administrator username and password are correct? On 08/04/2013 04:29, ZhiYing Yan wrote: Yes, you understand right. I want to the check the user configured in the src\main\resources\security.properties, with java code. Thank you for reply and expecting your help. Please take a look at EntitlementService#getMyEntitlements() [1], mapped by CXF to GET /entitlements/own (see [2] for more details). admin user, in fact, has assigned all defined entitlements (obtained via GET /entitelements). admin user is not a real user (stored into the SyncopeUser table), but a virtual user only for administration purpose. HTH Regards. [1] https://svn.apache.org/repos/asf/syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/services/EntitlementService.java [2] https://cwiki.apache.org/confluence/display/SYNCOPE/REST+API+upgrade#RESTAPIupgrade-EntitlementService From: Francesco Chicchiriccò [mailto:ilgro...@apache.org] Sent: Wednesday, April 03, 2013 6:37 PM To: user@syncope.apache.org<mailto:user@syncope.apache.org> Subject: Re: How to check if the syncope service url and administrator username and password are correct? On 03/04/2013 10:16, ZhiYing Yan wrote: Hello, I have a question. I don't want to check the users defined in the Syncope. What I need to check is the administrator. I need to check if user uses correct administrator username and password to access the rest API like http://localhost:9080/syncope/cxf/users . Now I uses the following code: Try{ String url="http://localhost:9080/syncope/cxf"; String name="admin"; String password="password"; WebClient client = WebClient.create(url, Collections.singletonList(new JacksonJsonProvider())); String authorizationHeader = "Basic " + Base64Utility.encode((name+":"+password).getBytes()); client.header("Authorization", authorizationHeader); client = client.path("/users/count"); // throw exception here if url or name or pwd is wrong. client.accept("application/json").get(Integer.class); } catch (ServerWebApplicationException e) { if (401 == e.getStatus()) { rc.setMessage("Username or password is not correct"); rc.setOk(false); } else { rc.setMessage(e.getMessage()); rc.setOk(false); } } catch (ClientWebApplicationException e) { rc.setMessage(e.getMessage()); rc.setOk(false); } is there a special url to access, for example http://localhost:9080/syncope/cxf/authentication, and response with full information? Now to access /users/count is workaround. Could you help me? Let me check if I've understood your question: do you want to check if the authenticated user corresponds to the admin user configured under core/src/main/resources/security.properties? -- Francesco Chicchiriccò ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member http://people.apache.org/~ilgrosso/