1 18 21 package org.apache.roller.webservices.xmlrpc; 22 23 import java.io.Serializable ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.xmlrpc.XmlRpcException; 28 import org.apache.roller.config.RollerConfig; 29 import org.apache.roller.model.RollerFactory; 30 import org.apache.roller.model.UserManager; 31 import org.apache.roller.pojos.UserData; 32 import org.apache.roller.pojos.WebsiteData; 33 import org.apache.roller.ui.core.RollerContext; 34 import org.apache.roller.util.cache.CacheManager; 35 import org.apache.roller.util.Utilities; 36 37 41 public class BaseAPIHandler implements Serializable { 42 static final long serialVersionUID = -698186274794937582L; 43 44 private static Log mLogger = 45 LogFactory.getFactory().getInstance(BaseAPIHandler.class); 46 47 public static final int AUTHORIZATION_EXCEPTION = 0001; 48 public static final String AUTHORIZATION_EXCEPTION_MSG = 49 "Invalid Username and/or Password"; 50 51 public static final int UNKNOWN_EXCEPTION = 1000; 52 public static final String UNKNOWN_EXCEPTION_MSG = 53 "An error occured processing your request"; 54 55 public static final int UNSUPPORTED_EXCEPTION = 1001; 56 public static final String UNSUPPORTED_EXCEPTION_MSG = 57 "Unsupported method - Roller does not support this method"; 58 59 public static final int USER_DISABLED = 1002; 60 public static final String USER_DISABLED_MSG = 61 "User is disabled"; 62 63 public static final int WEBLOG_NOT_FOUND = 1003; 64 public static final String WEBLOG_NOT_FOUND_MSG = 65 "Weblog is not found or is disabled"; 66 67 public static final int WEBLOG_DISABLED = 1004; 68 public static final String WEBLOG_DISABLED_MSG = 69 "Weblog is not found or is disabled"; 70 71 public static final int BLOGGERAPI_DISABLED = 1005; 72 public static final String BLOGGERAPI_DISABLED_MSG = 73 "Weblog does not exist or XML-RPC disabled in web"; 74 75 public static final int BLOGGERAPI_INCOMPLETE_POST = 1006; 76 public static final String BLOGGERAPI_INCOMPLETE_POST_MSG = 77 "Incomplete weblog entry"; 78 79 public static final int INVALID_POSTID = 2000; 80 public static final String INVALID_POSTID_MSG = 81 "The entry postid you submitted is invalid"; 82 83 87 public static final int UPLOAD_DENIED_EXCEPTION = 4000; 88 public static final String UPLOAD_DENIED_EXCEPTION_MSG = 89 "Upload denied"; 90 91 public BaseAPIHandler() { 93 } 94 95 102 109 protected WebsiteData validate(String blogid, String username, String password) 110 throws Exception { 111 boolean authenticated = false; 112 boolean userEnabled = false; 113 boolean weblogEnabled = false; 114 boolean apiEnabled = false; 115 boolean weblogFound = false; 116 WebsiteData website = null; 117 UserData user = null; 118 try { 119 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 120 user = userMgr.getUserByUserName(username); 121 userEnabled = user.getEnabled().booleanValue(); 122 123 website = userMgr.getWebsiteByHandle(blogid); 124 if (website != null) { 125 weblogFound = true; 126 weblogEnabled = website.getEnabled().booleanValue(); 127 apiEnabled = website.getEnableBloggerApi().booleanValue(); 128 } 129 130 if (user != null) { 131 RollerContext rollerContext = 133 RollerContext.getRollerContext(); 134 String encrypted = 135 RollerConfig.getProperty("passwds.encryption.enabled"); 136 if ("true".equalsIgnoreCase(encrypted)) { 138 password = Utilities.encodePassword(password, 139 RollerConfig.getProperty("passwds.encryption.algorithm")); 140 } 141 authenticated = password.equals(user.getPassword()); 142 } 143 } catch (Exception e) { 144 mLogger.error("ERROR internal error validating user", e); 145 } 146 147 if ( !authenticated ) { 148 throw new XmlRpcException( 149 AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG); 150 } 151 if ( !userEnabled ) { 152 throw new XmlRpcException( 153 USER_DISABLED, USER_DISABLED_MSG); 154 } 155 if ( !weblogEnabled ) { 156 throw new XmlRpcException( 157 WEBLOG_DISABLED, WEBLOG_DISABLED_MSG); 158 } 159 if ( !weblogFound ) { 160 throw new XmlRpcException( 161 WEBLOG_NOT_FOUND, WEBLOG_NOT_FOUND_MSG); 162 } 163 if ( !apiEnabled ) { 164 throw new XmlRpcException( 165 BLOGGERAPI_DISABLED, BLOGGERAPI_DISABLED_MSG); 166 } 167 return website; 168 } 169 170 176 protected boolean validateUser(String username, String password) 177 throws Exception { 178 boolean authenticated = false; 179 boolean enabled = false; 180 UserData user = null; 181 try { 182 183 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 184 user = userMgr.getUserByUserName(username); 185 186 enabled = user.getEnabled().booleanValue(); 187 if (enabled) { 188 RollerContext rollerContext = 190 RollerContext.getRollerContext(); 191 String encrypted = 192 RollerConfig.getProperty("passwds.encryption.enabled"); 193 if ("true".equalsIgnoreCase(encrypted)) { 195 password = Utilities.encodePassword(password, 196 RollerConfig.getProperty("passwds.encryption.algorithm")); 197 } 198 authenticated = user.getPassword().equals(password); 200 if (authenticated) { 201 } 203 } 204 } catch (Exception e) { 205 mLogger.error("ERROR internal error validating user", e); 206 } 207 208 if ( !enabled ) { 209 throw new XmlRpcException( 210 BLOGGERAPI_DISABLED, BLOGGERAPI_DISABLED_MSG); 211 } 212 213 if ( !authenticated ) { 214 throw new XmlRpcException( 215 AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG); 216 } 217 return authenticated; 218 } 219 220 protected void flushPageCache(WebsiteData website) throws Exception { 222 CacheManager.invalidate(website); 223 } 224 } 225 | Popular Tags |