FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Fossology\UI\Api\Helper\AuthHelper Class Reference

Provides helper methods for REST api. More...

Collaboration diagram for Fossology\UI\Api\Helper\AuthHelper:
Collaboration graph

Public Member Functions

 __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...
 

Static Public Member Functions

static loadJwks ()
 Load the JWK array. More...
 

Private Member Functions

 isDateExpired ($date)
 
 validateOauthLogin ($jwtToken, &$userId, &$tokenScope)
 Validate OAuth token. More...
 
 validateTokenLogin ($jwtToken, $jwtTokenPayloadDecoded, &$userId, &$tokenScope)
 Validate JWT token from FOSSology. More...
 

Private Attributes

 $session
 
 $userDao
 
 $dbHelper
 

Detailed Description

Provides helper methods for REST api.

Definition at line 37 of file AuthHelper.php.

Constructor & Destructor Documentation

◆ __construct()

Fossology\UI\Api\Helper\AuthHelper::__construct ( UserDao  $userDao,
Session  $session,
DbHelper  $dbhelper 
)

AuthHelper constructor.

Parameters
UserDao$userDaoUser dao to use
Session$sessionSession to use
DbHelper$dbhelperDb Helper to use

Definition at line 62 of file AuthHelper.php.

Member Function Documentation

◆ 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$userNameUsername
string$passwordPassword
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$expireWhen the token will expire ('YYYY-MM-DD')
string$createdWhen the token was created ('YYYY-MM-DD')
string$jtiToken id (pat_pk.user_pk)
string$scopeToken scope key
string$keyToken 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$dateDate 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$groupNameName of the group to update session with.
Returns
void
Exceptions
HttpForbiddenExceptionIf 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$valuesFromDbValues from DB.
int$tokenIdToken id (pat_pk)
Exceptions
HttpForbiddenExceptionIf 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
UnexpectedValueExceptionThrows 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$userIdUser id from the JWT.
string$scopeScope of the current token.
string$groupNameName 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$userIdUser id from the JWT.
string$groupNameName of the group to verify access to.
Returns
void
Exceptions
HttpForbiddenExceptionIf 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$jwtTokenToken from header
[out]integer$userIdUser ID from DB
[out]string$tokenScopeToken scope from DB
Returns
void
Exceptions
HttpForbiddenExceptionIf 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$jwtTokenToken from header
object$jwtTokenPayloadDecodedDecoded token
[out]integer$userIdUser ID from DB
[out]string$tokenScopeToken scope from DB
Returns
void
Exceptions
HttpForbiddenExceptionIf 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$authHeaderThe "Authorization" header sent by user.
int$userIdThe user id as per the valid token.
string$tokenScopeThe scope of the token presented.
Returns
void
Exceptions
HttpBadRequestExceptionIf the header is malformed.
HttpForbiddenExceptionIf the user is inactive.

Definition at line 101 of file AuthHelper.php.

Member Data Documentation

◆ $dbHelper

DbHelper Fossology\UI\Api\Helper\AuthHelper::$dbHelper
private

DB helper for DB interaction.

Definition at line 53 of file AuthHelper.php.

◆ $session

Session Fossology\UI\Api\Helper\AuthHelper::$session
private

Current Symfony session

Definition at line 43 of file AuthHelper.php.

◆ $userDao

UserDao Fossology\UI\Api\Helper\AuthHelper::$userDao
private

User DAO object

Definition at line 48 of file AuthHelper.php.


The documentation for this class was generated from the following file: