Class SecurityUtil

java.lang.Object
org.opencastproject.security.util.SecurityUtil

public final class SecurityUtil extends Object
Opencast security helpers.
  • Field Details

    • PROPERTY_KEY_SYS_USER

      public static final String PROPERTY_KEY_SYS_USER
      The name of the key used to store the name of the system user in the global config.
      See Also:
  • Method Details

    • runAs

      public static void runAs(SecurityService sec, Organization org, User user, Runnable fn)
      Run function f in the context described by the given organization and user.
      Parameters:
      sec - Security service to use for getting data
      org - Organization to switch to
      user - User to switch to
      fn - Function to execute
    • createSystemUser

      public static User createSystemUser(String systemUserName, Organization org)
      Create a system user for the given organization with global and organization local admin role. Get the systemUserName from the global config where it is stored under PROPERTY_KEY_SYS_USER. In an OSGi environment this is typically done calling componentContext.getBundleContext().getProperty(PROPERTY_KEY_SYS_USER).
      See Also:
    • createAnonymousUser

      public static User createAnonymousUser(Organization org)
      Create the global anonymous user with the given organization.
      Parameters:
      org - the organization
      Returns:
      the global anonymous user
    • createSystemUser

      public static User createSystemUser(org.osgi.service.component.ComponentContext cc, Organization org)
      Create a system user for the given organization with global admin role. The system user name is fetched from the global OSGi config.
      See Also:
    • getSystemUserName

      public static String getSystemUserName(org.osgi.service.component.ComponentContext cc)
      Fetch the system user name from the configuration.
      See Also:
    • getUserAndOrganization

      public static Optional<Tuple<User,Organization>> getUserAndOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId)
      Get a user and an organization. Only returns something if both elements can be determined.
    • hostAndPort

      public static Tuple<String,Integer> hostAndPort(URL url)
      Extract hostname and port number from a URL.
    • checkAgentAccess

      public static void checkAgentAccess(SecurityService securityService, String agentId) throws UnauthorizedException
      Check if the current user has access to the capture agent with the given id.
      Parameters:
      agentId - The agent id to check.
      Throws:
      UnauthorizedException - If the user doesn't have access.
    • getCaptureAgentRole

      public static String getCaptureAgentRole(String agentId)
      Get the role name of the role required to access the capture agent with the given agent id.
      Parameters:
      agentId - The id of the agent to get the role for.
      Returns:
      The role name.
    • getEpisodeRoleId

      public static String getEpisodeRoleId(String mediaPackageId, String action)
      Get the episode role id for a mediapackage and an action
      Parameters:
      mediaPackageId - the id of the mediapackage
      action - the action as a string
      Returns:
      the role