Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
cbe0a548
Commit
cbe0a548
authored
7 years ago
by
Thijs Kinkhorst
Browse files
Options
Downloads
Patches
Plain Diff
PSR-2
, no functional changes
parent
02885dc0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/casserver/www/serviceValidate.php
+79
-75
79 additions, 75 deletions
modules/casserver/www/serviceValidate.php
with
79 additions
and
75 deletions
modules/casserver/www/serviceValidate.php
+
79
−
75
View file @
cbe0a548
<?php
require
'tickets.php'
;
require
(
'tickets.php'
)
;
# set manually if called directly - ie not included from validate.php or cas.php
if
(
!
$function
)
$function
=
'serviceValidate'
;
// set manually if called directly - ie not included from validate.php or cas.php
if
(
!
$function
)
{
$function
=
'serviceValidate'
;
}
/*
* Incoming parameters:
...
...
@@ -11,93 +13,95 @@ if (!$function) $function = 'serviceValidate';
* ticket
*
*/
if
(
array_key_exists
(
'service'
,
$_GET
))
{
$service
=
$_GET
[
'service'
];
$ticket
=
$_GET
[
'ticket'
];
$forceAuthn
=
isset
(
$_GET
[
'renew'
])
&&
$_GET
[
'renew'
];
$service
=
$_GET
[
'service'
];
$ticket
=
$_GET
[
'ticket'
];
$forceAuthn
=
isset
(
$_GET
[
'renew'
])
&&
$_GET
[
'renew'
];
}
else
{
throw
new
Exception
(
'Required URL query parameter [service] not provided. (CAS Server)'
);
throw
new
Exception
(
'Required URL query parameter [service] not provided. (CAS Server)'
);
}
try
{
// Load SimpleSAMLphp, configuration and metadata
$casconfig
=
SimpleSAML_Configuration
::
getConfig
(
'module_casserver.php'
);
$path
=
$casconfig
->
resolvePath
(
$casconfig
->
getValue
(
'ticketcache'
,
'ticketcache'
));
$ticketcontent
=
retrieveTicket
(
$ticket
,
$path
);
$usernamefield
=
$casconfig
->
getValue
(
'attrname'
,
'eduPersonPrincipalName'
);
$dosendattributes
=
$casconfig
->
getValue
(
'attributes'
,
FALSE
);
$attributes
=
$ticketcontent
[
'attributes'
];
// Load SimpleSAMLphp, configuration and metadata
$casconfig
=
SimpleSAML_Configuration
::
getConfig
(
'module_casserver.php'
);
$pgtiouxml
=
""
;
$path
=
$casconfig
->
resolvePath
(
$casconfig
->
getValue
(
'ticketcache'
,
'ticketcache'
));
$ticketcontent
=
retrieveTicket
(
$ticket
,
$path
);
if
(
$ticketcontent
[
'service'
]
==
$service
&&
$ticketcontent
[
'forceAuthn'
]
==
$forceAuthn
&&
array_key_exists
(
$usernamefield
,
$attributes
)
&&
$ticketcontent
[
'validbefore'
]
>
time
())
{
if
(
isset
(
$_GET
[
'pgtUrl'
]))
{
$pgtUrl
=
$_GET
[
'pgtUrl'
];
$pgtiou
=
str_replace
(
'_'
,
'PGTIOU-'
,
SimpleSAML\Utils\Random
::
generateID
());
$pgt
=
str_replace
(
'_'
,
'PGT-'
,
SimpleSAML\Utils\Random
::
generateID
());
$content
=
array
(
'attributes'
=>
$attributes
,
'forceAuthn'
=>
false
,
'proxies'
=>
array_merge
(
array
(
$service
),
$ticketcontent
[
'proxies'
]),
'validbefore'
=>
time
()
+
60
);
\SimpleSAML\Utils\HTTP
::
fetch
(
$pgtUrl
.
'?pgtIou='
.
$pgtiou
.
'&pgtId='
.
$pgt
);
storeTicket
(
$pgt
,
$path
,
$content
);
$pgtiouxml
=
"
\n
<cas:proxyGrantingTicket>
$pgtiou
</cas:proxyGrantingTicket>
\n
"
;
}
$proxiesxml
=
join
(
"
\n
"
,
array_map
(
function
(
$a
)
{
return
"<cas:proxy>
$a
</cas:proxy>"
;
},
$ticketcontent
[
'proxies'
]));
if
(
$proxiesxml
)
{
$proxiesxml
=
"<cas:proxies>
\n
$proxiesxml
\n
</cas:proxies>
\n
"
;
}
returnResponse
(
'YES'
,
$function
,
$attributes
[
$usernamefield
][
0
],
$dosendattributes
?
$attributes
:
array
(),
$pgtiouxml
.
$proxiesxml
);
}
else
{
returnResponse
(
'NO'
,
$function
);
$usernamefield
=
$casconfig
->
getValue
(
'attrname'
,
'eduPersonPrincipalName'
);
$dosendattributes
=
$casconfig
->
getValue
(
'attributes'
,
false
);
$attributes
=
$ticketcontent
[
'attributes'
];
$pgtiouxml
=
""
;
if
(
$ticketcontent
[
'service'
]
==
$service
&&
$ticketcontent
[
'forceAuthn'
]
==
$forceAuthn
&&
array_key_exists
(
$usernamefield
,
$attributes
)
&&
$ticketcontent
[
'validbefore'
]
>
time
())
{
if
(
isset
(
$_GET
[
'pgtUrl'
]))
{
$pgtUrl
=
$_GET
[
'pgtUrl'
];
$pgtiou
=
str_replace
(
'_'
,
'PGTIOU-'
,
SimpleSAML\Utils\Random
::
generateID
());
$pgt
=
str_replace
(
'_'
,
'PGT-'
,
SimpleSAML\Utils\Random
::
generateID
());
$content
=
array
(
'attributes'
=>
$attributes
,
'forceAuthn'
=>
false
,
'proxies'
=>
array_merge
(
array
(
$service
),
$ticketcontent
[
'proxies'
]),
'validbefore'
=>
time
()
+
60
);
\SimpleSAML\Utils\HTTP
::
fetch
(
$pgtUrl
.
'?pgtIou='
.
$pgtiou
.
'&pgtId='
.
$pgt
);
storeTicket
(
$pgt
,
$path
,
$content
);
$pgtiouxml
=
"
\n
<cas:proxyGrantingTicket>
$pgtiou
</cas:proxyGrantingTicket>
\n
"
;
}
$proxiesxml
=
join
(
"
\n
"
,
array_map
(
function
(
$a
)
{
return
"<cas:proxy>
$a
</cas:proxy>"
;
},
$ticketcontent
[
'proxies'
]));
if
(
$proxiesxml
)
{
$proxiesxml
=
"<cas:proxies>
\n
$proxiesxml
\n
</cas:proxies>
\n
"
;
}
returnResponse
(
'YES'
,
$function
,
$attributes
[
$usernamefield
][
0
],
$dosendattributes
?
$attributes
:
array
(),
$pgtiouxml
.
$proxiesxml
);
}
else
{
returnResponse
(
'NO'
,
$function
);
}
}
catch
(
Exception
$e
)
{
returnResponse
(
'NO'
,
$function
,
$e
->
getMessage
());
returnResponse
(
'NO'
,
$function
,
$e
->
getMessage
());
}
function
returnResponse
(
$value
,
$function
,
$usrname
=
''
,
$attributes
=
array
(),
$xtraxml
=
""
)
{
if
(
$value
===
'YES'
)
{
if
(
$function
!=
'validate'
)
{
$attributesxml
=
""
;
foreach
(
$attributes
as
$attributename
=>
$attributelist
)
{
$attr
=
htmlspecialchars
(
$attributename
);
foreach
(
$attributelist
as
$attributevalue
)
{
$attributesxml
.
=
"<cas:
$attr
>"
.
htmlspecialchars
(
$attributevalue
)
.
"</cas:
$attr
>
\n
"
;
}
}
if
(
sizeof
(
$attributes
))
$attributesxml
=
"<cas:attributes>
\n
"
.
$attributesxml
.
"</cas:attributes>
\n
"
;
echo
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
function
returnResponse
(
$value
,
$function
,
$usrname
=
''
,
$attributes
=
array
(),
$xtraxml
=
""
)
{
if
(
$value
===
'YES'
)
{
if
(
$function
!=
'validate'
)
{
$attributesxml
=
""
;
foreach
(
$attributes
as
$attributename
=>
$attributelist
)
{
$attr
=
htmlspecialchars
(
$attributename
);
foreach
(
$attributelist
as
$attributevalue
)
{
$attributesxml
.
=
"<cas:
$attr
>"
.
htmlspecialchars
(
$attributevalue
)
.
"</cas:
$attr
>
\n
"
;
}
}
if
(
sizeof
(
$attributes
))
$attributesxml
=
"<cas:attributes>
\n
"
.
$attributesxml
.
"</cas:attributes>
\n
"
;
echo
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
<cas:authenticationSuccess>
<cas:user>'
.
htmlspecialchars
(
$usrname
)
.
'</cas:user>'
.
$xtraxml
.
$attributesxml
.
'</cas:authenticationSuccess>
$xtraxml
.
$attributesxml
.
'</cas:authenticationSuccess>
</cas:serviceResponse>'
;
}
else
{
echo
'yes'
.
"
\n
"
.
$usrname
;
}
}
else
{
if
(
$function
!=
'validate'
)
{
echo
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
}
else
{
echo
'yes'
.
"
\n
"
.
$usrname
;
}
}
else
{
if
(
$function
!=
'validate'
)
{
echo
'<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
<cas:authenticationFailure code="">
</cas:authenticationFailure>
</cas:serviceResponse>'
;
}
else
{
echo
'no'
;
}
}
}
\ No newline at end of file
}
else
{
echo
'no'
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment