1 4 package org.roller.presentation.xmlrpc; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.apache.xmlrpc.XmlRpcException; 9 import org.roller.model.UserManager; 10 import org.roller.pojos.UserData; 11 import org.roller.pojos.WebsiteData; 12 import org.roller.presentation.MainPageAction; 13 import org.roller.presentation.RollerContext; 14 import org.roller.presentation.RollerRequest; 15 import org.roller.presentation.pagecache.PageCacheFilter; 16 import org.roller.util.Utilities; 17 18 import java.io.Serializable ; 19 import org.roller.config.RollerConfig; 20 21 25 public class BaseAPIHandler implements Serializable 26 { 27 static final long serialVersionUID = -698186274794937582L; 28 29 private static Log mLogger = 30 LogFactory.getFactory().getInstance(BaseAPIHandler.class); 31 32 public static final int AUTHORIZATION_EXCEPTION = 0001; 33 public static final String AUTHORIZATION_EXCEPTION_MSG = 34 "Invalid Username and/or Password"; 35 36 public static final int UNKNOWN_EXCEPTION = 1000; 37 public static final String UNKNOWN_EXCEPTION_MSG = 38 "An error occured processing your request"; 39 40 public static final int BLOGGERAPI_DISABLED = 1000; 41 public static final String BLOGGERAPI_DISABLED_MSG = 42 "You have not enabled Blogger API support for your weblog"; 43 44 public static final int UNSUPPORTED_EXCEPTION = 1001; 45 public static final String UNSUPPORTED_EXCEPTION_MSG = 46 "Unsupported method - Roller does not support this method"; 47 48 public static final int INVALID_POSTID = 2000; 49 public static final String INVALID_POSTID_MSG = 50 "The entry postid you submitted is invalid"; 51 52 public static final int NOBLOGS_EXCEPTION = 3000; 53 public static final String NOBLOGS_EXCEPTION_MSG = 54 "There are no categories defined for your user"; 55 56 public static final int UPLOAD_DENIED_EXCEPTION = 4000; 57 public static final String UPLOAD_DENIED_EXCEPTION_MSG = 58 "Upload denied"; 59 60 public BaseAPIHandler() 62 { 63 } 64 65 72 protected WebsiteData validate(String username, String password) throws Exception 74 { 75 boolean authenticated = false; 76 boolean enabled = false; 77 WebsiteData website = null; 78 try 79 { 80 RollerRequest rreq = RollerRequest.getRollerRequest(); 82 83 UserManager userMgr = rreq.getRoller().getUserManager(); 84 website = userMgr.getWebsite(username); 85 86 enabled = website.getEnableBloggerApi().booleanValue(); 87 if (enabled) 88 { 89 RollerContext rollerContext = 91 RollerContext.getRollerContext(rreq.getRequest()); 92 String encrypted = 93 RollerConfig.getProperty("passwds.encryption.enabled"); 94 if ("true".equalsIgnoreCase(encrypted)) 96 { 97 password = Utilities.encodePassword(password, 98 RollerConfig.getProperty("passwds.encryption.algorithm")); 99 } 100 authenticated= website.getUser().getPassword().equals(password); 102 if (authenticated) 103 { 104 rreq.getRoller().setUser(website.getUser()); 105 } 106 } 107 } 108 catch (Exception e) 109 { 110 mLogger.error("ERROR internal error validating user", e); 111 } 112 113 if ( !enabled ) 114 { 115 throw new XmlRpcException( 116 BLOGGERAPI_DISABLED, BLOGGERAPI_DISABLED_MSG); 117 } 118 119 if ( !authenticated ) 120 { 121 throw new XmlRpcException( 122 AUTHORIZATION_EXCEPTION, AUTHORIZATION_EXCEPTION_MSG); 123 } 124 return website; 125 } 126 127 protected void flushPageCache(String user) throws Exception 129 { 130 RollerRequest rreq = RollerRequest.getRollerRequest(); 132 133 UserManager umgr = rreq.getRoller().getUserManager(); 134 UserData ud = umgr.getUser(user); 135 136 PageCacheFilter.removeFromCache( rreq.getRequest(), ud ); 137 MainPageAction.flushMainPageCache(); 138 } 139 } 140 | Popular Tags |