Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
e-epal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Χάρης Παπαδόπουλος
e-epal
Commits
47e82951
Commit
47e82951
authored
Apr 11, 2017
by
Χάρης Παπαδόπουλος
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CAS login. Beta version finished
parent
4d0c5bb4
Changes
93
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
93 changed files
with
233 additions
and
15004 deletions
+233
-15004
.gitignore
.gitignore
+0
-1
drupal/modules/casost/casost.routing.yml
drupal/modules/casost/casost.routing.yml
+0
-6
drupal/modules/casost/src/CAS/CAS/AuthenticationException.php
...al/modules/casost/src/CAS/CAS/AuthenticationException.php
+0
-108
drupal/modules/casost/src/CAS/CAS/Autoload.php
drupal/modules/casost/src/CAS/CAS/Autoload.php
+0
-105
drupal/modules/casost/src/CAS/CAS/Client.php
drupal/modules/casost/src/CAS/CAS/Client.php
+0
-3910
drupal/modules/casost/src/CAS/CAS/CookieJar.php
drupal/modules/casost/src/CAS/CAS/CookieJar.php
+0
-385
drupal/modules/casost/src/CAS/CAS/Exception.php
drupal/modules/casost/src/CAS/CAS/Exception.php
+0
-59
drupal/modules/casost/src/CAS/CAS/GracefullTerminationException.php
...ules/casost/src/CAS/CAS/GracefullTerminationException.php
+0
-86
drupal/modules/casost/src/CAS/CAS/InvalidArgumentException.php
...l/modules/casost/src/CAS/CAS/InvalidArgumentException.php
+0
-46
drupal/modules/casost/src/CAS/CAS/Languages/Catalan.php
drupal/modules/casost/src/CAS/CAS/Languages/Catalan.php
+0
-114
drupal/modules/casost/src/CAS/CAS/Languages/English.php
drupal/modules/casost/src/CAS/CAS/Languages/English.php
+0
-114
drupal/modules/casost/src/CAS/CAS/Languages/French.php
drupal/modules/casost/src/CAS/CAS/Languages/French.php
+0
-116
drupal/modules/casost/src/CAS/CAS/Languages/German.php
drupal/modules/casost/src/CAS/CAS/Languages/German.php
+0
-116
drupal/modules/casost/src/CAS/CAS/Languages/Greek.php
drupal/modules/casost/src/CAS/CAS/Languages/Greek.php
+0
-115
drupal/modules/casost/src/CAS/CAS/Languages/Japanese.php
drupal/modules/casost/src/CAS/CAS/Languages/Japanese.php
+0
-113
drupal/modules/casost/src/CAS/CAS/Languages/LanguageInterface.php
...odules/casost/src/CAS/CAS/Languages/LanguageInterface.php
+0
-96
drupal/modules/casost/src/CAS/CAS/Languages/Spanish.php
drupal/modules/casost/src/CAS/CAS/Languages/Spanish.php
+0
-117
drupal/modules/casost/src/CAS/CAS/OutOfSequenceBeforeAuthenticationCallException.php
...AS/CAS/OutOfSequenceBeforeAuthenticationCallException.php
+0
-56
drupal/modules/casost/src/CAS/CAS/OutOfSequenceBeforeClientException.php
...casost/src/CAS/CAS/OutOfSequenceBeforeClientException.php
+0
-58
drupal/modules/casost/src/CAS/CAS/OutOfSequenceBeforeProxyException.php
.../casost/src/CAS/CAS/OutOfSequenceBeforeProxyException.php
+0
-59
drupal/modules/casost/src/CAS/CAS/OutOfSequenceException.php
drupal/modules/casost/src/CAS/CAS/OutOfSequenceException.php
+0
-49
drupal/modules/casost/src/CAS/CAS/PGTStorage/AbstractStorage.php
...modules/casost/src/CAS/CAS/PGTStorage/AbstractStorage.php
+0
-222
drupal/modules/casost/src/CAS/CAS/PGTStorage/Db.php
drupal/modules/casost/src/CAS/CAS/PGTStorage/Db.php
+0
-440
drupal/modules/casost/src/CAS/CAS/PGTStorage/File.php
drupal/modules/casost/src/CAS/CAS/PGTStorage/File.php
+0
-259
drupal/modules/casost/src/CAS/CAS/ProxiedService.php
drupal/modules/casost/src/CAS/CAS/ProxiedService.php
+0
-72
drupal/modules/casost/src/CAS/CAS/ProxiedService/Abstract.php
...al/modules/casost/src/CAS/CAS/ProxiedService/Abstract.php
+0
-149
drupal/modules/casost/src/CAS/CAS/ProxiedService/Exception.php
...l/modules/casost/src/CAS/CAS/ProxiedService/Exception.php
+0
-46
drupal/modules/casost/src/CAS/CAS/ProxiedService/Http.php
drupal/modules/casost/src/CAS/CAS/ProxiedService/Http.php
+0
-91
drupal/modules/casost/src/CAS/CAS/ProxiedService/Http/Abstract.php
...dules/casost/src/CAS/CAS/ProxiedService/Http/Abstract.php
+0
-360
drupal/modules/casost/src/CAS/CAS/ProxiedService/Http/Get.php
...al/modules/casost/src/CAS/CAS/ProxiedService/Http/Get.php
+0
-85
drupal/modules/casost/src/CAS/CAS/ProxiedService/Http/Post.php
...l/modules/casost/src/CAS/CAS/ProxiedService/Http/Post.php
+0
-152
drupal/modules/casost/src/CAS/CAS/ProxiedService/Imap.php
drupal/modules/casost/src/CAS/CAS/ProxiedService/Imap.php
+0
-280
drupal/modules/casost/src/CAS/CAS/ProxiedService/Testable.php
...al/modules/casost/src/CAS/CAS/ProxiedService/Testable.php
+0
-75
drupal/modules/casost/src/CAS/CAS/ProxyChain.php
drupal/modules/casost/src/CAS/CAS/ProxyChain.php
+0
-127
drupal/modules/casost/src/CAS/CAS/ProxyChain/AllowedList.php
drupal/modules/casost/src/CAS/CAS/ProxyChain/AllowedList.php
+0
-119
drupal/modules/casost/src/CAS/CAS/ProxyChain/Any.php
drupal/modules/casost/src/CAS/CAS/ProxyChain/Any.php
+0
-64
drupal/modules/casost/src/CAS/CAS/ProxyChain/Interface.php
drupal/modules/casost/src/CAS/CAS/ProxyChain/Interface.php
+0
-53
drupal/modules/casost/src/CAS/CAS/ProxyChain/Trusted.php
drupal/modules/casost/src/CAS/CAS/ProxyChain/Trusted.php
+0
-59
drupal/modules/casost/src/CAS/CAS/ProxyTicketException.php
drupal/modules/casost/src/CAS/CAS/ProxyTicketException.php
+0
-71
drupal/modules/casost/src/CAS/CAS/Request/AbstractRequest.php
...al/modules/casost/src/CAS/CAS/Request/AbstractRequest.php
+0
-379
drupal/modules/casost/src/CAS/CAS/Request/CurlMultiRequest.php
...l/modules/casost/src/CAS/CAS/Request/CurlMultiRequest.php
+0
-146
drupal/modules/casost/src/CAS/CAS/Request/CurlRequest.php
drupal/modules/casost/src/CAS/CAS/Request/CurlRequest.php
+0
-200
drupal/modules/casost/src/CAS/CAS/Request/Exception.php
drupal/modules/casost/src/CAS/CAS/Request/Exception.php
+0
-45
drupal/modules/casost/src/CAS/CAS/Request/MultiRequestInterface.php
...ules/casost/src/CAS/CAS/Request/MultiRequestInterface.php
+0
-83
drupal/modules/casost/src/CAS/CAS/Request/RequestInterface.php
...l/modules/casost/src/CAS/CAS/Request/RequestInterface.php
+0
-179
drupal/modules/casost/src/CAS/CAS/TypeMismatchException.php
drupal/modules/casost/src/CAS/CAS/TypeMismatchException.php
+0
-70
drupal/modules/casost/src/CAS/LICENSE
drupal/modules/casost/src/CAS/LICENSE
+0
-201
drupal/modules/casost/src/CAS/NOTICE
drupal/modules/casost/src/CAS/NOTICE
+0
-81
drupal/modules/casost/src/CAS/README.md
drupal/modules/casost/src/CAS/README.md
+0
-31
drupal/modules/casost/src/CAS/docs/Building
drupal/modules/casost/src/CAS/docs/Building
+0
-34
drupal/modules/casost/src/CAS/docs/ChangeLog
drupal/modules/casost/src/CAS/docs/ChangeLog
+0
-565
drupal/modules/casost/src/CAS/docs/Upgrading
drupal/modules/casost/src/CAS/docs/Upgrading
+0
-100
drupal/modules/casost/src/CAS/docs/examples/config.example.php
...l/modules/casost/src/CAS/docs/examples/config.example.php
+0
-104
drupal/modules/casost/src/CAS/docs/examples/create_pgt_storage_db_table.php
...ost/src/CAS/docs/examples/create_pgt_storage_db_table.php
+0
-53
drupal/modules/casost/src/CAS/docs/examples/example.css
drupal/modules/casost/src/CAS/docs/examples/example.css
+0
-10
drupal/modules/casost/src/CAS/docs/examples/example_advanced_saml11.php
.../casost/src/CAS/docs/examples/example_advanced_saml11.php
+0
-82
drupal/modules/casost/src/CAS/docs/examples/example_custom_urls.php
...ules/casost/src/CAS/docs/examples/example_custom_urls.php
+0
-70
drupal/modules/casost/src/CAS/docs/examples/example_gateway.php
.../modules/casost/src/CAS/docs/examples/example_gateway.php
+0
-71
drupal/modules/casost/src/CAS/docs/examples/example_hardening.php
...odules/casost/src/CAS/docs/examples/example_hardening.php
+0
-85
drupal/modules/casost/src/CAS/docs/examples/example_html.php
drupal/modules/casost/src/CAS/docs/examples/example_html.php
+0
-76
drupal/modules/casost/src/CAS/docs/examples/example_lang.php
drupal/modules/casost/src/CAS/docs/examples/example_lang.php
+0
-63
drupal/modules/casost/src/CAS/docs/examples/example_logout.php
...l/modules/casost/src/CAS/docs/examples/example_logout.php
+0
-64
drupal/modules/casost/src/CAS/docs/examples/example_no_ssl_cn_validation.php
...st/src/CAS/docs/examples/example_no_ssl_cn_validation.php
+0
-68
drupal/modules/casost/src/CAS/docs/examples/example_pgt_storage_db.php
...s/casost/src/CAS/docs/examples/example_pgt_storage_db.php
+0
-74
drupal/modules/casost/src/CAS/docs/examples/example_pgt_storage_file.php
...casost/src/CAS/docs/examples/example_pgt_storage_file.php
+0
-74
drupal/modules/casost/src/CAS/docs/examples/example_proxy_GET.php
...odules/casost/src/CAS/docs/examples/example_proxy_GET.php
+0
-98
drupal/modules/casost/src/CAS/docs/examples/example_proxy_POST.php
...dules/casost/src/CAS/docs/examples/example_proxy_POST.php
+0
-103
drupal/modules/casost/src/CAS/docs/examples/example_proxy_rebroadcast.php
...asost/src/CAS/docs/examples/example_proxy_rebroadcast.php
+0
-63
drupal/modules/casost/src/CAS/docs/examples/example_proxy_serviceWeb.php
...casost/src/CAS/docs/examples/example_proxy_serviceWeb.php
+0
-71
drupal/modules/casost/src/CAS/docs/examples/example_proxy_serviceWeb_chaining.php
...c/CAS/docs/examples/example_proxy_serviceWeb_chaining.php
+0
-71
drupal/modules/casost/src/CAS/docs/examples/example_renew.php
...al/modules/casost/src/CAS/docs/examples/example_renew.php
+0
-72
drupal/modules/casost/src/CAS/docs/examples/example_service.php
.../modules/casost/src/CAS/docs/examples/example_service.php
+0
-96
drupal/modules/casost/src/CAS/docs/examples/example_service_POST.php
...les/casost/src/CAS/docs/examples/example_service_POST.php
+0
-105
drupal/modules/casost/src/CAS/docs/examples/example_service_that_proxies.php
...st/src/CAS/docs/examples/example_service_that_proxies.php
+0
-106
drupal/modules/casost/src/CAS/docs/examples/example_simple.php
...l/modules/casost/src/CAS/docs/examples/example_simple.php
+0
-63
drupal/modules/casost/src/CAS/docs/examples/script_info.php
drupal/modules/casost/src/CAS/docs/examples/script_info.php
+0
-20
drupal/modules/casost/src/CAS/docs/images/esup-portail.png
drupal/modules/casost/src/CAS/docs/images/esup-portail.png
+0
-0
drupal/modules/casost/src/CAS/docs/images/jasig.png
drupal/modules/casost/src/CAS/docs/images/jasig.png
+0
-0
drupal/modules/casost/src/CAS/docs/images/phpcas.png
drupal/modules/casost/src/CAS/docs/images/phpcas.png
+0
-0
drupal/modules/casost/src/CAS/docs/index.html
drupal/modules/casost/src/CAS/docs/index.html
+0
-19
drupal/modules/casost/src/CAS/package.xml
drupal/modules/casost/src/CAS/package.xml
+0
-182
drupal/modules/casost/src/CAS/phpCAS.php
drupal/modules/casost/src/CAS/phpCAS.php
+0
-1958
drupal/modules/casost/src/Controller/CASLogin.php
drupal/modules/casost/src/Controller/CASLogin.php
+43
-136
drupal/modules/casost/src/Controller/CASLogout.php
drupal/modules/casost/src/Controller/CASLogout.php
+87
-13
drupal/modules/casost/src/Controller/CBController.php
drupal/modules/casost/src/Controller/CBController.php
+0
-230
drupal/modules/epal/src/Controller/CurrentUser.php
drupal/modules/epal/src/Controller/CurrentUser.php
+21
-0
drupal/modules/oauthost/src/Controller/OAuthLogin.php
drupal/modules/oauthost/src/Controller/OAuthLogin.php
+2
-0
drupal/modules/oauthost/src/Controller/OAuthLogout.php
drupal/modules/oauthost/src/Controller/OAuthLogout.php
+5
-1
source/components/home.ts
source/components/home.ts
+1
-1
source/components/navbar/navbar.component.html
source/components/navbar/navbar.component.html
+7
-12
source/components/navbar/navbar.component.ts
source/components/navbar/navbar.component.ts
+26
-8
source/components/school.home.ts
source/components/school.home.ts
+1
-1
source/services/helper-data-service.ts
source/services/helper-data-service.ts
+40
-14
No files found.
.gitignore
View file @
47e82951
...
...
@@ -9,7 +9,6 @@ drupal/modules/*
!drupal/modules/epalreadydata/
!drupal/modules/oauthost/
!drupal/modules/casost/
drupal/modules/casost/src/CAS/*
!drupal/modules/epaldeploysystem/
# Logs
...
...
drupal/modules/casost/casost.routing.yml
View file @
47e82951
...
...
@@ -4,12 +4,6 @@ casost.log_in_go:
_controller
:
'
\Drupal\casost\Controller\CASLogin::loginGo'
requirements
:
_access
:
'
TRUE'
casost.callback_log_in
:
path
:
/cas/cb
defaults
:
_controller
:
'
\Drupal\casost\Controller\CBController::loginCB'
requirements
:
_permission
:
'
access
content'
casost.log_out_go
:
path
:
/cas/logout
options
:
...
...
drupal/modules/casost/src/CAS/CAS/AuthenticationException.php
deleted
100644 → 0
View file @
4d0c5bb4
<?php
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP Version 5
*
* @file CAS/AuthenticationException.php
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
/**
* This interface defines methods that allow proxy-authenticated service handlers
* to interact with phpCAS.
*
* Proxy service handlers must implement this interface as well as call
* phpCAS::initializeProxiedService($this) at some point in their implementation.
*
* While not required, proxy-authenticated service handlers are encouraged to
* implement the CAS_ProxiedService_Testable interface to facilitate unit testing.
*
* @class CAS_AuthenticationException
* @category Authentication
* @package PhpCAS
* @author Joachim Fritschi <jfritschi@freenet.de>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class
CAS_AuthenticationException
extends
RuntimeException
implements
CAS_Exception
{
/**
* This method is used to print the HTML output when the user was not
* authenticated.
*
* @param CAS_Client $client phpcas client
* @param string $failure the failure that occured
* @param string $cas_url the URL the CAS server was asked for
* @param bool $no_response the response from the CAS server (other
* parameters are ignored if TRUE)
* @param bool $bad_response bad response from the CAS server ($err_code
* and $err_msg ignored if TRUE)
* @param string $cas_response the response of the CAS server
* @param int $err_code the error code given by the CAS server
* @param string $err_msg the error message given by the CAS server
*/
public
function
__construct
(
$client
,
$failure
,
$cas_url
,
$no_response
,
$bad_response
=
''
,
$cas_response
=
''
,
$err_code
=
''
,
$err_msg
=
''
)
{
phpCAS
::
traceBegin
();
$lang
=
$client
->
getLangObj
();
$client
->
printHTMLHeader
(
$lang
->
getAuthenticationFailed
());
printf
(
$lang
->
getYouWereNotAuthenticated
(),
htmlentities
(
$client
->
getURL
()),
isset
(
$_SERVER
[
'SERVER_ADMIN'
])
?
$_SERVER
[
'SERVER_ADMIN'
]
:
''
);
phpCAS
::
trace
(
'CAS URL: '
.
$cas_url
);
phpCAS
::
trace
(
'Authentication failure: '
.
$failure
);
if
(
$no_response
)
{
phpCAS
::
trace
(
'Reason: no response from the CAS server'
);
}
else
{
if
(
$bad_response
)
{
phpCAS
::
trace
(
'Reason: bad response from the CAS server'
);
}
else
{
switch
(
$client
->
getServerVersion
())
{
case
CAS_VERSION_1_0
:
phpCAS
::
trace
(
'Reason: CAS error'
);
break
;
case
CAS_VERSION_2_0
:
case
CAS_VERSION_3_0
:
if
(
empty
(
$err_code
)
)
{
phpCAS
::
trace
(
'Reason: no CAS error'
);
}
else
{
phpCAS
::
trace
(
'Reason: ['
.
$err_code
.
'] CAS error: '
.
$err_msg
);
}
break
;
}
}
phpCAS
::
trace
(
'CAS response: '
.
$cas_response
);
}
$client
->
printHTMLFooter
();
phpCAS
::
traceExit
();
}
}
?>
drupal/modules/casost/src/CAS/CAS/Autoload.php
deleted
100644 → 0
View file @
4d0c5bb4
<?php
/**
* Autoloader Class
*
* PHP Version 5
*
* @file CAS/Autoload.php
* @category Authentication
* @package SimpleCAS
* @author Brett Bieber <brett.bieber@gmail.com>
* @copyright 2008 Regents of the University of Nebraska
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
* @link http://code.google.com/p/simplecas/
**/
/**
* Autoload a class
*
* @param string $class Classname to load
*
* @return bool
*/
function
CAS_autoload
(
$class
)
{
// Static to hold the Include Path to CAS
static
$include_path
;
// Check only for CAS classes
if
(
substr
(
$class
,
0
,
4
)
!==
'CAS_'
)
{
return
false
;
}
// Setup the include path if it's not already set from a previous call
if
(
empty
(
$include_path
))
{
$include_path
=
array
(
dirname
(
dirname
(
__FILE__
)),
dirname
(
dirname
(
__FILE__
))
.
'/../test/'
);
}
// Declare local variable to store the expected full path to the file
foreach
(
$include_path
as
$path
)
{
$file_path
=
$path
.
'/'
.
str_replace
(
'_'
,
'/'
,
$class
)
.
'.php'
;
$fp
=
@
fopen
(
$file_path
,
'r'
,
true
);
if
(
$fp
)
{
fclose
(
$fp
);
include
$file_path
;
if
(
!
class_exists
(
$class
,
false
)
&&
!
interface_exists
(
$class
,
false
))
{
die
(
new
Exception
(
'Class '
.
$class
.
' was not present in '
.
$file_path
.
' [CAS_autoload]'
)
);
}
return
true
;
}
}
$e
=
new
Exception
(
'Class '
.
$class
.
' could not be loaded from '
.
$file_path
.
', file does not exist (Path="'
.
implode
(
':'
,
$include_path
)
.
'") [CAS_autoload]'
);
$trace
=
$e
->
getTrace
();
if
(
isset
(
$trace
[
2
])
&&
isset
(
$trace
[
2
][
'function'
])
&&
in_array
(
$trace
[
2
][
'function'
],
array
(
'class_exists'
,
'interface_exists'
))
)
{
return
false
;
}
if
(
isset
(
$trace
[
1
])
&&
isset
(
$trace
[
1
][
'function'
])
&&
in_array
(
$trace
[
1
][
'function'
],
array
(
'class_exists'
,
'interface_exists'
))
)
{
return
false
;
}
die
((
string
)
$e
);
}
// set up __autoload
if
(
function_exists
(
'spl_autoload_register'
))
{
if
(
!
(
spl_autoload_functions
())
||
!
in_array
(
'CAS_autoload'
,
spl_autoload_functions
())
)
{
spl_autoload_register
(
'CAS_autoload'
);
if
(
function_exists
(
'__autoload'
)
&&
!
in_array
(
'__autoload'
,
spl_autoload_functions
())
)
{
// __autoload() was being used, but now would be ignored, add
// it to the autoload stack
spl_autoload_register
(
'__autoload'
);
}
}
}
elseif
(
!
function_exists
(
'__autoload'
))
{
/**
* Autoload a class
*
* @param string $class Class name
*
* @return bool
*/
function
__autoload
(
$class
)
{
return
CAS_autoload
(
$class
);
}
}
?>
\ No newline at end of file
drupal/modules/casost/src/CAS/CAS/Client.php
deleted
100644 → 0
View file @
4d0c5bb4
This diff is collapsed.
Click to expand it.
drupal/modules/casost/src/CAS/CAS/CookieJar.php
deleted
100644 → 0
View file @
4d0c5bb4
<?php
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP Version 5
*
* @file CAS/CookieJar.php
* @category Authentication
* @package PhpCAS
* @author Adam Franco <afranco@middlebury.edu>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
/**
* This class provides access to service cookies and handles parsing of response
* headers to pull out cookie values.
*
* @class CAS_CookieJar
* @category Authentication
* @package PhpCAS
* @author Adam Franco <afranco@middlebury.edu>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://wiki.jasig.org/display/CASC/phpCAS
*/
class
CAS_CookieJar
{
private
$_cookies
;
/**
* Create a new cookie jar by passing it a reference to an array in which it
* should store cookies.
*
* @param array &$storageArray Array to store cookies
*
* @return void
*/
public
function
__construct
(
array
&
$storageArray
)
{
$this
->
_cookies
=&
$storageArray
;
}
/**
* Store cookies for a web service request.
* Cookie storage is based on RFC 2965: http://www.ietf.org/rfc/rfc2965.txt
*
* @param string $request_url The URL that generated the response headers.
* @param array $response_headers An array of the HTTP response header strings.
*
* @return void
*
* @access private
*/
public
function
storeCookies
(
$request_url
,
$response_headers
)
{
$urlParts
=
parse_url
(
$request_url
);
$defaultDomain
=
$urlParts
[
'host'
];
$cookies
=
$this
->
parseCookieHeaders
(
$response_headers
,
$defaultDomain
);
// var_dump($cookies);
foreach
(
$cookies
as
$cookie
)
{
// Enforce the same-origin policy by verifying that the cookie
// would match the url that is setting it
if
(
!
$this
->
cookieMatchesTarget
(
$cookie
,
$urlParts
))
{
continue
;
}
// store the cookie
$this
->
storeCookie
(
$cookie
);
phpCAS
::
trace
(
$cookie
[
'name'
]
.
' -> '
.
$cookie
[
'value'
]);
}
}
/**
* Retrieve cookies applicable for a web service request.
* Cookie applicability is based on RFC 2965: http://www.ietf.org/rfc/rfc2965.txt
*
* @param string $request_url The url that the cookies will be for.
*
* @return array An array containing cookies. E.g. array('name' => 'val');
*
* @access private
*/
public
function
getCookies
(
$request_url
)
{
if
(
!
count
(
$this
->
_cookies
))
{
return
array
();
}
// If our request URL can't be parsed, no cookies apply.
$target
=
parse_url
(
$request_url
);
if
(
$target
===
false
)
{
return
array
();
}
$this
->
expireCookies
();
$matching_cookies
=
array
();
foreach
(
$this
->
_cookies
as
$key
=>
$cookie
)
{
if
(
$this
->
cookieMatchesTarget
(
$cookie
,
$target
))
{
$matching_cookies
[
$cookie
[
'name'
]]
=
$cookie
[
'value'
];
}
}
return
$matching_cookies
;
}
/**
* Parse Cookies without PECL
* From the comments in http://php.net/manual/en/function.http-parse-cookie.php
*
* @param array $header array of header lines.
* @param string $defaultDomain The domain to use if none is specified in
* the cookie.
*
* @return array of cookies
*/
protected
function
parseCookieHeaders
(
$header
,
$defaultDomain
)
{
phpCAS
::
traceBegin
();
$cookies
=
array
();
foreach
(
$header
as
$line
)
{
if
(
preg_match
(
'/^Set-Cookie2?: /i'
,
$line
))
{
$cookies
[]
=
$this
->
parseCookieHeader
(
$line
,
$defaultDomain
);
}
}
phpCAS
::
traceEnd
(
$cookies
);
return
$cookies
;
}
/**
* Parse a single cookie header line.
*
* Based on RFC2965 http://www.ietf.org/rfc/rfc2965.txt
*
* @param string $line The header line.
* @param string $defaultDomain The domain to use if none is specified in
* the cookie.
*
* @return array
*/
protected
function
parseCookieHeader
(
$line
,
$defaultDomain
)
{
if
(
!
$defaultDomain
)
{
throw
new
CAS_InvalidArgumentException
(
'$defaultDomain was not provided.'
);
}
// Set our default values
$cookie
=
array
(
'domain'
=>
$defaultDomain
,
'path'
=>
'/'
,
'secure'
=>
false
,
);
$line
=
preg_replace
(
'/^Set-Cookie2?: /i'
,
''
,
trim
(
$line
));
// trim any trailing semicolons.
$line
=
trim
(
$line
,
';'
);
phpCAS
::
trace
(
"Cookie Line:
$line
"
);
// This implementation makes the assumption that semicolons will not
// be present in quoted attribute values. While attribute values that
// contain semicolons are allowed by RFC2965, they are hopefully rare
// enough to ignore for our purposes. Most browsers make the same
// assumption.
$attributeStrings
=
explode
(
';'
,
$line
);
foreach
(
$attributeStrings
as
$attributeString
)
{
// split on the first equals sign and use the rest as value
$attributeParts
=
explode
(
'='
,
$attributeString
,
2
);
$attributeName
=
trim
(
$attributeParts
[
0
]);
$attributeNameLC
=
strtolower
(
$attributeName
);
if
(
isset
(
$attributeParts
[
1
]))
{
$attributeValue
=
trim
(
$attributeParts
[
1
]);
// Values may be quoted strings.
if
(
strpos
(
$attributeValue
,
'"'
)
===
0
)
{
$attributeValue
=
trim
(
$attributeValue
,
'"'
);
// unescape any escaped quotes:
$attributeValue
=
str_replace
(
'\"'
,
'"'
,
$attributeValue
);
}
}
else
{
$attributeValue
=
null
;
}
switch
(
$attributeNameLC
)
{
case
'expires'
:
$cookie
[
'expires'
]
=
strtotime
(
$attributeValue
);
break
;
case
'max-age'
:
$cookie
[
'max-age'
]
=
(
int
)
$attributeValue
;
// Set an expiry time based on the max-age
if
(
$cookie
[
'max-age'
])
{
$cookie
[
'expires'
]
=
time
()
+
$cookie
[
'max-age'
];
}
else
{
// If max-age is zero, then the cookie should be removed
// imediately so set an expiry before now.
$cookie
[
'expires'
]
=
time
()
-
1
;
}
break
;
case
'secure'
:
$cookie
[
'secure'
]
=
true
;
break
;
case
'domain'
:
case
'path'
:
case
'port'
:
case
'version'
:
case
'comment'
:
case
'commenturl'
:
case
'discard'
:
case
'httponly'
:
$cookie
[
$attributeNameLC
]
=
$attributeValue
;
break
;
default
:
$cookie
[
'name'
]
=
$attributeName
;
$cookie
[
'value'
]
=
$attributeValue
;
}
}
return
$cookie
;
}
/**
* Add, update, or remove a cookie.
*
* @param array $cookie A cookie array as created by parseCookieHeaders()
*
* @return void
*
* @access protected
*/
protected
function
storeCookie
(
$cookie
)
{
// Discard any old versions of this cookie.
$this
->
discardCookie
(
$cookie
);
$this
->
_cookies
[]
=
$cookie
;
}
/**
* Discard an existing cookie
*
* @param array $cookie An cookie
*
* @return void
*
* @access protected
*/
protected
function
discardCookie
(
$cookie
)
{
if
(
!
isset
(
$cookie
[
'domain'
])
||
!
isset
(
$cookie
[
'path'
])
||
!
isset
(
$cookie
[
'path'
])
)
{
throw
new
CAS_InvalidArgumentException
(
'Invalid Cookie array passed.'
);
}
foreach
(
$this
->
_cookies
as
$key
=>
$old_cookie
)
{
if
(
$cookie
[
'domain'
]
==
$old_cookie
[
'domain'
]
&&
$cookie
[
'path'
]
==
$old_cookie
[
'path'
]
&&
$cookie
[
'name'
]
==
$old_cookie
[
'name'
]
)
{
unset
(
$this
->
_cookies
[
$key
]);
}
}
}
/**
* Go through our stored cookies and remove any that are expired.
*
* @return void
*
* @access protected
*/
protected
function
expireCookies
()
{
foreach
(
$this
->
_cookies
as
$key
=>
$cookie
)
{
if
(
isset
(
$cookie
[
'expires'
])
&&
$cookie
[
'expires'
]
<
time
())
{
unset
(
$this
->
_cookies
[
$key
]);
}
}
}
/**
* Answer true if cookie is applicable to a target.
*
* @param array $cookie An array of cookie attributes.
* @param array $target An array of URL attributes as generated by parse_url().
*
* @return bool
*
* @access private
*/
protected
function
cookieMatchesTarget
(
$cookie
,
$target
)
{
if
(
!
is_array
(
$target
))
{
throw
new
CAS_InvalidArgumentException
(
'$target must be an array of URL attributes as generated by parse_url().'
);
}
if
(
!
isset
(
$target
[
'host'
]))
{
throw
new
CAS_InvalidArgumentException
(
'$target must be an array of URL attributes as generated by parse_url().'
);
}
// Verify that the scheme matches
if
(
$cookie
[
'secure'
]
&&
$target
[
'scheme'
]
!=
'https'
)
{
return
false
;
}
// Verify that the host matches
// Match domain and mulit-host cookies
if
(
strpos
(
$cookie
[
'domain'
],
'.'
)
===
0
)
{
// .host.domain.edu cookies are valid for host.domain.edu
if
(
substr
(
$cookie
[
'domain'
],
1
)
==
$target
[
'host'
])
{
// continue with other checks
}
else
{
// non-exact host-name matches.
// check that the target host a.b.c.edu is within .b.c.edu
$pos
=
strripos
(
$target
[
'host'
],
$cookie
[
'domain'
]);
if
(
!
$pos
)
{
return
false
;
}
// verify that the cookie domain is the last part of the host.
if
(
$pos
+
strlen
(
$cookie
[
'domain'
])
!=
strlen
(
$target
[
'host'
]))
{
return
false
;
}
// verify that the host name does not contain interior dots as per
// RFC 2965 section 3.3.2 Rejecting Cookies