Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UNL Information Services
NMC-PHP-Framework
Commits
942c6bab
Commit
942c6bab
authored
Sep 04, 2013
by
Tim Steiner
Browse files
Updates to Unl_Cas to make the native PHP session handling work with older versions of PHP. @1h00
parent
e3d4d2c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
library/Unl/Cas.php
View file @
942c6bab
...
...
@@ -41,8 +41,9 @@ class Unl_Cas
const
PARAM_RENEW
=
3
;
/**
* Session storage use to prevent infinate redirect loops when in gateway mode.
* @var Zend_Session_Namespace
* Session storage use to prevent infinite redirect loops when in gateway mode.
* Do not use this directly, use $this->_session()
* @var Zend_Session_Namespace|array
*/
private
$_session
;
...
...
@@ -75,13 +76,10 @@ class Unl_Cas
$this
->
_session
=
new
Zend_Session_Namespace
(
__CLASS__
);
}
catch
(
Zend_Session_Exception
$e
)
{
//Problem starting Zend_Session (probably because it was already started, use standard PHP sessions.
if
(
!
array_key_exists
(
__CLASS__
,
$_SESSION
)
||
!
$_SESSION
[
__CLASS__
]
instanceof
ArrayObject
)
{
$_SESSION
[
__CLASS__
]
=
new
ArrayObject
();
if
(
!
array_key_exists
(
__CLASS__
,
$_SESSION
)
||
!
is_array
(
$_SESSION
[
__CLASS__
]
)
)
{
$_SESSION
[
__CLASS__
]
=
array
();
}
$this
->
_session
=
$_SESSION
[
__CLASS__
];
}
if
(
!
isset
(
$this
->
_session
->
ticket
))
{
$this
->
_session
->
ticket
=
NULL
;
$this
->
_session
=
NULL
;
}
}
...
...
@@ -160,7 +158,7 @@ class Unl_Cas
*/
public
function
getUsername
()
{
return
$this
->
_session
->
username
;
return
$this
->
_session
(
'
username
'
)
;
}
/**
...
...
@@ -290,7 +288,7 @@ class Unl_Cas
$response
=
$client
->
request
();
if
(
$response
->
isSuccessful
()
&&
$this
->
_parseResponse
(
$response
->
getBody
()))
{
$this
->
_addValidTicket
(
$ticket
);
$this
->
_session
->
ticket
=
$ticket
;
$this
->
_session
(
'
ticket
'
,
$ticket
)
;
return
true
;
}
return
false
;
...
...
@@ -308,7 +306,7 @@ class Unl_Cas
if
(
$xml
->
loadXML
(
$response
))
{
if
(
$success
=
$xml
->
getElementsByTagName
(
'authenticationSuccess'
))
{
if
(
$success
->
length
>
0
&&
$uid
=
$success
->
item
(
0
)
->
getElementsByTagName
(
'user'
))
{
$this
->
_session
->
username
=
$uid
->
item
(
0
)
->
nodeValue
;
$this
->
_session
(
'
username
'
,
$uid
->
item
(
0
)
->
nodeValue
)
;
return
true
;
}
}
...
...
@@ -362,7 +360,7 @@ class Unl_Cas
public
function
isTicketExpired
()
{
return
!
$this
->
_isStillValidTicket
(
$this
->
_session
->
ticket
);
return
!
$this
->
_isStillValidTicket
(
$this
->
_session
(
'
ticket
'
)
);
}
public
function
handleLogoutRequest
(
$saml
)
...
...
@@ -382,9 +380,30 @@ class Unl_Cas
public
function
destroySession
()
{
$this
->
_removeValidTicket
(
$this
->
_session
->
ticket
);
$this
->
_session
->
ticket
=
NULL
;
$this
->
_session
->
username
=
NULL
;
$this
->
_removeValidTicket
(
$this
->
_session
(
'ticket'
));
$this
->
_session
(
'ticket'
,
NULL
);
$this
->
_session
(
'username'
,
NULL
);
}
// Wrapper to use either Zend sessions or native PHP sessions
protected
function
_session
(
$key
,
$val
=
NULL
)
{
if
(
$this
->
_session
instanceof
Zend_Session_Namespace
)
{
if
(
func_num_args
()
==
2
)
{
$this
->
_session
->
$key
=
$val
;
}
else
{
return
$this
->
_session
->
$key
;
}
}
else
{
if
(
func_num_args
()
==
2
)
{
$_SESSION
[
__CLASS__
][
$key
]
=
$val
;
}
else
{
if
(
!
isset
(
$_SESSION
[
__CLASS__
][
$key
]))
{
return
NULL
;
}
return
$_SESSION
[
__CLASS__
][
$key
];
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment