Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
devel:documentation:security:dev:security [2021/02/23 13:54] kucerar cas since information |
devel:documentation:security:dev:security [2023/12/01 16:18] chalupat [The authentication flow from front] |
||
---|---|---|---|
Line 2: | Line 2: | ||
===== Dictionary terms ===== | ===== Dictionary terms ===== | ||
- | * **Base permission** - basic permission, e.g. '' | ||
- | * **Group permission** - group permission could contain base permissions. Group is related to some domain object, e.g. '' | ||
- | * **Authority** - Group + base permission, e.g. '' | ||
- | |||
+ | * **Base permission** | ||
+ | * **Group permission** | ||
+ | * **Authority** | ||
===== API authentication ===== | ===== API authentication ===== | ||
Line 21: | Line 20: | ||
* if credentials do not match, pass request to another filter in chain | * if credentials do not match, pass request to another filter in chain | ||
- | In reality there is only one authentication servlet filter - '' | + | In reality there is only one authentication servlet filter - '' |
==== API endpoints ==== | ==== API endpoints ==== | ||
Line 27: | Line 26: | ||
There are 2 endpoints for successful user login: | There are 2 endpoints for successful user login: | ||
- | * / | + | * / |
* / | * / | ||
And one endpoint for user logout: | And one endpoint for user logout: | ||
- | | + | |
+ | | ||
In case of successful request on the endpoint, the token is passed in HTTP response header. Respose header is called '' | In case of successful request on the endpoint, the token is passed in HTTP response header. Respose header is called '' | ||
Line 37: | Line 37: | ||
==== Implemented authentication filters ==== | ==== Implemented authentication filters ==== | ||
- | Filter do not check authorization or user's permissions, | + | Filter do not check authorization or user's permissions, |
* BasicIdMAuthenticationFilter | * BasicIdMAuthenticationFilter | ||
- | | + | |
- | * internal API transforms the login and password and passes them to Authorization Manager | + | * internal API transforms the login and password and passes them to Authorization Manager |
- | * enabled by default | + | * enabled by default |
* JwtIdMAuthenticationFilter | * JwtIdMAuthenticationFilter | ||
- | | + | |
- | * tokens without expiration are taken as valid | + | * tokens without expiration are taken as valid |
- | * HMAC256 | + | * HMAC256 |
- | * enabled by default | + | * enabled by default |
* SsoIdmAuthenticationFilter | * SsoIdmAuthenticationFilter | ||
- | | + | |
- | * processes the result of the authentication in the HTTP header " | + | * processes the result of the authentication in the HTTP header " |
- | * **disabled by default**, can be enabled by the configuration property '' | + | * **disabled by default**, can be enabled by the configuration property '' |
* //external authentication server// | * //external authentication server// | ||
- | | + | |
- | * external filters are based on the same principles mentioned above | + | * external filters are based on the same principles mentioned above |
- | * primary purpose is to issue the internal IdM JWT token to user using the remote-auth endpoint | + | * primary purpose is to issue the internal IdM JWT token to user using the remote-auth endpoint |
- | * filter behaves quite permissively - if user accesses other endpoints then those for authentication, | + | * filter behaves quite permissively - if user accesses other endpoints then those for authentication, |
* CasIdmAuthenticationFilter | * CasIdmAuthenticationFilter | ||
- | | + | |
- | * Used for SSO against CAS | + | * Used for SSO against CAS |
- | * CAS need to be configured correctly - see tutorial TODO | + | * CAS need to be configured correctly - see tutorial TODO |
- | * By default this filter is disabled | + | * By default this filter is disabled |
- | * **Don' | + | * **Don' |
- | * Can be enabled by configuration property '' | + | * Can be enabled by configuration property '' |
===== Authorization and JWT token ===== | ===== Authorization and JWT token ===== | ||
Line 76: | Line 76: | ||
* iat - issued at date | * iat - issued at date | ||
+ | All IdM JWT tokens are signed using HMAC256 algorithm. The symmetric encryption key is configuration property of CzechIdM, stored as " | ||
- | All IdM JWT tokens are signed using HMAC256 algorithm. The symmetric encryption key is configuration property | + | Backend |
- | Backend of CzechIdM supports immediate detection of user's authorization change. Each modification type is implemented as application event processor, for further details please check the source code and tests :) When user's authorization changes, then persisted tokens, which user owns, are disabled => user is logged out. Types of modifications: | + | |
- | + | ||
- | | + | |
* disabling the user | * disabling the user | ||
* role's permissions change - revokes tokens of all users which have the role assigned | * role's permissions change - revokes tokens of all users which have the role assigned | ||
Line 89: | Line 88: | ||
Token can be used instead of a basic authentication to authenticate to the CzechIdM API. Token can be obtainted by [[# | Token can be used instead of a basic authentication to authenticate to the CzechIdM API. Token can be obtainted by [[# | ||
- | {{ : | + | {{ .: |
Use token agenda for generate system tokens, those can be used for system to system communication. Token expiration can be set optionally, but is not required. Token will grant the same authorities and permissions as token owner. | Use token agenda for generate system tokens, those can be used for system to system communication. Token expiration can be set optionally, but is not required. Token will grant the same authorities and permissions as token owner. | ||
If you have a valid token, you can use it, for example to get all identities: | If you have a valid token, you can use it, for example to get all identities: | ||
- | |||
< | < | ||
+ | |||
curl -X GET " | curl -X GET " | ||
+ | |||
</ | </ | ||
+ | |||
==== TokenManager ==== | ==== TokenManager ==== | ||
- | '' | + | '' |
===== Token expiration extension ===== | ===== Token expiration extension ===== | ||
- | By default both frontend (FE) and backend (BE) automatically extend the expiration of IdM JWT. In case of successful GET request on API, the token expiration is extended on BE and passed in HTTP response (watch out for CORS, has to be explicitly allowed, since the HTTP header is called " | + | By default both frontend (FE) and backend (BE) automatically extend the expiration of IdM JWT. In case of successful GET request on API, the token expiration is extended on BE and passed in HTTP response (watch out for CORS, has to be explicitly allowed, since the HTTP header is called " |
Developer tip: do not trust the console, especially while working with promises: | Developer tip: do not trust the console, especially while working with promises: | ||
Line 116: | Line 117: | ||
console.log(response.headers); | console.log(response.headers); | ||
} | } | ||
+ | |||
</ | </ | ||
Line 122: | Line 124: | ||
@since 10.5.0 | @since 10.5.0 | ||
- | User with authority '' | + | User with authority '' |
- | Feature is available from user main menu in application - any other active user can be selected and currently logged user will be logged as selected used. | + | |
Currently logged user token (see above) is filled with selected user authorities - original user is preserved as token owner. Return back (logout) to originally logged user is available from user main menu too. | Currently logged user token (see above) is filled with selected user authorities - original user is preserved as token owner. Return back (logout) to originally logged user is available from user main menu too. | ||
- | {{ : | + | {{ .: |
===== Enforce password change ===== | ===== Enforce password change ===== | ||
Line 135: | Line 137: | ||
<note tip>Flag for enforce password change can be filled by project processors (see password change, reset and generate events) or by GUI (flag added to password detail).</ | <note tip>Flag for enforce password change can be filled by project processors (see password change, reset and generate events) or by GUI (flag added to password detail).</ | ||
+ | |||
===== SSO ===== | ===== SSO ===== | ||
SSO support on FE is implemented by issuing the internal IdM JWT without the need to type in user's credentials. This is done by sending a " | SSO support on FE is implemented by issuing the internal IdM JWT without the need to type in user's credentials. This is done by sending a " | ||
- | We expect either HTTP header or Cookie to be the bearer of the remote authentication data. When the user accesses IdM, FE first tries to sign him in using the '' | + | We expect either HTTP header or Cookie to be the bearer of the remote authentication data. When the user accesses IdM, FE first tries to sign him in using the '' |
- | SSO authentication to AD domain can be configured with the help of SsoIdmAuthenticationFilter and Apache web server, which is installed in front of IdM. For more details about SSO configuration see [[tutorial: | + | SSO authentication to AD domain can be configured with the help of SsoIdmAuthenticationFilter and Apache web server, which is installed in front of IdM. For more details about SSO configuration see [[:tutorial: |
===== Two-factor authentication ===== | ===== Two-factor authentication ===== | ||
Line 147: | Line 150: | ||
@since 10.7.0 | @since 10.7.0 | ||
- | Feature is available from user profile (user main menu) in application. Two-factor authentication | + | Feature is available from user profile (user main menu) in application. Two-factor authentication is optional and can be enabled from user profile: |
- | {{ : | + | {{ .: |
- | After user sign in to CzechIdM using username and password, user will be prompted to provide an authentication code from a text message (notification) or from TOTP application. CzechIdM | + | After user sign in to CzechIdM using username and password, user will be prompted to provide an authentication code from a text message (notification) or from TOTP application. CzechIdM will only ask to provide two-factor authentication code again if user have logged out, is using a new device, or user session expires. |
Supported methods to get authentication code: | Supported methods to get authentication code: | ||
- | * **Application** - authentication code is generated by TOTP application (Google Authenticator, | + | * **Application** |
- | * **Sms notification** - authentication code is send by standard IdM notification. **Sms notifications have to be supported** to use this method ([[..: | + | |
The first authentication code obtained by selected method is needed to enable using two-factor authentication: | The first authentication code obtained by selected method is needed to enable using two-factor authentication: | ||
- | {{ : | + | {{ .: |
<note tip>HTTP Basic authentication cannot be used with two-factor authentication enabled.</ | <note tip>HTTP Basic authentication cannot be used with two-factor authentication enabled.</ | ||
Line 172: | Line 174: | ||
=== Configuration === | === Configuration === | ||
- | Basic configuration is available by [[..: | + | Basic configuration is available by [[..: |
- | Advanced: Is possible to change [[https:// | + | Advanced: Is possible to change [[https:// |
===== CAS authentication ===== | ===== CAS authentication ===== | ||
Line 182: | Line 184: | ||
This feature is disabled by default. If you want to enable it, see configuration properties [[..: | This feature is disabled by default. If you want to enable it, see configuration properties [[..: | ||
- | You need to have working CAS - You are able to log in directly to CAS. | + | You need to have working CAS - You are able to log in directly to CAS. Cas will return username of authenticated user. This username for CAS must be same as username in IdM. |
- | Cas will return username of authenticated user. This username for CAS must be same as username in IdM. | + | |
- | Other then that, you need to configure CAS. Mandatory CAS configuration is below | + | Other then that, you need to configure CAS. Mandatory CAS configuration is below cas.properties |
- | cas.properties | + | |
< | < | ||
+ | |||
... | ... | ||
cas.client.validator-type=CAS30 | cas.client.validator-type=CAS30 | ||
Line 196: | Line 197: | ||
cas.logout.followServiceRedirects=true | cas.logout.followServiceRedirects=true | ||
... | ... | ||
+ | |||
</ | </ | ||
idm-200.json | idm-200.json | ||
+ | |||
< | < | ||
{ | { | ||
Line 207: | Line 210: | ||
" | " | ||
} | } | ||
+ | |||
</ | </ | ||
- | When all configuration is done. You will be able to log into IdM **ONLY** via CAS. | + | When all configuration is done. You will be able to log into IdM **ONLY** |
- | **The authentication flow is**: | + | |
- | Access IdM URL -> if you are not logged in -> redirect to CAS -> log in -> redirect back to IdM -> You are authenticated in IdM | + | ===== OIDC authentication ===== |
- | Access IdM URL -> If you are logged in (jwt token is valid) | + | |
- | **Logout: | + | @since 13.1.0 |
- | Click on logout button in IdM -> Log out of IdM -> CAS logout URL is called | + | |
- | **Expired jwt token: | + | This feature is disabled by default. If you want to enable it, see configuration properties [[this> |
- | Logged out of IdM -> redirect to / | + | |
+ | CAS Service for OIDC configuration: | ||
+ | |||
+ | idm-oidc-201.json | ||
+ | < | ||
+ | |||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ==== The authentication flow from front ==== | ||
+ | |||
+ | {{ .: | ||
+ | |||
+ | 1) User isn't authenticated so frotend redirects user to api endpoint for OIDC login. | ||
+ | |||
+ | 2) IDM redirects user to OIDC providers login page (adress from .well-known endpoint on OIDC providers or can be overwritten in config) | ||
+ | |||
+ | 3) User login on OIDC providers page | ||
+ | |||
+ | 4) User gets redirected back to IDM with " | ||
+ | |||
+ | 5) IDM uses " | ||
+ | |||
+ | 6) After validation IDM creates CIDMST token (with externalID set to SID) | ||
+ | |||
+ | 7) IDM redirects to front with CIDMST | ||
+ | |||
+ | |||
+ | ==== The authentication flow from external application (hub, ...) ==== | ||
+ | |||
+ | {{ .: | ||
+ | |||
+ | 1) Authentication happens on external application | ||
+ | |||
+ | 2) When accessing a resource, external application presents access token (in header " | ||
+ | |||
+ | 3) IDM validates token on OIDC provider | ||
+ | |||
+ | 4) If user has access to resource returns it | ||
+ | |||
+ | |||
+ | ==== Single logout flow from IDM ==== | ||
+ | |||
+ | {{ .: | ||
+ | |||
+ | 1) User clicks on logout button so front redirects him to api endpoint for OIDC logout. | ||
+ | |||
+ | 2) IDM redirect him to logout endpoint on OIDC provider | ||
+ | |||
+ | 3) OIDC provider calls IMD and IDM invalidates all tokens with SID (from JWT token) | ||
+ |