Package com.appiancorp.services
Class ServiceContextFactory
java.lang.Object
com.appiancorp.services.ServiceContextFactory
- Direct Known Subclasses:
WebServiceContextFactory
Provides utility methods for creating new service contexts.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
static EscalatedServiceContext
createEscalatedServiceContext
(ServiceContext sc, String grantorUsername) Create ServiceContext based on sc that is escalated with the privileges of grantorUsernamestatic EscalatedServiceContext
createEscalatedServiceContext
(String username, String grantorUsername) Similar togetServiceContext(String)
, but also populates the grantorstatic ServiceContext
Retrieves a service context for an anonymous system administrator.static ServiceContext
Retrieves a service context for an anonymous system administrator, to be used for migration of EXISTING objects in the system.static User
Retrieves the user that is the system administrator.static ServiceContext
getServiceContext
(com.appiancorp.services.ASLIdentity id) Gets a service context for the ASLIdentity passed in.static ServiceContext
getServiceContext
(String username) Gets a service context for the username passed in.static User
Creates a user object whose username is the given name.static ServiceContext
Populates the i18n fields (locale, time zone, and calendar id) on the given service context object.static ServiceContext
populateServiceContextI18nSettings
(ServiceContext sc, Locale overrideLocale) Populates the i18n fields (locale, time zone, and calendar id) on the given service context object.static ServiceContext
populateServiceContextI18nSettings
(ServiceContext sc, Locale overrideLocale, boolean allowOverrideForDisabledLocale) Populates the i18n fields (locale, time zone, and calendar id) on the given service context object.
-
Field Details
-
ADMIN_USERNAME
- See Also:
-
-
Constructor Details
-
ServiceContextFactory
public ServiceContextFactory()
-
-
Method Details
-
getAdministratorUser
Retrieves the user that is the system administrator. This method can be used to consume a service as the administrator, but should obviously be used sparingly for security reasons.- Returns:
- a user who is the system administrator
-
getAdministratorServiceContext
Retrieves a service context for an anonymous system administrator. This method can be used to consume a service as the administrator, but should obviously be used sparingly for security reasons.- Returns:
- an anonymous administrator service context
-
getAdministratorServiceContextForMigration
Retrieves a service context for an anonymous system administrator, to be used for migration of EXISTING objects in the system. Other code may provide migration-specific behavior in response to a service context marked for migration (e.g. the Content engine will not set the modified timestamp, last modifier, or version UUID when creating/updating content objects with a service context marked for migration). WARNING! DO NOT USE this service context for non-migration code or when doing anything other than migrating existing objects in the system! WARNING! DO NOT USE this service context for creating NEW objects in the system, even during migration!- Returns:
- an anonymous administrator service context
-
getUser
Creates a user object whose username is the given name. This object can then be used to obtain aServiceContext
.- Parameters:
userName_
- the username to use- Returns:
- a
User
with the given username
-
getServiceContext
Gets a service context for the ASLIdentity passed in. The locale and timezone will NOT be automatically populated if this method is used to generate the service context, and must be manually populated. Some service methods do not work if these fields are not populated.- Parameters:
id
- the ASLIdentity for which to create the service context- Returns:
- the newly created service context
-
getServiceContext
Gets a service context for the username passed in. The locale and timezone will NOT be automatically populated if this method is used to generate the service context, and must be manually populated. Some service methods do not work if these fields are not populated.- Parameters:
username
- the username of the user for which to create the service context- Returns:
- the newly created service context
-
createEscalatedServiceContext
public static EscalatedServiceContext createEscalatedServiceContext(String username, String grantorUsername) Similar togetServiceContext(String)
, but also populates the grantor- Parameters:
username
- the username of the user for which to create the service contextgrantorUsername
- the username of the user granting permissions to the main user for privilege escalation- Returns:
- the newly created service context
-
createEscalatedServiceContext
public static EscalatedServiceContext createEscalatedServiceContext(ServiceContext sc, String grantorUsername) Create ServiceContext based on sc that is escalated with the privileges of grantorUsername- Parameters:
sc
- original ServiceContext where identity, locale, timezone and calendarId are copied fromgrantorUsername
- the name of the grantor for privilege escalation- Returns:
-
populateServiceContextI18nSettings
public static ServiceContext populateServiceContextI18nSettings(ServiceContext sc, Locale overrideLocale, boolean allowOverrideForDisabledLocale) Populates the i18n fields (locale, time zone, and calendar id) on the given service context object. If we do not detect an overridden locale, then the i18n settings are set using the user's preferences. Finally, if the users's preferences are not enabled for the site, the site defaults will be used.- Parameters:
sc
- A service context object.overrideLocale
- Locale object to overrideallowOverrideForDisabledLocale
- Boolean to decide if the locale is enabled or not before override. Override always if true, otherwise override only if the locale is enabled.- Returns:
- The given service context object but with the i18n fields set.
-
populateServiceContextI18nSettings
public static ServiceContext populateServiceContextI18nSettings(ServiceContext sc, Locale overrideLocale) Populates the i18n fields (locale, time zone, and calendar id) on the given service context object. If we do not detect an overridden locale, then the i18n settings are set using the user's preferences. If we detect an overridden locale but the locale is not enabled to the user, then the i18n settings are set using the user's preferences. Finally, if the users's preferences are not enabled for the site, the site defaults will be used.- Parameters:
sc
- A service context object.overrideLocale
- Locale object to override- Returns:
- The given service context object but with the i18n fields set.
-
populateServiceContextI18nSettings
Populates the i18n fields (locale, time zone, and calendar id) on the given service context object. Directly checks Spring for if an override locale has been set since some legacy services may call this method from places that are not Spring aware. Because of this possibility, we aggressively null check to avoid expensive try/catch blocks in this section of the code. Non-Spring aware places calling this method would kill the overridden locale if we did not check to see if one is set. If we do not detect an overridden locale, then the i18n settings are set using the user's preferences. Finally, if the users's preferences are not enabled for the site, the site defaults will be used.- Parameters:
sc
- A service context object.- Returns:
- The given service context object but with the i18n fields set.
-
areI18nSettingsPopulated
-