Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/server/auth/saml/XPathUtils.java @ 5948:d7b9b3e3c61a
Make instantiation of saml.User easier.
Most of the parameters of the constructor can be taken from the
Assertion object, so there's no reason to pass them separately.
Also, trying to check the validity dates isn't useful for the single
sign on case. See comments in the hasExpired method.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 08 May 2013 17:56:14 +0200 |
parents | 407cff3b03ab |
children | 7b0db743f074 |
rev | line source |
---|---|
5939
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt f�r Gew�sserkunde |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
3 * |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
7 */ |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
8 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
9 package org.dive4elements.river.client.server.auth.saml; |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
10 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
11 import javax.xml.namespace.QName; |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
12 import javax.xml.xpath.XPathConstants; |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
13 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
14 import org.w3c.dom.Node; |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
15 import org.w3c.dom.NodeList; |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
16 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
17 import org.dive4elements.artifacts.common.utils.XMLUtils; |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
18 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
19 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
20 /** |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
21 * Convenience methods to evaluate XPath queries on SAML documents. The |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
22 * methods are just front-ends for the {@link XMLUtils.xpath} method. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
23 */ |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
24 public class XPathUtils |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
25 { |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
26 /** |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
27 * Evaluates an XPath query on a given object and returns the result |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
28 * as a given type, using SamlNamespaceContext as the namespace |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
29 * context. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
30 * @param root The object which is used as the root of the tree to |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
31 * be searched in. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
32 * @param query The XPath query |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
33 * @param returnType The type of the result. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
34 * @return The result of type 'returnType' or null if something |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
35 * went wrong during XPath evaluation. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
36 */ |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
37 public static final Object xpath(Object root, String query, |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
38 QName returnType) { |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
39 return XMLUtils.xpath(root, query, returnType, |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
40 SamlNamespaceContext.INSTANCE); |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
41 } |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
42 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
43 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
44 /** |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
45 * Evaluates an XPath query on a given object and returns the result |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
46 * as a String, using SamlNamespaceContext as the namespace context. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
47 * @param root The object which is used as the root of the tree to |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
48 * be searched in. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
49 * @param query The XPath query |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
50 * @return The result as a String or null if something went wrong |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
51 * during XPath evaluation. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
52 */ |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
53 public static final String xpathString(Object root, String query) { |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
54 return (String)xpath(root, query, XPathConstants.STRING); |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
55 } |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
56 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
57 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
58 /** |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
59 * Evaluates an XPath query on a given object and returns the result |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
60 * as a Node, using SamlNamespaceContext as the namespace context. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
61 * @param root The object which is used as the root of the tree to |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
62 * be searched in. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
63 * @param query The XPath query |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
64 * @return The result as a Node or null if something went wrong |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
65 * during XPath evaluation. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
66 */ |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
67 public static final Node xpathNode(Object root, String query) { |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
68 return (Node)xpath(root, query, XPathConstants.NODE); |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
69 } |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
70 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
71 |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
72 /** |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
73 * Evaluates an XPath query on a given object and returns the result |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
74 * as a NodeList, using SamlNamespaceContext as the namespace |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
75 * context. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
76 * @param root The object which is used as the root of the tree to |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
77 * be searched in. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
78 * @param query The XPath query |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
79 * @return The result as a NodeList or null if something |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
80 * went wrong during XPath evaluation. |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
81 */ |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
82 public static final NodeList xpathNodeList(Object root, String query) { |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
83 return (NodeList)xpath(root, query, XPathConstants.NODESET); |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
84 } |
407cff3b03ab
Add XPathUtils, helper functions to process SAML with XPath.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
85 } |