FOSSology  4.4.0
Open Source License Compliance by Open Source Software
Auth.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
12 namespace Fossology\Lib\Auth;
13 
23 class Auth
24 {
27  const USER_NAME = 'User';
30  const USER_ID = 'UserId';
33  const GROUP_ID = 'GroupId';
36  const USER_LEVEL = 'UserLevel';
37 
40  const PERM_NONE = 0;
43  const PERM_READ = 1;
46  const PERM_WRITE= 3;
49  const PERM_CADMIN=5;
52  const PERM_ADMIN=10;
53 
56  const TOKEN_OAUTH = 0x1;
59  const TOKEN_TOKEN = 0x2;
62  const TOKEN_BOTH = 0x3;
63 
68  public static function getUserId()
69  {
70  if (array_key_exists('auth', $GLOBALS['SysConf'])) {
71  return $GLOBALS['SysConf']['auth'][self::USER_ID];
72  }
73  return 0;
74  }
75 
80  public static function getGroupId()
81  {
82  if (array_key_exists('auth', $GLOBALS['SysConf'])) {
83  return $GLOBALS['SysConf']['auth'][self::GROUP_ID];
84  }
85  return 0;
86  }
87 
92  public static function isAdmin()
93  {
94  return $_SESSION[self::USER_LEVEL]==self::PERM_ADMIN;
95  }
96 
101  public static function isClearingAdmin()
102  {
103  return $_SESSION[self::USER_LEVEL]>=self::PERM_CADMIN;
104  }
105 
110  public static function getRestTokenType()
111  {
112  global $SysConf;
113  $restToken = "token";
114  if (array_key_exists('AUTHENTICATION', $SysConf) &&
115  array_key_exists('resttoken', $SysConf['AUTHENTICATION'])) {
116  $restToken = $SysConf['AUTHENTICATION']['resttoken'];
117  }
118  switch ($restToken) {
119  case 'oauth':
120  return self::TOKEN_OAUTH;
121  break;
122  case 'both':
123  return self::TOKEN_BOTH;
124  break;
125  default:
126  return self::TOKEN_TOKEN;
127  }
128  }
129 }
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
static getUserId()
Get the current user's id.
Definition: Auth.php:68
static getGroupId()
Get the current user's group id.
Definition: Auth.php:80
static getRestTokenType()
Definition: Auth.php:110
static isAdmin()
Check if user is admin.
Definition: Auth.php:92
static isClearingAdmin()
Check if user is clearing admin.
Definition: Auth.php:101