Class SecurityUtil
java.lang.Object
org.opencastproject.security.util.SecurityUtil
Opencast security helpers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the key used to store the name of the system user in the global config. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckAgentAccess(SecurityService securityService, String agentId) Check if the current user has access to the capture agent with the given id.static UserCreate the global anonymous user with the given organization.static UsercreateSystemUser(String systemUserName, Organization org) Create a system user for the given organization with global and organization local admin role.static UsercreateSystemUser(org.osgi.service.component.ComponentContext cc, Organization org) Create a system user for the given organization with global admin role.static StringgetCaptureAgentRole(String agentId) Get the role name of the role required to access the capture agent with the given agent id.static StringgetEpisodeRoleId(String mediaPackageId, String action) Get the episode role id for a mediapackage and an actionstatic StringgetSystemUserName(org.osgi.service.component.ComponentContext cc) Fetch the system user name from the configuration.static Optional<Tuple<User, Organization>> getUserAndOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId) Get a user and an organization.hostAndPort(URL url) Extract hostname and port number from a URL.static voidrunAs(SecurityService sec, Organization org, User user, Runnable fn) Run functionfin the context described by the given organization and user.
-
Field Details
-
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
Run functionfin the context described by the given organization and user.- Parameters:
sec- Security service to use for getting dataorg- Organization to switch touser- User to switch tofn- Function to execute
-
createSystemUser
Create a system user for the given organization with global and organization local admin role. Get thesystemUserNamefrom the global config where it is stored underPROPERTY_KEY_SYS_USER. In an OSGi environment this is typically done callingcomponentContext.getBundleContext().getProperty(PROPERTY_KEY_SYS_USER).- See Also:
-
createAnonymousUser
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
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
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
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
Get the episode role id for a mediapackage and an action- Parameters:
mediaPackageId- the id of the mediapackageaction- the action as a string- Returns:
- the role
-