ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilWACToken Class Reference

Class ilWACToken. More...

+ Collaboration diagram for ilWACToken:

Public Member Functions

 __construct ($path, $client, $timestamp=0, $ttl=0)
 ilWACToken constructor. More...
 
 generateToken ()
 
 getSessionId ()
 
 setSessionId ($session_id)
 
 getTimestamp ()
 
 setTimestamp ($timestamp)
 
 getIp ()
 
 setIp ($ip)
 
 getToken ()
 
 setToken ($token)
 
 getPath ()
 
 setPath ($path)
 
 getId ()
 
 getHashedId ()
 
 setId ($id)
 
 getClient ()
 
 setClient ($client)
 
 getTTL ()
 
 setTTL ($ttl)
 
 getRawToken ()
 
 setRawToken ($raw_token)
 

Static Public Member Functions

static getSALT ()
 
static setSALT ($salt)
 

Data Fields

const SALT_FILE_PATH = './data/wacsalt.php'
 

Protected Member Functions

 initSalt ()
 
 generateSaltFile ()
 

Protected Attributes

 $session_id = ''
 
 $timestamp = 0
 
 $ip = ''
 
 $token = ''
 
 $raw_token = ''
 
 $path = ''
 
 $id = ''
 
 $client = ''
 
 $ttl = 0
 

Static Protected Attributes

static $SALT = ''
 

Detailed Description

Class ilWACToken.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 12 of file class.ilWACToken.php.

Constructor & Destructor Documentation

◆ __construct()

ilWACToken::__construct (   $path,
  $client,
  $timestamp = 0,
  $ttl = 0 
)

ilWACToken constructor.

Parameters
string$path
string$client
int$timestamp
int$ttl

Definition at line 65 of file class.ilWACToken.php.

References $_SERVER, $client, $path, $session_id, $timestamp, $ttl, generateToken(), getPath(), ilWACSignedPath\getTokenMaxLifetimeInSeconds(), setClient(), setId(), setIp(), setPath(), setSessionId(), setTimestamp(), setTTL(), and time.

66  {
67  assert(is_string($path));
68  assert(is_string($client));
69  assert(is_int($timestamp));
70  assert(is_int($ttl));
71  $this->setClient($client);
72  $this->setPath($path);
73  $session_id = session_id();
74  $this->setSessionId($session_id ? $session_id : '-');
75  if (isset($_SERVER['REMOTE_ADDR'])) {
76  $this->setIp($_SERVER['REMOTE_ADDR']);
77  }
78  $this->setTimestamp($timestamp ? $timestamp : time());
80  $this->setTTL($ttl); // since we do not know the type at this poit we choose the shorter duration for security reasons
81  $this->generateToken();
82  $this->setId($this->getPath());
83  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
setTimestamp($timestamp)
setSessionId($session_id)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getTokenMaxLifetimeInSeconds()
setClient($client)
+ Here is the call graph for this function:

Member Function Documentation

◆ generateSaltFile()

ilWACToken::generateSaltFile ( )
protected
Returns
void
Exceptions
ilWACException

Definition at line 129 of file class.ilWACToken.php.

References $template, ilWACException\DATA_DIR_NON_WRITEABLE, and time.

Referenced by initSalt().

130  {
131  if (is_file(self::SALT_FILE_PATH)) {
132  unlink(self::SALT_FILE_PATH);
133  }
134  $template = file_get_contents('./Services/WebAccessChecker/wacsalt.php.template');
135  $random = new \ilRandom();
136  $salt = md5(time() * $random->int(1000, 9999) . self::SALT_FILE_PATH);
137  self::setSALT($salt);
138  $template = str_replace('INSERT_SALT', $salt, $template);
139  if (is_writable(dirname(self::SALT_FILE_PATH))) {
140  file_put_contents(self::SALT_FILE_PATH, $template);
141  } else {
142  throw new ilWACException(ilWACException::DATA_DIR_NON_WRITEABLE, self::SALT_FILE_PATH);
143  }
144  }
Class ilWACException.
$template
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the caller graph for this function:

◆ generateToken()

ilWACToken::generateToken ( )
Returns
void

Definition at line 89 of file class.ilWACToken.php.

References $token, array, getClient(), getTimestamp(), getTTL(), initSalt(), setRawToken(), and setToken().

Referenced by __construct(), and ilWACTokenTest\testTokenGeneration().

90  {
91  $this->initSalt();
92  $token = implode('-', array(
93  self::getSALT(),
94  $this->getClient(),
95  $this->getTimestamp(),
96  $this->getTTL(),
97  ));
98  $this->setRawToken($token);
99  $token = sha1($token);
100  $this->setToken($token);
101  }
setRawToken($raw_token)
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClient()

ilWACToken::getClient ( )
Returns
string

Definition at line 298 of file class.ilWACToken.php.

References $client.

Referenced by generateToken().

299  {
300  return (string) $this->client;
301  }
+ Here is the caller graph for this function:

◆ getHashedId()

ilWACToken::getHashedId ( )
Returns
string

Definition at line 259 of file class.ilWACToken.php.

260  {
261  return (string) md5($this->id);
262  }

◆ getId()

ilWACToken::getId ( )
Returns
string

Definition at line 250 of file class.ilWACToken.php.

References $id.

251  {
252  return (string) $this->id;
253  }

◆ getIp()

ilWACToken::getIp ( )
Returns
string

Definition at line 190 of file class.ilWACToken.php.

References $ip.

191  {
192  return (string) $this->ip;
193  }

◆ getPath()

ilWACToken::getPath ( )
Returns
string

Definition at line 230 of file class.ilWACToken.php.

References $path.

Referenced by __construct().

231  {
232  return (string) $this->path;
233  }
+ Here is the caller graph for this function:

◆ getRawToken()

ilWACToken::getRawToken ( )
Returns
string

Definition at line 338 of file class.ilWACToken.php.

References $raw_token.

339  {
340  return (string) $this->raw_token;
341  }

◆ getSALT()

static ilWACToken::getSALT ( )
static
Returns
string

Definition at line 278 of file class.ilWACToken.php.

Referenced by ilWACTokenTest\testTokenGeneration().

279  {
280  return (string) self::$SALT;
281  }
+ Here is the caller graph for this function:

◆ getSessionId()

ilWACToken::getSessionId ( )
Returns
string

Definition at line 150 of file class.ilWACToken.php.

References $session_id.

151  {
152  return (string) $this->session_id;
153  }

◆ getTimestamp()

ilWACToken::getTimestamp ( )
Returns
int

Definition at line 170 of file class.ilWACToken.php.

References $timestamp.

Referenced by generateToken().

171  {
172  return (int) $this->timestamp;
173  }
+ Here is the caller graph for this function:

◆ getToken()

ilWACToken::getToken ( )
Returns
string

Definition at line 210 of file class.ilWACToken.php.

References $token.

211  {
212  return (string) $this->token;
213  }

◆ getTTL()

ilWACToken::getTTL ( )
Returns
int

Definition at line 318 of file class.ilWACToken.php.

References $ttl.

Referenced by generateToken().

319  {
320  return (int) $this->ttl;
321  }
+ Here is the caller graph for this function:

◆ initSalt()

ilWACToken::initSalt ( )
protected
Returns
void

Definition at line 107 of file class.ilWACToken.php.

References generateSaltFile().

Referenced by generateToken().

108  {
109  if (self::getSALT()) {
110  return;
111  }
112  $salt = '';
113  if (is_file(self::SALT_FILE_PATH)) {
114  require self::SALT_FILE_PATH;
115  self::setSALT($salt);
116  }
117 
118  if (strcmp($salt, '') === 0) {
119  $this->generateSaltFile();
120  $this->initSalt();
121  }
122  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setClient()

ilWACToken::setClient (   $client)
Parameters
string$client
Returns
void

Definition at line 308 of file class.ilWACToken.php.

References $client.

Referenced by __construct().

309  {
310  assert(is_string($client));
311  $this->client = $client;
312  }
+ Here is the caller graph for this function:

◆ setId()

ilWACToken::setId (   $id)
Parameters
string$id

Definition at line 268 of file class.ilWACToken.php.

References $id.

Referenced by __construct().

269  {
270  assert(is_string($id));
271  $this->id = $id;
272  }
+ Here is the caller graph for this function:

◆ setIp()

ilWACToken::setIp (   $ip)
Parameters
string$ip
Returns
void

Definition at line 200 of file class.ilWACToken.php.

References $ip.

Referenced by __construct().

201  {
202  assert(is_string($ip));
203  $this->ip = $ip;
204  }
+ Here is the caller graph for this function:

◆ setPath()

ilWACToken::setPath (   $path)
Parameters
string$path
Returns
void

Definition at line 240 of file class.ilWACToken.php.

References $path.

Referenced by __construct().

241  {
242  assert(is_string($path));
243  $this->path = $path;
244  }
+ Here is the caller graph for this function:

◆ setRawToken()

ilWACToken::setRawToken (   $raw_token)
Parameters
string$raw_token
Returns
void

Definition at line 348 of file class.ilWACToken.php.

References $raw_token.

Referenced by generateToken().

349  {
350  assert(is_string($raw_token));
351  $this->raw_token = $raw_token;
352  }
+ Here is the caller graph for this function:

◆ setSALT()

static ilWACToken::setSALT (   $salt)
static
Parameters
string$salt
Returns
void

Definition at line 288 of file class.ilWACToken.php.

Referenced by ilWACCheckingInstanceTest\setUp(), and ilWACTokenTest\setUp().

289  {
290  assert(is_string($salt));
291  self::$SALT = $salt;
292  }
+ Here is the caller graph for this function:

◆ setSessionId()

ilWACToken::setSessionId (   $session_id)
Parameters
string$session_id
Returns
void

Definition at line 160 of file class.ilWACToken.php.

References $session_id.

Referenced by __construct().

161  {
162  assert(is_string($session_id));
163  $this->session_id = $session_id;
164  }
+ Here is the caller graph for this function:

◆ setTimestamp()

ilWACToken::setTimestamp (   $timestamp)
Parameters
int$timestamp
Returns
void

Definition at line 180 of file class.ilWACToken.php.

References $timestamp.

Referenced by __construct().

181  {
182  assert(is_int($timestamp));
183  $this->timestamp = $timestamp;
184  }
+ Here is the caller graph for this function:

◆ setToken()

ilWACToken::setToken (   $token)
Parameters
string$token
Returns
void

Definition at line 220 of file class.ilWACToken.php.

References $token.

Referenced by generateToken().

221  {
222  assert(is_string($token));
223  $this->token = $token;
224  }
+ Here is the caller graph for this function:

◆ setTTL()

ilWACToken::setTTL (   $ttl)
Parameters
int$ttl
Returns
void

Definition at line 328 of file class.ilWACToken.php.

References $ttl.

Referenced by __construct().

329  {
330  assert(is_int($ttl));
331  $this->ttl = $ttl;
332  }
+ Here is the caller graph for this function:

Field Documentation

◆ $client

ilWACToken::$client = ''
protected

Definition at line 50 of file class.ilWACToken.php.

Referenced by __construct(), getClient(), and setClient().

◆ $id

ilWACToken::$id = ''
protected

Definition at line 46 of file class.ilWACToken.php.

Referenced by getId(), and setId().

◆ $ip

ilWACToken::$ip = ''
protected

Definition at line 30 of file class.ilWACToken.php.

Referenced by getIp(), and setIp().

◆ $path

ilWACToken::$path = ''
protected

Definition at line 42 of file class.ilWACToken.php.

Referenced by __construct(), getPath(), and setPath().

◆ $raw_token

ilWACToken::$raw_token = ''
protected

Definition at line 38 of file class.ilWACToken.php.

Referenced by getRawToken(), and setRawToken().

◆ $SALT

ilWACToken::$SALT = ''
staticprotected

Definition at line 18 of file class.ilWACToken.php.

◆ $session_id

ilWACToken::$session_id = ''
protected

Definition at line 22 of file class.ilWACToken.php.

Referenced by __construct(), getSessionId(), and setSessionId().

◆ $timestamp

ilWACToken::$timestamp = 0
protected

Definition at line 26 of file class.ilWACToken.php.

Referenced by __construct(), getTimestamp(), and setTimestamp().

◆ $token

ilWACToken::$token = ''
protected

Definition at line 34 of file class.ilWACToken.php.

Referenced by generateToken(), getToken(), and setToken().

◆ $ttl

ilWACToken::$ttl = 0
protected

Definition at line 54 of file class.ilWACToken.php.

Referenced by __construct(), getTTL(), and setTTL().

◆ SALT_FILE_PATH

const ilWACToken::SALT_FILE_PATH = './data/wacsalt.php'

Definition at line 14 of file class.ilWACToken.php.


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