public class AuthorizationHelper extends Object
Constructor and Description |
---|
AuthorizationHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
addLoginNameAlias(String ambariUserName,
String loginAlias)
There are cases when users log-in with a login name that is
define in LDAP and which do not correspond to the user name stored
locally in ambari.
|
Collection<org.springframework.security.core.GrantedAuthority> |
convertPrivilegesToAuthorities(Collection<PrivilegeEntity> privilegeEntities)
Converts collection of RoleEntities to collection of GrantedAuthorities
|
static int |
getAuthenticatedId()
Gets the ID of the logged-in user.
|
static String |
getAuthenticatedName()
Gets the name of the logged in user.
|
static String |
getAuthenticatedName(String defaultUsername)
Gets the name of the logged-in user, if any.
|
static org.springframework.security.core.Authentication |
getAuthentication()
Retrieves the authenticated user and authorization details from the application's security context.
|
static List<String> |
getAuthorizationNames(org.springframework.security.core.Authentication authentication)
Retrieve authorization names based on the details of the authenticated user
|
static String |
getProxyUserName()
Gets the name of the logged-in proxy user, if any.
|
static String |
getProxyUserName(org.springframework.security.core.Authentication authentication)
Gets the name of the logged-in proxy user, if any.
|
static boolean |
isAuthorized(org.springframework.security.core.Authentication authentication,
ResourceType resourceType,
Long resourceId,
RoleAuthorization requiredAuthorization)
Determines if the specified authenticated user is authorized to perform an operation on the
specific resource by matching the authenticated user's authorizations with the one indicated.
|
static boolean |
isAuthorized(org.springframework.security.core.Authentication authentication,
ResourceType resourceType,
Long resourceId,
Set<RoleAuthorization> requiredAuthorizations)
Determines if the specified authenticated user is authorized to perform an operation on the
the specific resource by matching the authenticated user's authorizations with one from the
provided set of authorizations.
|
static boolean |
isAuthorized(ResourceType resourceType,
Long resourceId,
RoleAuthorization requiredAuthorization)
Determines if the authenticated user (from application's security context) is authorized to
perform an operation on the specific resource by matching the authenticated user's
authorizations with the one indicated.
|
static boolean |
isAuthorized(ResourceType resourceType,
Long resourceId,
Set<RoleAuthorization> requiredAuthorizations)
Determines if the authenticated user (from application's security context) is authorized to
perform an operation on the specific resource by matching the authenticated user's
authorizations with one from the provided set of authorizations.
|
static String |
resolveLoginAliasToUserName(String loginAlias)
Looks up the provided loginAlias in the current http session and return the ambari
user name that the alias is defined for.
|
static void |
verifyAuthorization(org.springframework.security.core.Authentication authentication,
ResourceType resourceType,
Long resourceId,
Set<RoleAuthorization> requiredAuthorizations)
Determines if the specified authenticated user is authorized to perform an operation on the
the specific resource by matching the authenticated user's authorizations with one from the
provided set of authorizations.
|
static void |
verifyAuthorization(ResourceType resourceType,
Long resourceId,
Set<RoleAuthorization> requiredAuthorizations)
Determines if the authenticated user (from application's security context) is authorized to
perform an operation on the the specific resource by matching the authenticated user's
authorizations with one from the provided set of authorizations.
|
public static String getProxyUserName(org.springframework.security.core.Authentication authentication)
authentication
- public static String getProxyUserName()
public Collection<org.springframework.security.core.GrantedAuthority> convertPrivilegesToAuthorities(Collection<PrivilegeEntity> privilegeEntities)
public static String getAuthenticatedName()
null
if none set.public static String getAuthenticatedName(String defaultUsername)
defaultUsername
- the value if there is no logged-in userpublic static int getAuthenticatedId()
public static boolean isAuthorized(ResourceType resourceType, Long resourceId, RoleAuthorization requiredAuthorization)
resourceType
- a resource type being acted uponresourceId
- the privilege resource id (or adminresource.id) of the relevant resourcerequiredAuthorization
- the required authorizationisAuthorized(Authentication, ResourceType, Long, Set)
public static boolean isAuthorized(ResourceType resourceType, Long resourceId, Set<RoleAuthorization> requiredAuthorizations)
resourceType
- a resource type being acted uponresourceId
- the privilege resource id (or adminresource.id) of the relevant resourcerequiredAuthorizations
- a set of requirements for which one match will allow authorizationisAuthorized(Authentication, ResourceType, Long, Set)
public static boolean isAuthorized(org.springframework.security.core.Authentication authentication, ResourceType resourceType, Long resourceId, RoleAuthorization requiredAuthorization)
authentication
- the authenticated user and associated access privilegesresourceType
- a resource type being acted uponresourceId
- the privilege resource id (or adminresource.id) of the relevant resourcerequiredAuthorization
- the required authorizationisAuthorized(Authentication, ResourceType, Long, Set)
public static boolean isAuthorized(org.springframework.security.core.Authentication authentication, ResourceType resourceType, Long resourceId, Set<RoleAuthorization> requiredAuthorizations)
Ambari
,
a cluster
, or a view
.
The specified resource id is the (admin)resource id referenced by a specific resource instance
such as a cluster or view.authentication
- the authenticated user and associated access privilegesresourceType
- a resource type being acted uponresourceId
- the privilege resource id (or adminresource.id) of the relevant resourcerequiredAuthorizations
- a set of requirements for which one match will allow authorizationpublic static void verifyAuthorization(ResourceType resourceType, Long resourceId, Set<RoleAuthorization> requiredAuthorizations) throws AuthorizationException
AuthorizationException
will be thrown.resourceType
- a resource type being acted uponresourceId
- the privilege resource id (or adminresource.id) of the relevant resourcerequiredAuthorizations
- a set of requirements for which one match will allow authorizationAuthorizationException
- if authorization is not grantedisAuthorized(ResourceType, Long, Set)
public static void verifyAuthorization(org.springframework.security.core.Authentication authentication, ResourceType resourceType, Long resourceId, Set<RoleAuthorization> requiredAuthorizations) throws AuthorizationException
AuthorizationException
will be thrown.authentication
- the authenticated user and associated access privilegesresourceType
- a resource type being acted uponresourceId
- the privilege resource id (or adminresource.id) of the relevant resourcerequiredAuthorizations
- a set of requirements for which one match will allow authorizationAuthorizationException
- if authorization is not grantedisAuthorized(Authentication, ResourceType, Long, Set)
public static org.springframework.security.core.Authentication getAuthentication()
public static void addLoginNameAlias(String ambariUserName, String loginAlias)
ambariUserName
- ambari user name for which the alias is to be stored in the sessionloginAlias
- the alias for the ambari user name.public static String resolveLoginAliasToUserName(String loginAlias)
loginAlias
- the login alias to resolve to ambari user namepublic static List<String> getAuthorizationNames(org.springframework.security.core.Authentication authentication)
authentication
- the authenticated user and associated access privilegesCopyright © 2022 Apache Software Foundation. All rights reserved.