View Javadoc

1   package org.apache.turbine.services.xmlrpc.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Vector;
23  
24  import org.apache.turbine.om.security.User;
25  import org.apache.turbine.services.security.TurbineSecurity;
26  import org.apache.turbine.util.TurbineException;
27  
28  import org.apache.xmlrpc.AuthenticatedXmlRpcHandler;
29  
30  /***
31   * An authenticated Handler for use with the XML-RPC service that will deal
32   * with clients sending file to the server (Turbine application)
33   * and clients getting files from the server (Turbine application).
34   *
35   * usage in TurbineResources.properties is:
36   * services.XmlRpcService.handler.file = org.apache.turbine.services.xmlrpc.util.AuthenticatedFileHandler
37   *
38   * See the FileHandler class for further documentation.
39   *
40   * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
41   * @version $Id: AuthenticatedFileHandler.java 534527 2007-05-02 16:10:59Z tv $
42   * @deprecated This is not scope of the Service itself but of an
43   *             application which uses the service. This class shouldn't
44   *             be part of Turbine but of an addon application.
45   */
46  public class AuthenticatedFileHandler
47          extends FileHandler
48          implements AuthenticatedXmlRpcHandler
49  {
50      /***
51       * Default Constructor
52       */
53      public AuthenticatedFileHandler()
54      {
55      }
56  
57      /***
58       * Handles all requests for an Authenticated file transfer.
59       */
60      public Object execute(String method, Vector params, String username, String password)
61              throws TurbineException
62      {
63          Object obj = null;
64  
65          // Authenticate the user and get the object.
66          User user = null;
67          user = TurbineSecurity.getAuthenticatedUser(username, password);
68  
69          if (user != null)
70          {
71              if (method.equals("send"))
72              {
73                  // JDK 1.3 has no Boolean.valueOf(boolean)
74                  obj = new Boolean(this.send((String) params.elementAt(0),
75                          (String) params.elementAt(1),
76                          (String) params.elementAt(2)));
77              }
78  
79              if (method.equals("get"))
80              {
81                  obj = this.get((String) params.elementAt(0),
82                          (String) params.elementAt(1));
83              }
84  
85              if (method.equals("remove"))
86              {
87                  AuthenticatedFileHandler.remove((String) params.elementAt(0),
88                          (String) params.elementAt(1));
89                  obj = Boolean.TRUE;
90              }
91          }
92          else
93          {
94              obj = Boolean.FALSE;
95          }
96  
97          return (Object) obj;
98      }
99  }