1 16 package org.apache.roller.webservices.adminapi; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import org.apache.roller.RollerException; 20 import org.apache.roller.model.Roller; 21 import org.apache.roller.model.RollerFactory; 22 import org.apache.roller.pojos.UserData; 23 24 29 abstract class Authenticator { 30 private HttpServletRequest request; 31 private Roller roller; 32 private String userName; 33 34 35 public Authenticator(HttpServletRequest req) { 36 setRequest(req); 37 setRoller(RollerFactory.getRoller()); 38 } 39 40 public abstract void authenticate() throws HandlerException; 41 42 46 protected void verifyUser() throws HandlerException { 47 try { 48 UserData user = getRoller().getUserManager().getUserByUserName(getUserName()); 49 if (user != null && user.hasRole("admin") && user.getEnabled().booleanValue()) { 50 } else { 52 throw new UnauthorizedException("ERROR: User must have the admin role to use the AAPP endpoint: " + getUserName()); 53 } 54 } catch (RollerException re) { 55 throw new InternalException("ERROR: Could not verify user: " + getUserName(), re); 56 } 57 } 58 59 public HttpServletRequest getRequest() { 60 return request; 61 } 62 63 protected void setRequest(HttpServletRequest request) { 64 this.request = request; 65 } 66 67 public String getUserName() { 68 return userName; 69 } 70 71 protected void setUserName(String userId) { 72 this.userName = userId; 73 } 74 75 protected Roller getRoller() { 76 return roller; 77 } 78 79 protected void setRoller(Roller roller) { 80 this.roller = roller; 81 } 82 } 83 | Popular Tags |