I direct this post to you, since you've kindly answered my questions
along the way, as well as stating your interest in a working SAML2.0 SSO
solution for RS.
Well, I just managed getting simpleSAMLphp to function as a SAML2.0
Service Provider for Resourcespace by editing the 'login.php' page only.
I have yet to convert my changes into a working plugin for RS, but it
seems managable with only minor changes to the current 'login.php'.
My idea for now, concerning the plugin integration with 'login.php', is
to add a variable check that defaults to 'false' in case simpleSAMLphp
is not present, which in case of 'true' would fire an externalauth hook,
supplying it with a dummy username and password which would be set to
the username and password of the SAML2.0 identity logged in through an IdP!
Now, Tom, do you think this would work?
Best regards,
S�ren G.
Søren G.
--
You received this message because you are subscribed to the Google Groups "ResourceSpace" group.
To post to this group, send email to resour...@googlegroups.com.
To unsubscribe from this group, send email to resourcespac...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/resourcespace?hl=en.
what I do is to introduce simpleSAMLphp as a SAML2.0 Service Provider,
installed on the same site as RS, and then completely bypass the
login.php page on RS by replacing this page with a simple page
consisting of 3 lines of PHP code:
<?php
require_once "simplesamlphp/lib/_autoload.php";
$auth = new SimpleSAML_Auth_Simple('Resourcespace');
$auth -> requireAuth(array('ReturnTo' =>
'https://server.example.com/setcookies.php', 'KeepPost' => FALSE,));
?>
...which sends the user back to RS and a page that sets the user's
cookies and adds the user to the SQL backend (if not already added) with
the same $ref as the user's LDAP uidNumber, before loading the RS frontpage.
This page effectively functions as the regular login.php + some of the
ldapauth plugin functionalities.
The code for setcookies.php is as follows:
<?php
require_once "simplesamlphp/lib/_autoload.php";
include "include/db.php";
include "include/general.php";
include "include/resource_functions.php";
include "include/collections_functions.php";
global $auth;
global $username;
global $password;
global $password_hash;
global $usergroup;
$auth = new SimpleSAML_Auth_Simple('Resourcespace');
/*
* Check for initial authentication, then login user and set session
and language cookies
*/
if ($auth->isAuthenticated()) {
/*
* Get SAML2.0 attributes from response.
*/
$attributes = $auth -> getAttributes();
$username = $attributes['uid'][0];
$password = $attributes['userPassword'][0];
$password_hash = md5("RS".$username . $password);
$ref = $attributes['uidNumber'][0];
$usergroup = $attributes['rsUserGroup'][0];
$fullname = $attributes['cn'][0];
$email = $attributes['mail'][0];
$session_hash = md5($password_hash . $username . $password .
date("Y-m-d"));
$ip = get_ip();
$comments = "Auto created SAML2 authenticated user from
server.example.com";
/*
* Check if user already exists in SQL backend.
* If user exists, login. If not, authenticate with simpleSAMLphp
SP as configured earlier.
*/
$user_exists=sql_query('SELECT ref FROM user WHERE
username="'.$username.'"');
if (count($user_exists)>=1) {
sql_query('UPDATE user SET password="'.$password_hash.'" WHERE
username="'.$username.'"');
}
/*
* Initialize SQL user fields from SAML-response.
*/
else {
/*
* Create user in SQL backend.
*/
sql_query("INSERT INTO user (ref, username, password, fullname,
email, usergroup, comments) VALUES ('$ref' , '$username' ,
'$password_hash' , '$fullname' , '$email' , '$usergroup' , '$comments')");
}
$session_hash = md5($password_hash . $username . $password .
date("Y-m-d"));
$valid=sql_query("SELECT ref FROM user WHERE username='$username'
AND password='$password_hash'");
if (count($valid)>=1) {
# Account expiry
$expires=sql_value("SELECT account_expires VALUE FROM user
WHERE username='$username' AND password='$password'","");
if ($expires!="" && $expires!="0000-00-00 00:00:00" &&
strtotime($expires)<=time()) {
$valid=0;$error=$lang["accountexpired"];
}
else {
$expires=0;
if (getval("remember","")!="") {
$expires=time()+(3600*24*100);
} # remember login for 100 days
# Store language cookie
if ($global_cookies) {
setcookie("language","en",time()+(3600*24*1000),"/");
}
else {
setcookie("language","en",time()+(3600*24*1000));
setcookie("language","en",time()+(3600*24*1000),$baseurl_short . "pages/");
}
$language_selection="en";
# Update the user record. Set the password hash again in
case a plain text password was provided.
sql_query("UPDATE user SET
password='$password_hash',session='$session_hash',last_active=now(),login_tries=0,lang='$language_selection'
WHERE username='$username' AND (password='$password_hash')");
# Blank the IP address lockout counter for this IP
sql_query("DELETE FROM ip_lockout WHERE ip='" .
escape_check($ip) . "'");
# Set the session cookie.
if ($global_cookies){
$cookie_path="/";
setcookie("user","",1);
}
else {
$cookie_path="";
setcookie("user","",1,"/");
}
setcookie("user",$username . "|" .
$session_hash,$expires,$cookie_path);
setcookie("email",$email,$expires,$cookie_path);
# Set default resource types
#setcookie("restypes",$default_res_types);
# If the redirect URL is the collection frame, do not
redirect to this as this will cause
# the collection frame to appear full screen.
#if (strpos($url,"pages/collections.php")!==false) {
# $url="index.php";
#}
}
}
?>
<script type="text/javascript">
top.location.href="https://server.example.com";
</script>
<?php
}
?>
Please pardon if my PHP skills aren't all too obvious ;)
As mentioned in an earlier reply to Tom (among others), I haven't made
this into an RS plugin, but I guess it'd be possible :)
-At the same time, I ONLY use SAML2.0 as authentication method, so I've
never worried about externalauth or ldapauth alongside SAML2.0,
basically beacuse simpleSAMLphp offers all of this already (and it works
beutifully!) ...
I hope it makes just little sense to you, otherwise feel free to ask!
Best regards,
S�ren G.
> --
> You received this message because you are subscribed to the Google
> Groups "ResourceSpace" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/resourcespace/-/wbEhVPm4mPUJ.
There are a few things that need to be taken into consideration, though.
E.g. the missing password when logging in to RS through simpleSAMLphp,
since it doesn't ever send a password as such, which is why simply md5
encode the string already contained (in my case) in the LDAP attribute
'uidNumber' and save this along with the user information. Since
passwords would then be possible to reset in the LDAP, there's no need
for such a function in RS, which is why I turned it off.
It'll probably be nice to set cookie lifetime to a fixed number of hours
when using simpleSAMLphp, since cookies with a longer lifetime than the
SAML2.0 token at times require users to reauthenticate with
simpleSAMLphp before being able to even logout, since the $auth ->
requireAuth() function halts any activity until it itself is able to get
a positive answer from $auth -> isAuthenticated() ...
Those details shouldn't be too hard to overcome with default settings
for a plugin, overriding certain standard RS settings, but are worth
taking into consideration :)
I'm not sure when I'll have the time to look into this, but at the
moment I'm finishing off my own RS implementation, looking into merging
my patches with the latest revision from SVN and after that I'll
probably be able to take it for a spin :)
Cheers,
S�ren G.
On 15/11/11 00.12, Dan Huby wrote:
> Looks great S�ren... a plugin version (as for LDAP) would be useful
-David
> --
> You received this message because you are subscribed to the Google Groups "ResourceSpace" group.
Of course! Feel free to mail me directly.
Best regards,
S�ren
Of course! Feel free to mail me directly.
Best regards,
S�ren
--
ResourceSpace: Open Source Digital Asset Management
http://www.resourcespace.org
---
You received this message because you are subscribed to the Google Groups "ResourceSpace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to resourcespac...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.