Package com.polarion.platform.security
Interface ISecurityService
public interface ISecurityService
The entry point for authentication and authorization tasks. The
ISecurityService
manages both the users, roles and their relationship as well as
permissions and their relationship to users and roles.- Author:
- dobisekm
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addContextRoleToUser
(String userName, String roleId, IContextId ctx) void
addGlobalRoleToUser
(String userName, String roleId) void
authenticate
(String userName, String password, String source) Deprecated.boolean
void
changePassword
(String userName, String password) void
checkPermission
(IPermission permission, IContextId contextId) Check that the current user has been given permission in the given context.void
checkPermission
(String user, IPermission permission, IContextId contextId) Check that the given user has been given permission in the given context.void
checkPermission
(Subject user, IPermission permission, IContextId contextId) Check that given user has given permission in given context.constructPermission
(String permissionName) ConstructIPermission
class based on the permission name.void
createContextRole
(String roleId, IContextId ctx) Creates a context role.void
createGlobalRole
(String roleId) Creates a global role.void
createUser
(String userName, String password) <T> T
doAsSystemUser
(PrivilegedAction<T> action) <T> T
doAsSystemUser
(PrivilegedExceptionAction<T> action) Performs the given operation on behalf of the system user.<T> T
doAsUser
(Subject user, PrivilegedAction<T> action) <T> T
doAsUser
(Subject user, PrivilegedExceptionAction<T> action) Makes the given operation on behalf of the given user.findPermissionFactory
(String permissionName) getContextRoleAssignmentsForUser
(String userName, IContextId context) Returns the context roles assigned to the specific User together with the source of the assignment.getContextRolesForUser
(String userName, IContextId context) Returns the context roles assigned to the user.getContextRolesForUser
(String userName, IContextId... contextIds) Returns context roles assigned to the user for specified contexts.Shortcut forgetSubjectUser(getCurrentSubject())
getCurrentUserCredentials
(String credentialsKey) Shortcut forgetDefaultHatForContextRole
(IContextId ctx, String role) getParentPermissions
(IPermission permission) getRolesForUser
(String userName) Returns all global roles assigned to the given user.getRolesForUser
(String userName, IContextId context) Returns all global + context roles assigned to the user.getRolesForUser
(String userName, IContextId... contextIds) Returns all global + context roles assigned to the user for specified contexts.getSubjectCredentials
(Subject subj, String credentialsKey) Returns the credentials of the logged on user.getSubjectUser
(Subject subj) getUserAssignmentsForContextRole
(String roleId, IContextId context) Returns the Users assigned the specific role together with the source of the assignment.getUsersForContextRole
(String roleId, IContextId ctx) Returns the IDs of all users, that have the given role for the given context.getUsersForGlobalRole
(String roleId) Returns the IDs of all users, that do have the given role.Returns the IDs of all users, that have some role in the given context.boolean
hasAddonLicense
(String addonId) Checks whether the current user has a license for a specific add-on.boolean
hasPermission
(IPermission permission, IContextId contextId) Has the current user been given permission in the given context?boolean
hasPermission
(String user, IPermission permission, IContextId contextId) Has the given user been given permission in the given context?boolean
hasPermission
(Collection<String> roles, IPermission permission, IContextId contextId) boolean
hasPermission
(Subject user, IPermission permission, IContextId contextId) Has the given user been given permission in the given context?login()
Create a login flow builderDeprecated.Since 3.21.1 please uselogin()
andILogin.IUsingAuthenticator.with(com.polarion.platform.security.login.IPassword)
loginUserFromVault
(String userVaultKey, String source) Deprecated.loginWithToken
(String token, String source) Deprecated.Since 3.21.1 please uselogin()
andILogin.IUsingAuthenticator.with(com.polarion.platform.security.login.IToken)
void
Removes the credentials from the subject and logs it out.void
removeContextRole
(String roleId, IContextId ctx) Removes a global role.void
removeContextRoleFromUser
(String userName, String roleId, IContextId ctx) void
removeGlobalRole
(String roleId) Removes the global role.void
removeGlobalRoleFromUser
(String userName, String roleId) void
removeUser
(String userName) void
setDefaultHatForContextRole
(IContextId ctx, String role, String hatId) void
setDefaultHatForGlobalRole
(String role, String hatId) synchronizeBackendSecurity
(Collection<String> users, Collection<IContextId> contexts) Synchronizes the back-end's, that is the repository's security, with the current state.
-
Method Details
-
getCurrentSubject
Subject getCurrentSubject()- Returns:
- The Subject under which we operate right now.
-
getSystemUserSubject
Subject getSystemUserSubject()- Returns:
- The subject representing the system user.
-
getCurrentUser
String getCurrentUser()Shortcut forgetSubjectUser(getCurrentSubject())
- Returns:
- The ID of the current user or
null
if none exists. - See Also:
-
getSubjectUser
- Parameters:
subj
-- Returns:
- the ID of the user represented by the given subject or
null
ifsubj==null
or it does not represent a user.
-
getCurrentUserCredentials
Shortcut forgetSubjectUserCredentials(getCurrentSubject(), credentialsKey)
.- Parameters:
credentialsKey
-- Returns:
- the credentials or
null
if no user is logged on. - See Also:
-
getSubjectCredentials
Returns the credentials of the logged on user. This method is used for interactions with other systems, like SVN.- Parameters:
credentialsKey
- This is a string identification of the target system. This is a preparation for setups, where a single user will have different sets of credentials for different resources (e.g. for different SVN repositories). If the key is not recognized or is null, then the default credentials are returned.- Returns:
- the credentials or
null
if no user is logged on.
-
authenticate
@Deprecated void authenticate(@NotNull String userName, @Nullable String password, @NotNull String source) throws AuthenticationFailedException Deprecated.Since 3.21.1 please uselogin()
andILogin.IWithCredentials.verifyCredentials()
Verifies the provided user's credentials, but does not log them on.
Requires only one configured authentication provider. If more than one is configured, use the method with authenticatorId parameter- Parameters:
userName
-password
-source
- the authentication source, (e.g. "portal/IP" or "system"), used for writing to logs.- Throws:
AuthenticationFailedException
- if the provided credentials are invalid.IllegalArgumentException
- ifuserName
orsource
arenull
IllegalStateException
- if Polarion is configured to use more than one authentication provider.- Since:
- 3.17.0
-
login
@Deprecated Subject login(String userName, String password, String source) throws AuthenticationFailedException Deprecated.Since 3.21.1 please uselogin()
andILogin.IUsingAuthenticator.with(com.polarion.platform.security.login.IPassword)
Checks the given credentials and creates the Subject representing the logged on user. This subject can then be used as a parameter for other methods.
Requires only one configured authentication provider. If more than one is configured, use the method with authenticatorId parameter- Parameters:
userName
-password
-source
- the login source (e.g. "portal/IP" or "system"), only used for writing to logs.- Returns:
- authenticated subject (not
null
) - Throws:
AuthenticationFailedException
IllegalArgumentException
- ifuserName
orsource
arenull
IllegalStateException
- if Polarion is configured to use more than one authentication provider.
-
loginWithToken
@Deprecated @NotNull Subject loginWithToken(@NotNull String token, @NotNull String source) throws AuthenticationFailedException Deprecated.Since 3.21.1 please uselogin()
andILogin.IUsingAuthenticator.with(com.polarion.platform.security.login.IToken)
Checks the given token using the underlying security mechanism and creates the Subject representing the logged on user. This subject can then be used as a parameter to other methods.
To have Teamcenter Security Services (TCSS) login with a token, you need to first use the following method to create a Base64 encoded tokenTcssToken.create(String, String)
.
Alternatively, to use Kerberos/SPNEGO to login, you need to encode a token intoBase64
and then pass it directly.
Requires only one configured authentication provider. If more than one is configured, use the method with authenticatorId parameter- Parameters:
token
- The Token used for validation. Cannot benull
. The token must be encoded using theBase64
encoding scheme.source
- The login source (e.g. "portal/IP" or "system"), used only for writing to logs.- Returns:
- The authenticated subject (not
null
). - Throws:
AuthenticationFailedException
- If the given token is invalid.IllegalArgumentException
- If themechanism
,token
or thesource
arenull
.IllegalStateException
- if Polarion is configured to use more than one authentication provider.- Since:
- 3.17.0
-
loginUserFromVault
@Deprecated Subject loginUserFromVault(String userVaultKey, String source) throws AuthenticationFailedException Deprecated.Checks the given credentials and creates the Subject representing the logged on user. The subject can be then used as a parameter to other methods.- Parameters:
userVaultKey
-source
- The login source (e.g. "portal/IP" or "system"), used only for writing to logs.- Returns:
- authenticated subject (not
null
) - Throws:
AuthenticationFailedException
IllegalArgumentException
- ifuserName
orsource
arenull
- Since:
- 3.5.2
-
login
Create a login flow builder- Returns:
- new login flow builder
- Since:
- 3.21.1
-
logout
Removes the credentials from the subject and logs it out.- Parameters:
subj
-
-
doAsSystemUser
Performs the given operation on behalf of the system user.- Parameters:
action
- The action to run.- Throws:
Exception
-
doAsSystemUser
- Parameters:
action
- The action to run.- Returns:
- the value returned by the
action
- See Also:
-
doAsUser
Makes the given operation on behalf of the given user. The user must be logged on.- Parameters:
user
-action
- The action to run.- Returns:
- the value returned by the
action
- Throws:
Exception
-
doAsUser
- Parameters:
user
-action
- The value returned by theaction
.- Returns:
- The value returned by the
action
. - See Also:
-
canManageUsers
boolean canManageUsers() -
createUser
- Throws:
UnsupportedOperationException
-
changePassword
-
removeUser
-
constructPermission
ConstructIPermission
class based on the permission name.- Parameters:
permissionName
-- Returns:
IPermission
(notnull
)- Throws:
IllegalArgumentException
- if no such permission exists.
-
hasPermission
Has the current user been given permission in the given context?- Parameters:
permission
- permission (notnull
)contextId
- context id (can benull
)- Returns:
true
if permission is granted.
-
hasPermission
Has the given user been given permission in the given context?- Parameters:
user
- The user'sSubject
permission
- permissioncontextId
- context id (can benull
)- Returns:
true
if permission is granted.
-
hasPermission
Has the given user been given permission in the given context?- Parameters:
user
- idpermission
- permissioncontextId
- context id (can benull
)- Returns:
true
if permission is granted.
-
hasPermission
- Since:
- 3.5.0
-
checkPermission
Check that the current user has been given permission in the given context.- Parameters:
permission
- permission (notnull
)contextId
- context id (can benull
)- Throws:
PermissionDeniedException
- if permission is denied.
-
checkPermission
void checkPermission(Subject user, IPermission permission, IContextId contextId) throws PermissionDeniedException Check that given user has given permission in given context.- Parameters:
user
- user'sSubject
permission
- permissioncontextId
- The context id (can benull
)- Throws:
PermissionDeniedException
- if permission is denied.
-
checkPermission
void checkPermission(String user, IPermission permission, IContextId contextId) throws PermissionDeniedException Check that the given user has been given permission in the given context.- Parameters:
user
- idpermission
- permissioncontextId
- context id (can benull
)- Throws:
PermissionDeniedException
- if permission is denied.
-
getGlobalRoles
- Returns:
- The immutable
Collection
of role Ids, that exist in the system.
-
createGlobalRole
Creates a global role. Does nothing if the role already exists.- Parameters:
roleId
-
-
removeGlobalRole
Removes the global role. Does nothing, if no such role exists.Roles 'admin' and 'user' can't be removed. The method is returned without doing any action in such cases.
- Parameters:
roleId
-- Throws:
IllegalArgumentException
- if roleId is null.
-
getContextRoles
- Parameters:
ctx
-- Returns:
- The immutable
Collection
of role IDs, that exist in the given context.
-
createContextRole
Creates a context role. Does nothing if the role already exists.The context role will exist in the given context and the whole context tree below.
- Parameters:
roleId
-
-
removeContextRole
Removes a global role. Does nothing, if no such role exists.Note: The existence of a context role might be inherited from the parent context. If so then the deletion in the current context might have no impact.
- Parameters:
roleId
-- Throws:
IllegalArgumentException
- if roleId is null.
-
getUsersForGlobalRole
Returns the IDs of all users, that do have the given role.- Parameters:
roleId
-- Returns:
- A collection of Strings. Returns an empty collection for
an unknown role. Never returns
null
.
-
getUsersForContextRole
Returns the IDs of all users, that have the given role for the given context. (Project or Global level roles.)- Parameters:
roleId
-ctx
-- Returns:
- A collection of Strings. Returns an empty collection for
an unknown role. Never returns
null
.
-
getUserAssignmentsForContextRole
@NotNull Map<String,IRoleAssignment> getUserAssignmentsForContextRole(@NotNull String roleId, @Nullable IContextId context) Returns the Users assigned the specific role together with the source of the assignment. WARNING: If you are not interested in the sources, usegetUsersForContextRole(java.lang.String, com.polarion.subterra.base.data.identification.IContextId)
instead for better performance.- Returns:
- user to assignment map
- Since:
- 3.20.1
-
getContextRoleAssignmentsForUser
@NotNull Map<String,IRoleAssignment> getContextRoleAssignmentsForUser(@NotNull String userName, @Nullable IContextId context) Returns the context roles assigned to the specific User together with the source of the assignment. WARNING: If you are not interested in the sources, usegetContextRolesForUser(java.lang.String, com.polarion.subterra.base.data.identification.IContextId)
instead for better performance.- Returns:
- role to assignment map
- Since:
- 3.20.1
-
getUsersWithContextRole
Returns the IDs of all users, that have some role in the given context.- Parameters:
ctx
-- Returns:
- A collection of
String
user IDs. Never returnsnull
.
-
addGlobalRoleToUser
-
removeGlobalRoleFromUser
-
addContextRoleToUser
void addContextRoleToUser(@NotNull String userName, @NotNull String roleId, @NotNull IContextId ctx) -
removeContextRoleFromUser
void removeContextRoleFromUser(@NotNull String userName, @NotNull String roleId, @NotNull IContextId ctx) -
getRolesForUser
Returns all global roles assigned to the given user.- Parameters:
userName
-- Returns:
- mutable
Collection
ofString
roles
-
getRolesForUser
Returns all global + context roles assigned to the user.- Parameters:
userName
-context
- The contextId, might benull
, only global roles are returned in such cases.- Returns:
- mutable
Collection
ofString
roles
-
getContextRolesForUser
@NotNull Collection<String> getContextRolesForUser(@NotNull String userName, @NotNull IContextId context) Returns the context roles assigned to the user.- Parameters:
userName
-context
- The contextId, might not benull
.- Returns:
- mutable
Collection
ofString
roles.
-
getRolesForUser
@NotNull Map<IContextId,Collection<String>> getRolesForUser(@NotNull String userName, @NotNull IContextId... contextIds) Returns all global + context roles assigned to the user for specified contexts.- Parameters:
userName
-contextIds
- The contextIds, might not benull
- Returns:
- mutable
Map
ofIContextId
andCollection
of roles. - Since:
- 3.7.2
-
getContextRolesForUser
@NotNull Map<IContextId,Collection<String>> getContextRolesForUser(@NotNull String userName, @NotNull IContextId... contextIds) Returns context roles assigned to the user for specified contexts.- Parameters:
userName
-contextIds
- The contextIds, might not benull
.- Returns:
- mutable
Map
ofIContextId
andCollection
of roles. - Since:
- 3.7.2
-
findPermissionFactory
- Since:
- 3.5.0
-
getParentPermissions
- Since:
- 3.5.0
-
setDefaultHatForGlobalRole
-
getDefaultHatForGlobalRole
-
setDefaultHatForContextRole
-
getDefaultHatForContextRole
-
synchronizeBackendSecurity
ISecurityService.IBackendSecuritySynchronizationResult synchronizeBackendSecurity(Collection<String> users, Collection<IContextId> contexts) Synchronizes the back-end's, that is the repository's security, with the current state.Actual behaviour is implementation-dependent.
- Parameters:
users
- The names of users to be synchronized (notnull
)contexts
- ids of contexts to be synchronized (notnull
)- Returns:
- result of synchronization (not
null
) - Since:
- 3.1.1
-
getUserManagementPolicy
IUserManagementPolicy getUserManagementPolicy()- Since:
- 3.3.1
-
hasAddonLicense
Checks whether the current user has a license for a specific add-on.- Parameters:
addonId
-- Returns:
- true if the user has the add-on license.
- Since:
- 3.9.0
-
getUserAuthenticationProvidersManager
- Returns:
- user to authentication provider manager
- Since:
- 3.21.1
-
login()
andILogin.IWithCredentials.verifyCredentials()