Class CaldavManagedModeService

java.lang.Object
org.exoplatform.caldav.service.CaldavManagedModeService

@Service public class CaldavManagedModeService extends Object
Whether the instance chooses the CalDAV server for its users instead of letting each of them connect an account of their own.

One key, and only one. The whole mode is the presence of managedServerId in a single global setting: absent means off, present means on and names the server. The obvious alternative — an enabled boolean beside the id — buys nothing and adds a state that cannot be rendered honestly: enabled with no server. A single key cannot reach it.

The dependency runs from CaldavServerService to this class and never back. This one reads the registry's storage directly — the same storage that service reads, in the same add-on — precisely so that the registry service can call checkServerNotManaged(long) on the two writes that would otherwise leave the mode pointing at a server nobody can synchronise with. Injecting the registry service here instead would close a bean cycle, which Spring Boot refuses outright.

Nothing here provisions anything. Managed mode says which server a user's account belongs on; how that account acquires its credentials is a separate concern, and until it exists a managed user who never connected by hand is simply assigned and not provisioned. The screens state that rather than paper over it.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.exoplatform.commons.api.settings.data.Scope
    Where the choice lives: global, not per user.
    static final String
    The one key.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    checkServerNotManaged(long serverId)
    Refuses a registry write that would strand managed mode on a server it can no longer point at.
    void
    Switches managed mode off: users choose their own server again.
    org.exoplatform.caldav.model.CaldavManagedMode
    What the instance decided, and whether it applies to this caller.
    The registration the instance chose, or null when it chose none.
    boolean
    isManagedFor(String username)
    Whether this user is governed by the instance's choice, by name.
    boolean
    isManagedFor(org.exoplatform.services.security.Identity userIdentity)
    Whether this user is governed by the instance's choice.
    void
    saveManagedServer(long serverId)
    Records the server the instance synchronises everybody with.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MANAGED_SCOPE

      public static final org.exoplatform.commons.api.settings.data.Scope MANAGED_SCOPE
      Where the choice lives: global, not per user.
    • MANAGED_SERVER_KEY

      public static final String MANAGED_SERVER_KEY
      The one key. Its ABSENCE is what "managed mode is off" means, so nothing ever writes an empty value here — see clearManagedServer().

      The exclusions planned next (excludedGroups, groups whose members keep choosing their own server) belong beside this one, in this same scope: they qualify the same decision, and reading them will change isManagedFor(Identity) and nothing else.

      See Also:
  • Constructor Details

    • CaldavManagedModeService

      public CaldavManagedModeService()
  • Method Details

    • getManagedServerId

      public Long getManagedServerId()
      The registration the instance chose, or null when it chose none.
      Returns:
      the managed registration's identifier, null when managed mode is off
    • isManagedFor

      public boolean isManagedFor(org.exoplatform.services.security.Identity userIdentity)
      Whether this user is governed by the instance's choice.

      The per-viewer verdict, and the single place it is decided. Today it is "the instance chose a server", so the identity changes nothing; group exclusions land here — one method, rather than a condition scattered over every screen that hides an affordance.

      Parameters:
      userIdentity - the user being asked about, null for an anonymous caller
      Returns:
      true when the user's CalDAV account is the instance's to decide
    • isManagedFor

      public boolean isManagedFor(String username)
      Whether this user is governed by the instance's choice, by name.

      The identity resolution lives here rather than in the REST layer, which holds no ACL knowledge by contract: a controller has a username and nothing else, and turning one into an identity is exactly the kind of question this layer answers.

      Parameters:
      username - the user being asked about, blank for an anonymous caller
      Returns:
      true when the user's CalDAV account is the instance's to decide
    • getManagedMode

      public org.exoplatform.caldav.model.CaldavManagedMode getManagedMode(String username)
      What the instance decided, and whether it applies to this caller.

      The server is named, not merely identified: every screen showing this prints a name, and having each of them fetch the registry to turn an id into a name would be three round trips for one word. A row deleted out from under the setting leaves the name null rather than failing — the registry refuses that deletion, so this is the belt to that braces.

      Parameters:
      username - the user asking, blank for an anonymous caller
      Returns:
      the mode as it stands for that caller
    • saveManagedServer

      public void saveManagedServer(long serverId)
      Records the server the instance synchronises everybody with.

      The row has to exist and to be active. A deactivated registration is not a candidate: it is precisely the row nobody can connect to, and pointing the whole instance at it would take every user's connect affordance away in exchange for a server that answers nothing. The check is here rather than in the drawer for the usual reason — a form validates what someone types, a service validates what reaches it.

      Parameters:
      serverId - the registration to synchronise everybody with
      Throws:
      IllegalArgumentException - carrying caldav.managed.serverNotEligible when the row does not exist or is not active
    • clearManagedServer

      public void clearManagedServer()
      Switches managed mode off: users choose their own server again.

      The key is removed, never emptied. Absence is the whole definition of "off", and a setting holding an empty string would be a second way to say the same thing — the sort of second way that survives a refactoring of the first.

    • checkServerNotManaged

      public void checkServerNotManaged(long serverId)
      Refuses a registry write that would strand managed mode on a server it can no longer point at.

      Deactivating or deleting the managed row is not forbidden out of caution: either one leaves every user of the instance with no connect affordance — managed mode took it away — and a server that cannot serve them. The administrator switches managed mode off first, which is one click in the row above, and the refusal says so through the message code the admin snackbars already render.

      Parameters:
      serverId - the registration being deactivated or deleted
      Throws:
      IllegalArgumentException - carrying caldav.managed.serverInUse when that row is the managed one