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.

The decision itself — which connector is designated for the caldav kind, which groups it does not reach, whether it applies to a given user — is held and answered by ManagedConnectorService in commons-exo, the same for calendars and mailboxes. What this class adds is the CalDAV knowledge commons-exo does not have: that the designated id must be a registration that exists and is active, which provider it is configured with (the eligibility criterion commons-exo enforces), and the name the screens print instead of the id.

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.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    checkProviderChangeAllowed(long serverId, String providerName)
    Refuses the edit that would leave the managed row on a provider asking each user for something — the very thing designating it refused.
    void
    checkServerNotManaged(long serverId)
    Refuses the registry writes that would strand the mode.
    void
    Switches managed mode off: users choose their own server again, and the exclusions go with the designation they qualified.
    The registration this user is to be attached to at login, or null when managed mode does not apply to them - nothing designated, or a population the administrator excluded.
    The groups the instance's choice does not reach.
    org.exoplatform.caldav.model.CaldavManagedMode
    What the instance decided, and whether it applies to this caller.
    The registration the instance points everybody at, when managed mode is on.
    The registration managed mode governs this user with in the stored state, for a decision that disconnects them: the same rule as designatedServerFor(String), except that a user whose identity cannot be resolved is refused rather than counted as excluded.
    boolean
    isManagedFor(String username)
    Whether this user is governed by the instance's choice: managed mode is on and they belong to none of the excluded groups.
    void
    saveManagedServer(long serverId, List<String> excludedGroups, String username)
    Points the whole instance at one registration, minus the given groups.

    Methods inherited from class java.lang.Object

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

    • CaldavManagedModeService

      public CaldavManagedModeService()
  • Method Details

    • getManagedServerId

      public Long getManagedServerId()
      The registration the instance points everybody at, when managed mode is on.
      Returns:
      the managed registration's id, null when managed mode is off
    • getExcludedGroups

      public List<String> getExcludedGroups()
      The groups the instance's choice does not reach.
      Returns:
      the excluded eXo group ids, empty when none
    • isManagedFor

      public boolean isManagedFor(String username)
      Whether this user is governed by the instance's choice: managed mode is on and they belong to none of the excluded groups.

      Nobody is managed on nobody's behalf: an anonymous caller has no account to govern, and answering true would hide affordances from a page that has no user to hide them from.

      Parameters:
      username - the eXo login, null or blank for an anonymous caller
      Returns:
      true when the choice applies to them
    • designatedServerFor

      public Long designatedServerFor(String username)
      The registration this user is to be attached to at login, or null when managed mode does not apply to them - nothing designated, or a population the administrator excluded. The caller does not need to know which: in both cases it does nothing. Recomputed on every call, never stored.
      Parameters:
      username - the eXo login, null or blank for an anonymous caller
      Returns:
      the designated registration's id, or null
    • governingServerFor

      public Long governingServerFor(String username)
      The registration managed mode governs this user with in the stored state, for a decision that disconnects them: the same rule as designatedServerFor(String), except that a user whose identity cannot be resolved is refused rather than counted as excluded.
      Parameters:
      username - the eXo login
      Returns:
      the designated registration's id, or null when managed mode does not apply
      Throws:
      IllegalStateException - when exclusions apply and the identity cannot be resolved
    • 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 eXo login of the caller, null or blank when anonymous
      Returns:
      the mode as it stands for that caller
    • saveManagedServer

      public void saveManagedServer(long serverId, List<String> excludedGroups, String username) throws IllegalAccessException
      Points the whole instance at one registration, minus the given groups.

      This class refuses a registration that does not exist or is deactivated — the row nobody can connect to, which only this add-on can recognise. Everything else is commons-exo's, in one call so that nothing is written when anything is refused: that the caller is an administrator, that the row's provider asks the user for nothing (Personal cannot be designated, because it would produce an instance connector nobody can connect through), and the order of the two writes.

      Parameters:
      serverId - technical identifier of the registration
      excludedGroups - the eXo group ids the choice must not reach, null for none
      username - the eXo login of the caller
      Throws:
      IllegalAccessException - when the caller is not an administrator
      IllegalArgumentException - carrying caldav.managed.serverNotEligible when the row is unknown or deactivated, or the commons-exo code when its provider asks the user for something
    • clearManagedServer

      public void clearManagedServer(String username) throws IllegalAccessException
      Switches managed mode off: users choose their own server again, and the exclusions go with the designation they qualified. The accounts managed mode attached are disconnected in the background; the accounts users connected themselves are untouched.
      Parameters:
      username - the eXo login of the caller
      Throws:
      IllegalAccessException - when the caller is not an administrator
    • checkProviderChangeAllowed

      public void checkProviderChangeAllowed(long serverId, String providerName)
      Refuses the edit that would leave the managed row on a provider asking each user for something — the very thing designating it refused. Any other row may change provider freely.
      Parameters:
      serverId - the registration being edited
      providerName - the provider it would be configured with after the edit
      Throws:
      IllegalArgumentException - carrying caldav.managed.providerNotEligible when the row is the managed one and the provider is not eligible
    • checkServerNotManaged

      public void checkServerNotManaged(long serverId)
      Refuses the registry writes that would strand the mode.
      Parameters:
      serverId - the registration about to be deactivated or deleted
      Throws:
      IllegalArgumentException - carrying caldav.managed.serverInUse when managed mode points at that row