Provides helper methods for REST api.
More...
|
| __construct (UserDao $userDao, Session $session, DbHelper $dbhelper) |
|
| checkUsernameAndPassword ($userName, $password) |
| Check the username and password against the database. More...
|
|
| verifyAuthToken ($authHeader, &$userId, &$tokenScope) |
|
| isTokenActive ($valuesFromDb, $tokenId) |
|
| getSession () |
|
| updateUserSession ($userId, $scope, $groupName=null) |
| Update the session using updateSession(). More...
|
|
| generateJwtToken ($expire, $created, $jti, $scope, $key) |
|
| getMaxTokenValidity () |
|
| userHasGroupAccess ($userId, $groupName) |
| Verify if given User Id has access to given Group name. More...
|
|
| isGroupExisting ($groupName) |
| Verify if given Group name exists. More...
|
|
Provides helper methods for REST api.
Definition at line 37 of file AuthHelper.php.
◆ __construct()
Fossology\UI\Api\Helper\AuthHelper::__construct |
( |
UserDao |
$userDao, |
|
|
Session |
$session, |
|
|
DbHelper |
$dbhelper |
|
) |
| |
◆ checkUsernameAndPassword()
Fossology\UI\Api\Helper\AuthHelper::checkUsernameAndPassword |
( |
|
$userName, |
|
|
|
$password |
|
) |
| |
Check the username and password against the database.
If the user is not 'Default User' and is valid, this function also update session using updateSession().
- Parameters
-
string | $userName | Username |
string | $password | Password |
- Returns
- boolean True if user is valid, false otherwise.
- See also
- updateSession()
Definition at line 85 of file AuthHelper.php.
◆ generateJwtToken()
Fossology\UI\Api\Helper\AuthHelper::generateJwtToken |
( |
|
$expire, |
|
|
|
$created, |
|
|
|
$jti, |
|
|
|
$scope, |
|
|
|
$key |
|
) |
| |
Generates new JWT token.
- Parameters
-
string | $expire | When the token will expire ('YYYY-MM-DD') |
string | $created | When the token was created ('YYYY-MM-DD') |
string | $jti | Token id (pat_pk.user_pk ) |
string | $scope | Token scope key |
string | $key | Token secret key |
- Returns
- string New JWT token
Definition at line 218 of file AuthHelper.php.
◆ getMaxTokenValidity()
Fossology\UI\Api\Helper\AuthHelper::getMaxTokenValidity |
( |
| ) |
|
Get the value for maximum API token validity from sysconfig table.
- Returns
- integer The value stored in DB.
- See also
- Fossology::UI::Api::Helper::getMaxTokenValidity()
Definition at line 236 of file AuthHelper.php.
◆ getSession()
Fossology\UI\Api\Helper\AuthHelper::getSession |
( |
| ) |
|
Get the current Symfony session
- Returns
- Session
Definition at line 182 of file AuthHelper.php.
◆ isDateExpired()
Fossology\UI\Api\Helper\AuthHelper::isDateExpired |
( |
|
$date | ) |
|
|
private |
Check if the given date is expired (is past).
- Parameters
-
string | $date | Date in Y-m-d format |
- Returns
- boolean True if the date is of past.
Definition at line 152 of file AuthHelper.php.
◆ isGroupExisting()
Fossology\UI\Api\Helper\AuthHelper::isGroupExisting |
( |
|
$groupName | ) |
|
Verify if given Group name exists.
- Parameters
-
string | $groupName | Name of the group to update session with. |
- Returns
- void
- Exceptions
-
HttpForbiddenException | If the group does not exist. |
Definition at line 268 of file AuthHelper.php.
◆ isTokenActive()
Fossology\UI\Api\Helper\AuthHelper::isTokenActive |
( |
|
$valuesFromDb, |
|
|
|
$tokenId |
|
) |
| |
Check if the token is still active and not expired.
- Parameters
-
array | $valuesFromDb | Values from DB. |
int | $tokenId | Token id (pat_pk) |
- Exceptions
-
HttpForbiddenException | If the token is expired. |
Definition at line 167 of file AuthHelper.php.
◆ loadJwks()
static Fossology\UI\Api\Helper\AuthHelper::loadJwks |
( |
| ) |
|
|
static |
Load the JWK array.
Load the JWK list from cache file (if exists), otherwise download from server and cache it. The cache is stored for 24 hours.
- Returns
- CachedKeySet JWK keys
- Exceptions
-
UnexpectedValueException | Throws exception if jwk does not contain "keys" |
Definition at line 333 of file AuthHelper.php.
◆ updateUserSession()
Fossology\UI\Api\Helper\AuthHelper::updateUserSession |
( |
|
$userId, |
|
|
|
$scope, |
|
|
|
$groupName = null |
|
) |
| |
Update the session using updateSession().
- Parameters
-
int | $userId | User id from the JWT. |
string | $scope | Scope of the current token. |
string | $groupName | Name of the group to update session with. |
- See also
- updateSession()
Definition at line 195 of file AuthHelper.php.
◆ userHasGroupAccess()
Fossology\UI\Api\Helper\AuthHelper::userHasGroupAccess |
( |
|
$userId, |
|
|
|
$groupName |
|
) |
| |
Verify if given User Id has access to given Group name.
- Parameters
-
int | $userId | User id from the JWT. |
string | $groupName | Name of the group to verify access to. |
- Returns
- void
- Exceptions
-
HttpForbiddenException | If the user does not have access to group. |
Definition at line 249 of file AuthHelper.php.
◆ validateOauthLogin()
Fossology\UI\Api\Helper\AuthHelper::validateOauthLogin |
( |
|
$jwtToken, |
|
|
& |
$userId, |
|
|
& |
$tokenScope |
|
) |
| |
|
private |
Validate OAuth token.
Oauth tokens are majorly signed by RS256. Verify the key with library against the JWKs. If valid, then fetch the user id and token scope from the DB against the client_id
stored in the token.
- Parameters
-
| string | $jwtToken | Token from header |
[out] | integer | $userId | User ID from DB |
[out] | string | $tokenScope | Token scope from DB |
- Returns
- void
- Exceptions
-
HttpForbiddenException | If the token is expired. |
Definition at line 290 of file AuthHelper.php.
◆ validateTokenLogin()
Fossology\UI\Api\Helper\AuthHelper::validateTokenLogin |
( |
|
$jwtToken, |
|
|
|
$jwtTokenPayloadDecoded, |
|
|
& |
$userId, |
|
|
& |
$tokenScope |
|
) |
| |
|
private |
Validate JWT token from FOSSology.
The token id is base64 encoded in JTI and the key for it will be fetched from the DB to validate the token. Once valid and active, the userid and scope will be taken from the DB.
- Parameters
-
| string | $jwtToken | Token from header |
| object | $jwtTokenPayloadDecoded | Decoded token |
[out] | integer | $userId | User ID from DB |
[out] | string | $tokenScope | Token scope from DB |
- Returns
- void
- Exceptions
-
HttpForbiddenException | If the token is expired. |
Definition at line 403 of file AuthHelper.php.
◆ verifyAuthToken()
Fossology\UI\Api\Helper\AuthHelper::verifyAuthToken |
( |
|
$authHeader, |
|
|
& |
$userId, |
|
|
& |
$tokenScope |
|
) |
| |
Verify the JWT/oauth token sent by user.
- Parameters
-
string | $authHeader | The "Authorization" header sent by user. |
int | $userId | The user id as per the valid token. |
string | $tokenScope | The scope of the token presented. |
- Returns
- void
- Exceptions
-
HttpBadRequestException | If the header is malformed. |
HttpForbiddenException | If the user is inactive. |
Definition at line 101 of file AuthHelper.php.
◆ $dbHelper
DbHelper Fossology\UI\Api\Helper\AuthHelper::$dbHelper |
|
private |
◆ $session
Session Fossology\UI\Api\Helper\AuthHelper::$session |
|
private |
◆ $userDao
UserDao Fossology\UI\Api\Helper\AuthHelper::$userDao |
|
private |
The documentation for this class was generated from the following file: