# HG changeset patch # User Bjoern Ricks # Date 1345817670 0 # Node ID 59c77a9551c8f801c6cb64603f8727e23eaca116 # Parent f2a4e6e92ffdd619bb6efe793bc9fa79a5c32424 User new find-user REST service in UserClient Use new find-user REST interface to check if a user already exists in the database or a new user must be created. flys-client/trunk@5265 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r f2a4e6e92ffd -r 59c77a9551c8 flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Aug 24 11:42:31 2012 +0000 +++ b/flys-client/ChangeLog Fri Aug 24 14:14:30 2012 +0000 @@ -1,3 +1,9 @@ +2012-08-24 Björn Ricks + + * src/main/java/de/intevation/flys/client/server/auth/UserClient.java: + Use new find-user REST interface to check if a user already exists in the + database or a new user must be created. + 2012-08-24 Björn Ricks * src/main/java/de/intevation/flys/client/server/auth/UserClient.java: diff -r f2a4e6e92ffd -r 59c77a9551c8 flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java Fri Aug 24 11:42:31 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/auth/UserClient.java Fri Aug 24 14:14:30 2012 +0000 @@ -31,21 +31,21 @@ } public boolean userExists(User user) throws ConnectionException { - NodeList users = this.listUsers(); + Element data = this.findUser(user); - if (users == null || users.getLength() == 0) { + if (user == null) { return false; } - for(int i=0; i < users.getLength(); i++) { - Element usernode = (Element)users.item(i); - String name = usernode.getAttributeNS( - ArtifactNamespaceContext.NAMESPACE_URI, "name"); + String XPATH_USERACCOUNT = "/art:user/art:account/@name"; - if (name.equals(user.getName())) { - return true; - } + String account = XMLUtils.xpathString( + data, XPATH_USERACCOUNT, ArtifactNamespaceContext.INSTANCE); + + if (account == null) { + return false; } - return false; + + return account.equals(user.getAccount()); } public boolean createUser(User user) throws ConnectionException { @@ -104,6 +104,37 @@ XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE); } + + public Element findUser(User user) throws ConnectionException { + HttpClient client = new HttpClientImpl(this.url); + + Document document = XMLUtils.newDocument(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + Element action = creator.create("action"); + + Element type = creator.create("type"); + type.setAttribute("name", "find"); + Element account = creator.create("account"); + account.setAttribute("name", user.getAccount()); + + action.appendChild(type); + action.appendChild(account); + document.appendChild(action); + + logger.debug("Find user request xml: " + XMLUtils.toString(document)); + + Document resp = client.findUser(document); + + logger.debug("Find user request response xml: " + XMLUtils.toString(resp)); + + return resp.getDocumentElement(); + } } // vim: set si et fileencoding=utf-8 ts=4 sw=4 tw=80: