Permalink
Browse files

[ignore] fix code formatting

  • Loading branch information...
1 parent 352b835 commit 930ff65c41b87c4d8c1f6edc13bb0c9c54de4472 @adamretter adamretter committed Jan 13, 2014
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2001-2010 The eXist Project
+ * Copyright (C) 2001-2014 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -24,6 +24,7 @@
import org.apache.log4j.Logger;
import org.exist.dom.QName;
import org.exist.security.AuthenticationException;
+import org.exist.security.SecurityManager;
import org.exist.security.Subject;
import org.exist.storage.DBBroker;
import org.exist.xquery.*;
@@ -37,74 +38,77 @@
*/
public class AsUser extends Function {
- protected final static Logger logger = Logger.getLogger(AsUser.class);
+ private final static Logger logger = Logger.getLogger(AsUser.class);
- public final static FunctionSignature signature =
- new FunctionSignature(
- new QName("as-user", SystemModule.NAMESPACE_URI, SystemModule.PREFIX),
- "A pseudo-function to execute a limited block of code as a different " +
- "user. The first argument is the name of the user, the second is the " +
- "password. If the user can be authenticated, the function will execute the " +
- "code block given in the third argument with the permissions of that user and" +
- "returns the result of the execution. Before the function completes, it switches " +
- "the current user back to the old user.",
- new SequenceType[] {
- new FunctionParameterSequenceType("username", Type.STRING, Cardinality.EXACTLY_ONE, "The username of the user to run the code against"),
- new FunctionParameterSequenceType("password", Type.STRING, Cardinality.ZERO_OR_ONE, "The password of the user to run the code against"),
- new FunctionParameterSequenceType("code-block", Type.ITEM, Cardinality.ZERO_OR_MORE, "The code block to run as the identified user")
- },
- new FunctionParameterSequenceType("result", Type.ITEM, Cardinality.ZERO_OR_MORE, "the results of the code block executed"));
+ public final static FunctionSignature signature = new FunctionSignature(
+ new QName("as-user", SystemModule.NAMESPACE_URI, SystemModule.PREFIX),
+ "A pseudo-function to execute a limited block of code as a different " +
+ "user. The first argument is the name of the user, the second is the " +
+ "password. If the user can be authenticated, the function will execute the " +
+ "code block given in the third argument with the permissions of that user and" +
+ "returns the result of the execution. Before the function completes, it switches " +
+ "the current user back to the old user.",
+ new SequenceType[] {
+ new FunctionParameterSequenceType("username", Type.STRING, Cardinality.EXACTLY_ONE, "The username of the user to run the code against"),
+ new FunctionParameterSequenceType("password", Type.STRING, Cardinality.ZERO_OR_ONE, "The password of the user to run the code against"),
+ new FunctionParameterSequenceType("code-block", Type.ITEM, Cardinality.ZERO_OR_MORE, "The code block to run as the identified user")
+ },
+ new FunctionParameterSequenceType("result", Type.ITEM, Cardinality.ZERO_OR_MORE, "the results of the code block executed")
+ );
- public AsUser(XQueryContext context) {
+ public AsUser(final XQueryContext context) {
super(context, signature);
}
- public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
+ @Override
+ public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
logger.info("Entering the " + SystemModule.PREFIX + ":as-user XQuery function");
- final DBBroker broker = context.getBroker();
+ final DBBroker broker = context.getBroker();
- final Sequence usernameResult = getArgument(0).eval(contextSequence, contextItem);
- if (usernameResult.isEmpty()) {
- final XPathException exception = new XPathException(this, "No user specified");
- logger.error("No user specified, throwing an exception!", exception);
+ final Sequence usernameResult = getArgument(0).eval(contextSequence, contextItem);
+ if(usernameResult.isEmpty()) {
+ final XPathException exception = new XPathException(this, "No user specified");
+ logger.error("No user specified, throwing an exception!", exception);
throw exception;
}
+
final Sequence password = getArgument(1).eval(contextSequence, contextItem);
-
final String username = usernameResult.getStringValue();
- final org.exist.security.SecurityManager security = broker.getBrokerPool().getSecurityManager();
+ final SecurityManager sm = broker.getBrokerPool().getSecurityManager();
Subject user;
try {
- user = security.authenticate(username, password.getStringValue());
- } catch (final AuthenticationException e) {
- final XPathException exception = new XPathException(this, "Authentication failed", e);
- logger.error("Authentication failed for setting the user to [" + username + "] because of ["+e.getMessage()+"], throwing an exception!", exception);
+ user = sm.authenticate(username, password.getStringValue());
+ } catch(final AuthenticationException e) {
+ final XPathException exception = new XPathException(this, "Authentication failed", e);
+ logger.error("Authentication failed for setting the user to [" + username + "] because of [" + e.getMessage() + "].", exception);
throw exception;
- }
+ }
- final Subject oldUser = broker.getSubject();
- try {
- logger.info("Setting the authenticated user to: [" + username + "]");
- broker.setSubject(user);
- return getArgument(2).eval(contextSequence, contextItem);
- } finally {
- logger.info("Returning the user to the original user: [" + oldUser.getName() + "]");
- broker.setSubject(oldUser);
- }
+ final Subject oldUser = broker.getSubject();
+ try {
+ logger.info("Setting the authenticated user to: [" + username + "]");
+ broker.setSubject(user);
+ return getArgument(2).eval(contextSequence, contextItem);
+ } finally {
+ logger.info("Returning the user to the original user: [" + oldUser.getName() + "]");
+ broker.setSubject(oldUser);
+ }
}
/* (non-Javadoc)
* @see org.exist.xquery.AbstractExpression#getDependencies()
*/
+ @Override
public int getDependencies() {
return getArgument(2).getDependencies();
}
/* (non-Javadoc)
* @see org.exist.xquery.PathExpr#returnsType()
*/
+ @Override
public int returnsType() {
return getArgument(2).returnsType();
}
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2006-2009 The eXist Project
+ * Copyright (C) 2006-2014 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -21,8 +21,6 @@
*/
package org.exist.xquery.functions.xmldb;
-import org.apache.log4j.Logger;
-
import org.exist.dom.QName;
import org.exist.xquery.BasicFunction;
import org.exist.xquery.Cardinality;
@@ -38,26 +36,22 @@
* @author Adam Retter <adam.retter@devon.gov.uk>
*
*/
-public class XMLDBGetCurrentUser extends BasicFunction
-{
- protected static final Logger logger = Logger.getLogger(XMLDBGetCurrentUser.class);
-
- public final static FunctionSignature signature =
- new FunctionSignature(
- new QName("get-current-user", XMLDBModule.NAMESPACE_URI, XMLDBModule.PREFIX),
- "Returns the user-id of the current user from the xquery context.",
- null,
- new FunctionReturnSequenceType(Type.STRING, Cardinality.EXACTLY_ONE, "the user-id of the current user")
- );
-
- public XMLDBGetCurrentUser(XQueryContext context, FunctionSignature signature)
- {
- super(context, signature);
- }
-
- public Sequence eval(Sequence args[], Sequence contextSequence) throws XPathException
- {
- final StringValue stringValue = new StringValue(context.getSubject().getName());
- return stringValue;
- }
+public class XMLDBGetCurrentUser extends BasicFunction {
+
+ public final static FunctionSignature signature =
+ new FunctionSignature(
+ new QName("get-current-user", XMLDBModule.NAMESPACE_URI, XMLDBModule.PREFIX),
+ "Returns the user-id of the current user from the xquery context.",
+ null,
+ new FunctionReturnSequenceType(Type.STRING, Cardinality.EXACTLY_ONE, "the user-id of the current user")
+ );
+
+ public XMLDBGetCurrentUser(final XQueryContext context, final FunctionSignature signature) {
+ super(context, signature);
+ }
+
+ @Override
+ public Sequence eval(final Sequence args[], final Sequence contextSequence) throws XPathException {
+ return new StringValue(context.getSubject().getName());
+ }
}
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2010 The eXist Project
+ * Copyright (C) 2014 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -39,25 +39,25 @@
* @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
*
*/
-@Deprecated //remove after 1.6
-public class XMLDBIsAuthenticated extends BasicFunction
-{
- protected static final Logger logger = Logger.getLogger(XMLDBIsAuthenticated.class);
+@Deprecated
+public class XMLDBIsAuthenticated extends BasicFunction {
+ protected static final Logger logger = Logger.getLogger(XMLDBIsAuthenticated.class);
- public final static FunctionSignature signature =
- new FunctionSignature(
- new QName("is-authenticated", XMLDBModule.NAMESPACE_URI, XMLDBModule.PREFIX),
- "Returns the true() if current user from the xquery context is authenticated, false() otherwise.",
- null,
- new FunctionReturnSequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE, "true() if user from the xquery context is authenticated, false() otherwise"),
- IsAuthenticated.FNS_IS_AUTHENTICATED
- );
+ public final static FunctionSignature signature =
+ new FunctionSignature(
+ new QName("is-authenticated", XMLDBModule.NAMESPACE_URI, XMLDBModule.PREFIX),
+ "Returns the true() if current user from the xquery context is authenticated, false() otherwise.",
+ null,
+ new FunctionReturnSequenceType(Type.BOOLEAN, Cardinality.EXACTLY_ONE, "true() if user from the xquery context is authenticated, false() otherwise"),
+ IsAuthenticated.FNS_IS_AUTHENTICATED
+ );
- public XMLDBIsAuthenticated(XQueryContext context, FunctionSignature signature) {
- super(context, signature);
- }
-
- public Sequence eval(Sequence args[], Sequence contextSequence) throws XPathException {
- return new BooleanValue(context.getSubject().isExternallyAuthenticated());
- }
+ public XMLDBIsAuthenticated(final XQueryContext context, final FunctionSignature signature) {
+ super(context, signature);
+ }
+
+ @Override
+ public Sequence eval(final Sequence args[], final Sequence contextSequence) throws XPathException {
+ return new BooleanValue(context.getSubject().isExternallyAuthenticated());
+ }
}

0 comments on commit 930ff65

Please sign in to comment.