Skip to content

Commit 0c59d21

Browse files
committed
[refactor] Switch to FunctionDSL
1 parent 4959e6c commit 0c59d21

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

exist-core/src/main/java/org/exist/xquery/functions/system/AsUser.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,40 @@
2323

2424
import org.apache.logging.log4j.LogManager;
2525
import org.apache.logging.log4j.Logger;
26-
import org.exist.dom.QName;
2726
import org.exist.security.AuthenticationException;
2827
import org.exist.security.SecurityManager;
2928
import org.exist.security.Subject;
3029
import org.exist.storage.DBBroker;
3130
import org.exist.xquery.*;
32-
import org.exist.xquery.value.FunctionParameterSequenceType;
3331
import org.exist.xquery.value.Item;
3432
import org.exist.xquery.value.Sequence;
35-
import org.exist.xquery.value.SequenceType;
3633
import org.exist.xquery.value.Type;
3734

35+
import static org.exist.xquery.FunctionDSL.*;
36+
import static org.exist.xquery.functions.system.SystemModule.functionSignature;
37+
3838
/**
3939
*/
4040
public class AsUser extends Function {
4141

4242
private final static Logger logger = LogManager.getLogger(AsUser.class);
4343

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")
5857
);
5958

60-
public AsUser(final XQueryContext context) {
59+
public AsUser(final XQueryContext context, final FunctionSignature signature) {
6160
super(context, signature);
6261
}
6362

exist-core/src/main/java/org/exist/xquery/functions/system/SystemModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class SystemModule extends AbstractInternalModule {
6666
new FunctionDef(Shutdown.signatures[1], Shutdown.class),
6767
new FunctionDef(GetModuleLoadPath.signature, GetModuleLoadPath.class),
6868
new FunctionDef(TriggerSystemTask.signature, TriggerSystemTask.class),
69-
new FunctionDef(AsUser.signature, AsUser.class),
69+
new FunctionDef(AsUser.FS_AS_USER, AsUser.class),
7070
new FunctionDef(GetIndexStatistics.signature, GetIndexStatistics.class),
7171
new FunctionDef(UpdateStatistics.signature, UpdateStatistics.class),
7272
new FunctionDef(GetRunningXQueries.signature, GetRunningXQueries.class),

0 commit comments

Comments
 (0)