public class AccessControlManager extends Object
Modifier and Type | Class and Description |
---|---|
static class |
AccessControlManager.AccessTokens
Encapsulation of Access and Refresh tokens.
|
static class |
AccessControlManager.LoginResult
Encapsulation of login result.
|
static class |
AccessControlManager.NotificationEmailType
Email notification types enumeration.
|
Modifier and Type | Field and Description |
---|---|
static String |
ECOACCOUNTS_GROUP
The group name of the Eco-account enabled users.
|
static String |
ECOCREDITCALC_CLIENTID
The client ID to use in order to login and access the Eco-credit calculator
REST services.
|
static String |
ENDUSERMODULE_CLIENTID
The client ID to use in order to login and access the EndUserModule REST
services.
|
static Logger |
logger
Logger.
|
static String |
RECYCLEMODULE_CLIENTID
The client ID to use in order to login and access the RecycleModule REST
services.
|
static String |
RETAILERMODULE_CLIENTID
The client ID to use in order to login and access the RetailerModule REST
services.
|
static int |
UUIDLENGTH
Keycloak default UUID length (as of version 4.8.3.Final).
|
Constructor and Description |
---|
AccessControlManager() |
Modifier and Type | Method and Description |
---|---|
static void |
closeAdminAPIClient()
Close the Access Control Manager Admin API client, logging out the user also.
|
static boolean |
createEcoAccountUser(String username,
String password,
String email,
String firstname,
String lastname,
String locale)
Create an Eco-account enabled user in the Access Control Manager.
|
static AccessControlManager.LoginResult |
ecoAccountLogin(String ClientID,
String Username,
String Password)
Reverse proxy of
getAccessTokens(String, String, String) that
first checks if the user belongs to the Eco-accounts ACM group and has
verified the registration email address. |
static boolean |
endSession(String ClientID,
AccessControlManager.AccessTokens accessTokens)
Perform a session logout on the Access Control Manager, using the
corresponding Client ID and access/refresh tokens.
|
static boolean |
existsGroupUUID(String groupuuid)
Check if the specified group Universally Unique ID exists in the Access
Control Manager.
|
static boolean |
existsUserUUID(String useruuid)
Check if the specified user Universally Unique ID exists in the Access
Control Manager.
|
static AccessControlManager.AccessTokens |
getAccessTokens(String ClientID,
String Username,
String Password)
Perform a session login on the Access Control Manager and get the
access/refresh tokens.
|
static String |
getEmail(String useruuid)
Retrieve a user's email address from Universally Unique ID.
|
static String |
getEmailUUID(String email)
Get the email's Universally Unique ID from the Access Control Manager.
|
static String |
getGroupUUID(String group)
Get the group's Universally Unique ID from the Access Control Manager.
|
static String |
getPrincipalName(javax.ws.rs.core.SecurityContext securityContext)
Get the user name from the specified
SecurityContext . |
static String |
getUsername(String useruuid)
Retrieve a user's username from Universally Unique ID.
|
static String |
getUsernameUUID(String username)
Get the username's Universally Unique ID from the Access Control Manager.
|
static boolean |
isEnabled() |
static boolean |
isProperFormatUUID(String useruuid)
Check the format and NOT THE EXISTENCE of the specified
String
against the specification of a user's UUID. |
static boolean |
isUserAuthenticated(javax.ws.rs.core.SecurityContext securityContext)
Check if the specified
SecurityContext contains an authenticated
user. |
static boolean |
isUserEmailVerified(String useruuid)
Check if the specified user has verified his email address.
|
static AccessControlManager.AccessTokens |
refreshAccessTokens(String ClientID,
AccessControlManager.AccessTokens accessTokens,
boolean check_expiration)
Perform a refresh of the access tokens, optionally check the expiration.
|
static boolean |
removeEcoAccountUser(String useruuid)
Remove the Eco-account enabled user from the Access Control Manager.
|
static boolean |
sendNotificationEmail(String useruuid,
AccessControlManager.NotificationEmailType emailtype)
Send notification email to a registered user.
|
static boolean |
sendResetPasswordEmail(String useruuid)
Send the reset password email to a registered user, in order to change his
password in case he forgot it.
|
static boolean |
sendVerificationEmail(String useruuid)
Send the verification email to a registered but not yet enabled user, in
order to verify his email address and enable the account.
|
static boolean |
setUserEmailVerified(String useruuid,
boolean emailVerified)
Set the email verification status of the specified user.
|
static boolean |
updateEcoAccountUser(String useruuid,
String password,
String email,
String firstname,
String lastname,
String locale)
Update the user representation in the Access Control Manager.
|
public static final Logger logger
public static final String ECOCREDITCALC_CLIENTID
public static final String ENDUSERMODULE_CLIENTID
public static final String RECYCLEMODULE_CLIENTID
public static final String RETAILERMODULE_CLIENTID
public static final int UUIDLENGTH
public static final String ECOACCOUNTS_GROUP
public static boolean isEnabled()
true
if Access Control Manager is enabled,
false
otherwise.public static boolean isUserAuthenticated(javax.ws.rs.core.SecurityContext securityContext)
SecurityContext
contains an authenticated
user.securityContext
- the SecurityContext
to check for user
authentication.true
if the user is authenticated and user name can be
retrieved, false
otherwise.public static boolean isUserEmailVerified(String useruuid)
useruuid
- the user's Universally Unique ID.true
if email address is verified, false
otherwise.public static boolean setUserEmailVerified(String useruuid, boolean emailVerified)
useruuid
- the user's Universally Unique ID.emailVerified
- flag to denote if the email should be set as verified or
not.true
if set properly, false
otherwise.public static String getPrincipalName(javax.ws.rs.core.SecurityContext securityContext)
SecurityContext
.securityContext
- the SecurityContext
.String
if the SecurityContext
has an
authenticated user, null
otherwise.public static String getUsernameUUID(String username)
username
- the registered user's Access Control Manager username.null
otherwise.public static String getEmailUUID(String email)
email
- the registered user's Access Control Manager email.null
otherwise.public static String getGroupUUID(String group)
group
- the Access Control Manager group name.null
otherwise.public static boolean existsUserUUID(String useruuid)
useruuid
- the Universally Unique ID.true
if exists, false
otherwise.public static boolean existsGroupUUID(String groupuuid)
groupuuid
- the Universally Unique ID.true
if exists, false
otherwise.public static String getEmail(String useruuid)
useruuid
- the Universally Unique ID.String
if user exists and email can be
retrieved, null
otherwise.public static String getUsername(String useruuid)
useruuid
- the Universally Unique ID.String
if user exists and username can be
retrieved, null
otherwise.public static boolean isProperFormatUUID(String useruuid)
String
against the specification of a user's UUID. This can be used for quick
testing without contacting the Access Control Manager, of whether the
specified String
could represent a user's UUID. For UUID existence,
use existsUserUUID(String)
.useruuid
- the Universally Unique ID.true
if the format is as expected, false
otherwise.public static AccessControlManager.LoginResult ecoAccountLogin(String ClientID, String Username, String Password) throws IllegalArgumentException
getAccessTokens(String, String, String)
that
first checks if the user belongs to the Eco-accounts ACM group and has
verified the registration email address.ClientID
- registered client ID on Access Control Manager.Username
- registered user name on Access Control Manager.Password
- registered user's password on Access Control Manager.AccessControlManager.AccessTokens
object filled with valid token from the
Access Control Manager, or null
on failure.IllegalArgumentException
- if the provided ClientID or credentials are
not recognized by the Access Control
Manager.public static AccessControlManager.AccessTokens getAccessTokens(String ClientID, String Username, String Password) throws IllegalArgumentException
ClientID
- registered client ID on Access Control Manager.Username
- registered user name on Access Control Manager.Password
- registered user's password on Access Control Manager.AccessControlManager.AccessTokens
object filled with valid token from the
Access Control Manager, or null
on failure.IllegalArgumentException
- if the provided ClientID or credentials are
not recognized by the Access Control
Manager.public static AccessControlManager.AccessTokens refreshAccessTokens(String ClientID, AccessControlManager.AccessTokens accessTokens, boolean check_expiration)
ClientID
- registered client ID on Access Control Manager.accessTokens
- an AccessControlManager.AccessTokens
object filled with valid
token from the Access Control Manager that correspond
to the session asked to end.check_expiration
- if true
then check the expiration of the
specified access tokens and only perform the refresh
if they have expired.null
otherwise.public static boolean endSession(String ClientID, AccessControlManager.AccessTokens accessTokens)
true
is returned. The
responsible authority for this is the Access Control Manager, where all
session handling is done. An HTTP 200 status code in the response indicates
the proper acceptance of the request and if the Access Control Manager has no
issue, the user session is then ended.ClientID
- registered client ID on Access Control Manager.accessTokens
- an AccessControlManager.AccessTokens
object filled with valid token
from the Access Control Manager that correspond to the
session asked to end.true
if the session end request is performed without
errors, false
otherwise.public static void closeAdminAPIClient()
public static boolean createEcoAccountUser(String username, String password, String email, String firstname, String lastname, String locale)
username
- the username.password
- the password.email
- the email.firstname
- the user's real world first name.lastname
- the user's real world family name.locale
- ISO 639 alpha-2 language code for this locale. Supported
values are configured in the ACM.true
if the user account was created successfully,
false
otherwise.public static boolean sendVerificationEmail(String useruuid)
useruuid
- the user's Universally Unique ID.true
if the user was found, he is not yet enabled and
the email was sent successfully, false
otherwise.public static boolean sendResetPasswordEmail(String useruuid)
useruuid
- the user's Universally Unique ID.true
if the user was found and the email was sent
successfully, false
otherwise.public static boolean sendNotificationEmail(String useruuid, AccessControlManager.NotificationEmailType emailtype)
useruuid
- the user's Universally Unique ID.emailtype
- email notification type.true
if the user was found and the email was sent
successfully, false
otherwise.public static boolean removeEcoAccountUser(String useruuid)
useruuid
- the user's Universally Unique ID.true
if the account removal was successful,
false
otherwise.public static boolean updateEcoAccountUser(String useruuid, String password, String email, String firstname, String lastname, String locale)
useruuid
- the user's Universally Unique ID.password
- the updated password.email
- the updated email.firstname
- the updated user's real world first name.lastname
- the updated user's real world family name.locale
- ISO 639 alpha-2 language code for this locale. Supported
values are configured in the ACM.true
if the user account was updated successfully or no
field was provided (no change required), false
otherwise.Copyright © 2020. All rights reserved.