示例#1
0
 private User getDefaultUser() {
   if (defaultUsername != null) {
     User user = pool.getSecurityManager().getUser(defaultUsername);
     if (user != null) {
       if (!user.validate(defaultPassword)) {
         return null;
       }
     }
     return user;
   }
   return null;
 }
示例#2
0
 public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
   Sequence userSeq = getArgument(0).eval(contextSequence, contextItem);
   Sequence passwdSeq = getArgument(1).eval(contextSequence, contextItem);
   if (userSeq.isEmpty()) throw new XPathException(getASTNode(), "No user specified");
   String userName = userSeq.getStringValue();
   String passwd = passwdSeq.getStringValue();
   org.exist.security.SecurityManager security =
       context.getBroker().getBrokerPool().getSecurityManager();
   User user = security.getUser(userName);
   if (user == null) throw new XPathException(getASTNode(), "Authentication failed");
   if (user.validate(passwd)) {
     User oldUser = context.getBroker().getUser();
     try {
       context.getBroker().setUser(user);
       return getArgument(2).eval(contextSequence, contextItem);
     } finally {
       context.getBroker().setUser(oldUser);
     }
   } else throw new XPathException(getASTNode(), "Authentication failed");
 }