Changeset 301

Show
Ignore:
Timestamp:
03/25/06 22:20:01
Author:
douglm
Message:

Fix up handling of super user mode
Not using roles to determine capability of admin user. Now based solely on db values.

The role was only being used when switching groups and led to somewhat inconsistent behaviour.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java

    r27 r301  
    108108   * ==================================================================== */ 
    109109 
    110   AccessUtil(boolean superUser, boolean debug) throws CalFacadeException { 
    111     this.superUser = superUser; 
     110  AccessUtil(boolean debug) throws CalFacadeException { 
    112111    this.debug = debug; 
    113112    try { 
     
    118117  } 
    119118 
     119  void setSuperUser(boolean val) { 
     120    superUser = val; 
     121  } 
     122   
     123  boolean getSuperUser() { 
     124    return superUser; 
     125  } 
     126   
    120127  void setAuthUser(BwUser val) { 
    121128    authUser = val; 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java

    r299 r301  
    8080   */ 
    8181  public Calendars(Calintf cal, AccessUtil access,  
    82                    int currentMode, boolean ignoreCreator, boolean debug) 
     82                   int currentMode, boolean debug) 
    8383                  throws CalFacadeException { 
    84     super(cal, access, currentMode, ignoreCreator, debug); 
     84    super(cal, access, currentMode, debug); 
    8585 
    8686    publicCalendarRootPath = "/" + getSyspars().getPublicCalendarRoot(); 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfHelper.java

    r299 r301  
    7878 
    7979  protected int currentMode = CalintfUtil.guestMode; 
    80    
    81   protected boolean ignoreCreator; 
    8280 
    8381  private transient Logger log; 
     
    9189   */ 
    9290  public CalintfHelper(Calintf cal, AccessUtil access, 
    93                        int currentMode, boolean ignoreCreator,  
     91                       int currentMode,  
    9492                       boolean debug) { 
    9593    this.cal = cal; 
    9694    this.access = access; 
    9795    this.currentMode = currentMode; 
    98     this.ignoreCreator = ignoreCreator; 
    9996    this.debug = debug; 
    10097  } 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java

    r299 r301  
    170170  private EventProperties sponsors; 
    171171 
    172   /** True if this is superuser access 
    173    */ 
    174   private boolean superUser; 
    175  
    176172  private int currentMode = CalintfUtil.guestMode; 
    177173 
     
    183179   */ 
    184180  //sprivate boolean readOnly; 
    185  
    186   /** Ignore owner for superuser 
    187    */ 
    188   private boolean ignoreCreator; 
    189181 
    190182  /** Current hibernate session - exists only across one user interaction 
     
    231223                      String user, 
    232224                      boolean publicAdmin, 
    233                       boolean superUser, 
    234225                      Groups groups, 
    235226                      String synchId, 
     
    238229    boolean userCreated = false; 
    239230 
    240     if (authenticatedUser == null) { 
    241       this.superUser = false;  // be safe 
    242     } 
    243  
    244231    BwUser authUser; 
    245232 
    246233    try { 
    247       access = new AccessUtil(superUser, debug); 
     234      access = new AccessUtil(debug); 
    248235 
    249236      objTimestamp = new Timestamp(System.currentTimeMillis()); 
    250237 
    251       this.superUser = superUser; 
    252238      this.synchId = synchId; 
    253239      log = Logger.getLogger(getClass()); 
     
    263249      user = authenticatedUser; 
    264250    } 
    265  
    266     ignoreCreator = false; 
    267251 
    268252    if (authenticatedUser == null) { 
     
    296280      getLogger().info("Authenticated user " + authenticatedUser + 
    297281                       " logged on"); 
    298       ignoreCreator = superUser; 
    299282 
    300283      if (authenticatedUser.equals(user)) { 
     
    311294    access.setAuthUser(authUser); 
    312295 
    313     events = new Events(this, access, currentMode,  
    314                         ignoreCreator, debug); 
    315  
    316     calendars = new Calendars(this, access, currentMode,  
    317                               ignoreCreator, debug); 
     296    events = new Events(this, access, currentMode, debug); 
     297 
     298    calendars = new Calendars(this, access, currentMode, debug); 
    318299 
    319300    categories = new EventProperties(this, access, currentMode,  
    320                                      ignoreCreator,  
    321301                                     "word", BwCategory.class.getName(), 
    322302                                     "getCategoryRefs", 
    323303                                     -1, debug); 
    324304    locations = new EventProperties(this, access, currentMode,  
    325                                     ignoreCreator,  
    326305                                    "address", BwLocation.class.getName(), 
    327306                                    "getLocationRefs", 
    328307                                     CalFacadeDefs.maxReservedLocationId, debug); 
    329308    sponsors = new EventProperties(this, access, currentMode,  
    330                                    ignoreCreator,  
    331309                                   "name", BwSponsor.class.getName(), 
    332310                                   "getSponsorRefs", 
     
    340318    } 
    341319    return userCreated; 
     320  } 
     321 
     322  public void setSuperUser(boolean val) { 
     323    access.setSuperUser(val); 
     324  } 
     325   
     326  public boolean getSuperUser() { 
     327    return access.getSuperUser(); 
    342328  } 
    343329 
     
    718704    BwTimeZone tz = new BwTimeZone(); 
    719705 
    720     if (currentMode == CalintfUtil.publicAdminMode) { 
    721       requireSuper(); 
    722     } 
    723  
    724706    if (currentMode == CalintfUtil.guestMode) { 
    725707      throw new CalFacadeAccessException(); 
     
    795777  public void clearPublicTimezones() throws CalFacadeException { 
    796778    checkOpen(); 
    797     requireSuper(); 
    798779 
    799780    /* Delete all public timezones */ 
     
    13291310    getLogger().debug(msg); 
    13301311  } 
    1331  
    1332   /* Ensure the current user has super user access. 
    1333    */ 
    1334   private void requireSuper() throws CalFacadeException { 
    1335     if ((currentMode == CalintfUtil.publicAdminMode) && superUser) { 
    1336       return; 
    1337     } 
    1338  
    1339     throw new CalFacadeAccessException(); 
    1340   } 
    13411312} 
    13421313 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/EventProperties.java

    r299 r301  
    9696   */ 
    9797  public EventProperties(Calintf cal, AccessUtil access,  
    98                          int currentMode, boolean ignoreCreator, 
     98                         int currentMode,  
    9999                         String keyFieldName, 
    100100                         String className, 
     
    102102                         int minId,  
    103103                         boolean debug) { 
    104     super(cal, access, currentMode, ignoreCreator, debug); 
     104    super(cal, access, currentMode, debug); 
    105105 
    106106    this.keyFieldName = keyFieldName; 
     
    189189    qstr.append(" ent where "); 
    190190    boolean setUser = CalintfUtil.appendPublicOrCreatorTerm(qstr, "ent", 
    191                                       currentMode, ignoreCreator); 
     191                                      currentMode, cal.getSuperUser()); 
    192192    qstr.append(" and ent.id=:id"); 
    193193 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Events.java

    r299 r301  
    105105   */ 
    106106  public Events(Calintf cal, AccessUtil access,  
    107                 int currentMode, boolean ignoreCreator, boolean debug) { 
    108     super(cal, access, currentMode, ignoreCreator, debug); 
     107                int currentMode, boolean debug) { 
     108    super(cal, access, currentMode, debug); 
    109109  } 
    110110 
     
    600600 
    601601    boolean setUser = doCalendarClause(sb, qevName, calendar, 
    602                                        currentMode, ignoreCreator); 
     602                                       currentMode, cal.getSuperUser()); 
    603603 
    604604    sb.append(") "); 
     
    650650 
    651651    Collection rs = getLimitedRecurrences(calendar, filter, startDate, endDate, 
    652                                           currentMode, ignoreCreator
     652                                          currentMode, cal.getSuperUser()
    653653                                          recurRetrieval); 
    654654    if (rs != null) { 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java

    r207 r301  
    109109  private boolean isOpen; 
    110110 
    111   /** True if this is superuser access - probably doesn't mean anything. 
    112    */ 
    113   private boolean superUser; 
    114  
    115111  /** Ignore owner for superuser 
    116112   */ 
     
    129125                      String user, 
    130126                      boolean publicAdmin, 
    131                       boolean superUser, 
    132127                      Groups groups, 
    133128                      String synchId, 
     
    136131    boolean userCreated = false; 
    137132 
    138     if (authenticatedUser == null) { 
    139       this.superUser = false;  // be safe 
    140     } 
    141  
    142133    try { 
    143134      objTimestamp = new Timestamp(System.currentTimeMillis()); 
    144135 
    145       this.superUser = superUser; 
    146136      this.synchId = synchId; 
    147137 
     
    158148 
    159149    return userCreated; 
     150  } 
     151 
     152  public void setSuperUser(boolean val) { 
     153  } 
     154   
     155  public boolean getSuperUser() { 
     156    return false; 
    160157  } 
    161158 
     
    898895  } 
    899896 
    900   /* Ensure the current user has super user access. 
    901    */ 
    902   protected void requireSuper() throws CalFacadeException { 
    903     if ((currentMode == CalintfDefs.publicAdminMode) && superUser) { 
    904       return; 
    905     } 
    906  
    907     throw new CalFacadeAccessException(); 
    908   } 
    909  
    910897  /* Ensure the current user is not a guest. 
    911898   */ 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/Calintf.java

    r207 r301  
    9696   * @param user        String user we are acting as. If null we use authUser 
    9797   * @param publicAdmin boolean true if this is a public events admin app 
    98    * @param superUser   boolean true if this is a super user 
    9998   * @param groups      Object allowing interface to determine user groups. 
    10099   * @param synchId     non-null if this is for synchronization. Identifies the 
     
    107106                      String user, 
    108107                      boolean publicAdmin, 
    109                       boolean superUser, 
    110108                      Groups groups, 
    111109                      String synchId, 
    112110                      boolean debug) throws CalFacadeException; 
     111 
     112  /** Called after init to flag this user as a super user.  
     113   * 
     114   * @param val       true for a super user 
     115   */ 
     116  public void setSuperUser(boolean val); 
     117 
     118  /** Called after init to flag this user as a super user.  
     119   * 
     120   * @return boolean true if super user 
     121   */ 
     122  public boolean getSuperUser(); 
    113123 
    114124  /** Get the current system (not db) stats 
  • trunk/calendar3/caldav/src/edu/rpi/cct/uwcal/caldav/CaldavBWIntf.java

    r297 r301  
    6161import org.bedework.calfacade.CalFacadeException; 
    6262import org.bedework.calfacade.svc.EventInfo; 
    63 import org.bedework.calfacade.svc.UserAuth; 
    6463import org.bedework.calsvc.CalSvc; 
    6564import org.bedework.calsvci.CalSvcI; 
     
    11811180       * user, if non-null, is the user calendar we want to access. 
    11821181       */ 
    1183       CalSvcIPars pars = new CalSvcIPars(account, UserAuth.noPrivileges, 
     1182      CalSvcIPars pars = new CalSvcIPars(account,  
    11841183                                         account, 
    11851184                                         envPrefix, 
  • trunk/calendar3/caldavClientApi/src/org/bedework/caldav/client/CalintfCaldavImpl.java

    r2 r301  
    109109                      String user, 
    110110                      boolean publicAdmin, 
    111                       boolean superUser, 
    112111                      Groups groups, 
    113112                      String synchId, 
    114113                      boolean debug) throws CalFacadeException { 
    115114    boolean userAdded = super.init(authenticatedUser, user, publicAdmin, 
    116                                    superUser, groups, synchId, debug); 
     115                                   groups, synchId, debug); 
    117116 
    118117    if (httpManager == null) { 
  • trunk/calendar3/calsvc/src/org/bedework/calsvc/CalSvc.java

    r297 r301  
    126126 
    127127  private boolean open; 
     128   
     129  private boolean superUser; 
    128130 
    129131  //private BwFilter currentFilter; 
     
    302304      throw new CalFacadeException(t); 
    303305    } 
     306  } 
     307 
     308  public void setSuperUser(boolean val) { 
     309    superUser = val; 
     310  } 
     311   
     312  public boolean getSuperUser() { 
     313    return superUser; 
    304314  } 
    305315 
     
    567577  public void saveTimeZone(String tzid, VTimeZone vtz) 
    568578          throws CalFacadeException { 
     579    // Not sure we want this. public admins may want to add timezones 
     580    if (isPublicAdmin() && !isSuper()) { 
     581      throw new CalFacadeAccessException(); 
     582    } 
     583     
    569584    timezones.saveTimeZone(tzid, vtz); 
    570585  } 
     
    584599 
    585600  public void clearPublicTimezones() throws CalFacadeException { 
     601    if (isPublicAdmin() && !isSuper()) { 
     602      throw new CalFacadeAccessException(); 
     603    } 
     604     
    586605    timezones.clearPublicTimezones(); 
    587606  } 
     
    12431262   */ 
    12441263  public boolean addLocation(BwLocation val) throws CalFacadeException { 
     1264    setupSharableEntity(val); 
     1265 
    12451266    updateOK(val); 
    1246  
    1247     setupSharableEntity(val); 
    12481267 
    12491268    if (findLocation(val) != null) { 
     
    13481367 
    13491368  public boolean addSponsor(BwSponsor val) throws CalFacadeException { 
     1369    setupSharableEntity(val); 
     1370 
    13501371    updateOK(val); 
    1351  
    1352     setupSharableEntity(val); 
    13531372 
    13541373    if (findSponsor(val) != null) { 
     
    19952014                                      pars.getUser(), 
    19962015                                      pars.getPublicAdmin(), 
    1997                                       pars.isSuperUser(), 
    19982016                                      getGroups(), 
    19992017                                      pars.getSynchId(), 
     
    21052123   */ 
    21062124  private boolean isSuper() throws CalFacadeException { 
    2107     return pars.getPublicAdmin() && pars.isSuperUser()
     2125    return pars.getPublicAdmin() && superUser
    21082126  } 
    21092127 
  • trunk/calendar3/calsvci/src/org/bedework/calsvci/CalSvcI.java

    r212 r301  
    107107  public abstract void init(CalSvcIPars pars) throws CalFacadeException; 
    108108 
     109  /** Called after init to flag this user as a super user.  
     110   * 
     111   * @param val       true for a super user 
     112   */ 
     113  public abstract void setSuperUser(boolean val); 
     114 
     115  /** Called after init to flag this user as a super user.  
     116   * 
     117   * @return boolean true if super user 
     118   */ 
     119  public abstract boolean getSuperUser(); 
     120 
    109121  /** Get the current stats 
    110122   * 
  • trunk/calendar3/calsvci/src/org/bedework/calsvci/CalSvcIPars.java

    r293 r301  
    5555package org.bedework.calsvci; 
    5656 
    57 import org.bedework.calfacade.svc.UserAuth; 
    58  
    5957import java.io.Serializable; 
    6058 
     
    6866  private String authUser; 
    6967 
    70   private int rights; 
    71  
    7268  /** The current user - null for guest 
    7369   */ 
     
    9793   * 
    9894   * @param authUser    String authenticated user of the application 
    99    * @param rights      int rights as defined in 
    100    *                     org.bedework.calfacade.svc.UserAuth 
    10195   * @param user        String user to act as 
    10296   * @param enzPrefix   String Environment properties prefix 
     
    108102   */ 
    109103  public CalSvcIPars(String authUser, 
    110                      int rights, 
    111104                     String user, 
    112105                     String envPrefix, 
     
    116109                     boolean debug) { 
    117110    this.authUser = authUser; 
    118     this.rights = rights; 
    119111    this.user = user; 
    120112    this.envPrefix = envPrefix; 
     
    133125 
    134126  /** 
    135    * @return int rights 
    136    */ 
    137   public int getRights() { 
    138     return rights; 
    139   } 
    140  
    141   /** 
    142127   * @param val String user to run as 
    143128   */ 
     
    195180  } 
    196181 
    197   /** Check for public events owner user 
    198    * 
    199    * @return boolean    true for public events owner user 
    200    */ 
    201   public boolean isOwnerUser() { 
    202     return (rights & UserAuth.publicEventUser) != 0; 
    203   } 
    204  
    205   /** Check for content admin user 
    206    * 
    207    * @return boolean    true for content admin user 
    208    */ 
    209   public boolean isContentAdminUser() { 
    210     return (rights & UserAuth.contentAdminUser) != 0; 
    211   } 
    212  
    213   /** Check for priv user 
    214    * 
    215    * @return boolean    true for super user 
    216    */ 
    217   public boolean isSuperUser() { 
    218     return (rights & UserAuth.superUser) != 0; 
    219   } 
    220  
    221182  /** 
    222183   * @return boolean true for guest 
     
    231192    sb.append("authUser="); 
    232193    sb.append(getAuthUser()); 
    233     sb.append(", rights="); 
    234     sb.append(getRights()); 
    235194    sb.append(", user="); 
    236195    sb.append(getUser()); 
     
    250209  public Object clone() { 
    251210    CalSvcIPars pars = new CalSvcIPars(getAuthUser(), 
    252                                        getRights(), 
    253211                                       getUser(), 
    254212                                       getEnvPrefix(), 
  • trunk/calendar3/synchml/src/edu/rpi/cct/uwcal/synchml/common/Synchml.java

    r293 r301  
    6464import org.bedework.calfacade.CalFacadeUtil; 
    6565import org.bedework.calfacade.svc.EventInfo; 
    66 import org.bedework.calfacade.svc.UserAuth; 
    6766import org.bedework.calsvc.CalSvc; 
    6867import org.bedework.calsvci.CalSvcI; 
     
    123122    this.deviceId = deviceId; 
    124123    this.debug = debug; 
    125     CalSvcIPars pars = new CalSvcIPars(account, UserAuth.noPrivileges, 
     124    CalSvcIPars pars = new CalSvcIPars(account,  
    126125                                       account, 
    127126                                       null,     // XXX Requires an env prefix 
  • trunk/calendar3/test/src/org/bedework/tests/calsvc/CalSvcTestWrapper.java

    r293 r301  
    130130    } 
    131131 
    132     CalSvcIPars pars = new CalSvcIPars(user, access, user,  
     132    CalSvcIPars pars = new CalSvcIPars(user, user,  
    133133                                       envPrefix, 
    134134                                       publicEvents, 
  • trunk/calendar3/timers/src/org/bedework/timers/service/DbPollerTimerService.java

    r293 r301  
    5555package org.bedework.timers.service; 
    5656 
    57  
    58 import org.bedework.calfacade.svc.UserAuth; 
    5957import org.bedework.calsvc.CalSvc; 
    6058import org.bedework.calsvci.CalSvcI; 
     
    140138  private void init() throws Throwable { 
    141139    svci = new CalSvc(); 
    142     CalSvcIPars pars = new CalSvcIPars(account, UserAuth.superUser, 
     140    CalSvcIPars pars = new CalSvcIPars(account,  
    143141                                       account, 
    144142                                       null,   // XXX needs envPrefix 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/BwAbstractAction.java

    r293 r301  
    706706   * @throws Throwable 
    707707   */ 
    708   public synchronized BwSession getState(HttpServletRequest request, 
    709                                          BwActionFormBase form, 
    710                                          MessageResources messages, 
    711                                          String adminUserId, 
    712                                          boolean admin) throws Throwable { 
     708  private synchronized BwSession getState(HttpServletRequest request, 
     709                                          BwActionFormBase form, 
     710                                          MessageResources messages, 
     711                                          String adminUserId, 
     712                                          boolean admin) throws Throwable { 
    713713    BwSession s = BwWebUtil.getState(request); 
    714714    HttpSession sess = request.getSession(false); 
     
    798798              getPublicAdmin(form), false, debug); 
    799799 
    800     /** Somewhere up there we may have to do more for user auth in the 
    801         session. This is where we can figure out this is a first call. 
    802      */ 
    803  
     800    /* 
    804801    UserAuth ua = null; 
    805802    UserAuthPar par = new UserAuthPar(); 
     
    821818      return null; 
    822819    } 
     820    */ 
    823821 
    824822    return s; 
     
    843841   * @throws CalFacadeException 
    844842   */ 
    845   protected boolean checkSvci(HttpServletRequest request, 
    846                               BwActionFormBase form, 
    847                               BwSession sess, 
    848                               int access, 
    849                               String user, 
    850                               boolean publicAdmin, 
    851                               boolean canSwitch, 
    852                               boolean debug) throws CalFacadeException { 
     843  private boolean checkSvci(HttpServletRequest request, 
     844                            BwActionFormBase form, 
     845                            BwSession sess, 
     846                            int access, 
     847                            String user, 
     848                            boolean publicAdmin, 
     849                            boolean canSwitch, 
     850                            boolean debug) throws CalFacadeException { 
    853851    /** Do some checks first 
    854852     */ 
     
    883881                          svci.getUser()); 
    884882      } 
     883       
     884      // XXX access - disable use of roles 
     885      access = svci.getUserAuth().getUsertype(); 
    885886    } else { 
    886887      if (debug) { 
     
    902903        } 
    903904         
    904         CalSvcIPars pars = new CalSvcIPars(user, access, runAsUser,  
     905        CalSvcIPars pars = new CalSvcIPars(user, //access,  
     906                                           runAsUser,  
    905907                                           form.getEnv().getAppPrefix(), 
    906908                                           publicAdmin, 
     
    915917 
    916918        cb.in(true); 
     919 
     920        UserAuth ua = null; 
     921        UserAuthPar par = new UserAuthPar(); 
     922        par.svlt = servlet; 
     923        par.req = request; 
     924 
     925        try { 
     926          ua = svci.getUserAuth(user, par); 
     927 
     928          form.assignAuthorisedUser(ua.getUsertype() != UserAuth.noPrivileges); 
     929          svci.setSuperUser((ua.getUsertype() & UserAuth.superUser) != 0); 
     930 
     931          // XXX access - disable use of roles 
     932          access = ua.getUsertype(); 
     933           
     934          if (debug) { 
     935            debugMsg("UserAuth says that current user has the type: " + 
     936                     ua.getUsertype()); 
     937          } 
     938        } catch (Throwable t) { 
     939          form.getErr().emit("org.bedework.client.error.exc", t.getMessage()); 
     940          form.getErr().emit(t); 
     941          return false; 
     942        } 
    917943      } catch (CalFacadeException cfe) { 
    918944        throw cfe; 
     
    921947      } 
    922948    } 
    923  
     949     
    924950    form.assignUserVO((BwUser)svci.getUser().clone()); 
    925951 
     
    957983   * 
    958984   * <p>They are there because some servlet containers (jetty for one) 
    959    * appear to be broken. Role mapping does not appear to work reliably. 
    960    * Thsi seems to have something to do with jetty doing internal redirects 
     985   * appeared to be broken. Role mapping does not appear to work reliably. 
     986   * This seems to have something to do with jetty doing internal redirects 
    961987   * to handle login. In the process it seems to lose the appropriate servlet 
    962988   * context and with it the mapping of roles. 
     
    967993   * @throws CalFacadeException 
    968994   */ 
    969   protected int getAccess(HttpServletRequest req, 
    970                           MessageResources messages) 
    971          throws CalFacadeException { 
     995  private int getAccess(HttpServletRequest req, 
     996                        MessageResources messages) throws CalFacadeException { 
    972997    int access = 0; 
    973998 
     
    9941019    } 
    9951020 
    996     /** This is how it out to look 
     1021    /** This is how it ought to look 
    9971022    if (req.isUserInRole("admin")) { 
    9981023      access += UserAuth.superUser;