KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > xmlrpc > XmlRpcSupport


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25
26
27 package org.snipsnap.xmlrpc;
28
29 import org.apache.xmlrpc.XmlRpcException;
30 import org.radeox.util.logging.Logger;
31 import org.snipsnap.app.Application;
32 import org.snipsnap.user.AuthenticationService;
33 import org.snipsnap.user.User;
34
35 /**
36  * Utility base class for XML-RPC handlers.
37  *
38  * Constants were taken from Blojsom. This
39  * should make understanding the code easier.
40  * (both ways).
41  *
42  * @author Stephan J. Schmidt
43  * @version $Id: XmlRpcSupport.java 1043 2003-10-21 14:19:28Z leo $
44  */

45 public abstract class XmlRpcSupport implements XmlRpcHandler {
46    protected AuthenticationService authenticationService;
47
48    public static final int AUTHORIZATION_EXCEPTION = 0001;
49    public static final String JavaDoc AUTHORIZATION_EXCEPTION_MSG = "Invalid Username and/or Password";
50
51    public static final int UNKNOWN_EXCEPTION = 1000;
52    public static final String JavaDoc UNKNOWN_EXCEPTION_MSG = "An error occured processing your request";
53
54    public static final int UNSUPPORTED_EXCEPTION = 1001;
55    public static final String JavaDoc UNSUPPORTED_EXCEPTION_MSG = "Unsupported method - Snipsnap does not support this XML-RPC concept";
56
57
58   /**
59    * Utility method for XML-RPC handlers. Method authenticates
60    * an user, sets this user as the current user of
61    * the Application thread and throws an XmlRpcException if
62    * user couldn't be authenticated
63    *
64    * @param username Login name of the user received from XML-RPC call
65    * @param password Password credential received from XML-RPC call
66    */

67
68   protected User authenticate(String JavaDoc username, String JavaDoc password) throws XmlRpcException {
69     User user = authenticationService.authenticate(username, password);
70     if (user != null) {
71       Application.get().setUser(user);
72       return user;
73     }
74     Logger.warn("XML-RPC authenticate: invalid login for "+username);
75     throw new XmlRpcException(AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG);
76   }
77
78 }
79
Popular Tags