|
23 | 23 |
|
24 | 24 | import org.apache.logging.log4j.LogManager;
|
25 | 25 | import org.apache.logging.log4j.Logger;
|
26 |
| -import org.exist.dom.QName; |
27 | 26 | import org.exist.security.AuthenticationException;
|
28 | 27 | import org.exist.security.SecurityManager;
|
29 | 28 | import org.exist.security.Subject;
|
30 | 29 | import org.exist.storage.DBBroker;
|
31 | 30 | import org.exist.xquery.*;
|
32 |
| -import org.exist.xquery.value.FunctionParameterSequenceType; |
33 | 31 | import org.exist.xquery.value.Item;
|
34 | 32 | import org.exist.xquery.value.Sequence;
|
35 |
| -import org.exist.xquery.value.SequenceType; |
36 | 33 | import org.exist.xquery.value.Type;
|
37 | 34 |
|
| 35 | +import static org.exist.xquery.FunctionDSL.*; |
| 36 | +import static org.exist.xquery.functions.system.SystemModule.functionSignature; |
| 37 | + |
38 | 38 | /**
|
39 | 39 | */
|
40 | 40 | public class AsUser extends Function {
|
41 | 41 |
|
42 | 42 | private final static Logger logger = LogManager.getLogger(AsUser.class);
|
43 | 43 |
|
44 |
| - public final static FunctionSignature signature = new FunctionSignature( |
45 |
| - new QName("as-user", SystemModule.NAMESPACE_URI, SystemModule.PREFIX), |
46 |
| - "A pseudo-function to execute a limited block of code as a different " + |
47 |
| - "user. The first argument is the name of the user, the second is the " + |
48 |
| - "password. If the user can be authenticated, the function will execute the " + |
49 |
| - "code block given in the third argument with the permissions of that user and" + |
50 |
| - "returns the result of the execution. Before the function completes, it switches " + |
51 |
| - "the current user back to the old user.", |
52 |
| - new SequenceType[] { |
53 |
| - new FunctionParameterSequenceType("username", Type.STRING, Cardinality.EXACTLY_ONE, "The username of the user to run the code against"), |
54 |
| - new FunctionParameterSequenceType("password", Type.STRING, Cardinality.ZERO_OR_ONE, "The password of the user to run the code against"), |
55 |
| - new FunctionParameterSequenceType("code-block", Type.ITEM, Cardinality.ZERO_OR_MORE, "The code block to run as the identified user") |
56 |
| - }, |
57 |
| - new FunctionParameterSequenceType("result", Type.ITEM, Cardinality.ZERO_OR_MORE, "the results of the code block executed") |
| 44 | + private static String FS_AS_USER_NAME = "as-user"; |
| 45 | + public final static FunctionSignature FS_AS_USER = functionSignature( |
| 46 | + FS_AS_USER_NAME, |
| 47 | + "A pseudo-function to execute a limited block of code as a different " + |
| 48 | + "user. The first argument is the name of the user, the second is the " + |
| 49 | + "password. If the user can be authenticated, the function will execute the " + |
| 50 | + "code block given in the third argument with the permissions of that user and" + |
| 51 | + "returns the result of the execution. Before the function completes, it switches " + |
| 52 | + "the current user back to the old user.", |
| 53 | + returnsOptMany(Type.ITEM, "the results of the code block executed"), |
| 54 | + param("username", Type.STRING, "The username of the user to run the code against"), |
| 55 | + optParam("password", Type.STRING, "The password of the user to run the code against"), |
| 56 | + optManyParam("code-block", Type.ITEM, "The code block to run as the identified user") |
58 | 57 | );
|
59 | 58 |
|
60 |
| - public AsUser(final XQueryContext context) { |
| 59 | + public AsUser(final XQueryContext context, final FunctionSignature signature) { |
61 | 60 | super(context, signature);
|
62 | 61 | }
|
63 | 62 |
|
|
0 commit comments