Skip to content

Commit c7400c5

Browse files
Merge pull request #97 from ericvaandering/add_autocreate
Automatically create account for shibboleth version
2 parents f9b3ec7 + e00fe31 commit c7400c5

6 files changed

Lines changed: 219 additions & 2 deletions

File tree

DocDB/cgi/DocDBGlobals.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ $Preferences{Security}{Certificates}{ShowCertInstructions} = $FALSE; # TRUE or
9292
$Preferences{Security}{AuthName} = ""; # Set to override default AuthName of group1 or group2, etc.
9393
$Preferences{Security}{SSOGroupVariables} = (); # Environmental variables with lists of groups
9494
$Preferences{Security}{AutoCreateSSO} = $FALSE; # Automatically create an SSO user if none exists
95+
$Preferences{Security}{AutoCreateShib} = $FALSE; # Automatically create a Shibboleth user if none exists
9596
$Preferences{Security}{UseCertGroupsForSSO} = $FALSE; # If no SSO account exists, use the groups from the certificate
9697
$Preferences{Security}{TransferCertToSSO} = $FALSE; # Automatically transfer certificate user information to SSO
9798
# (implies AutoCreateSSO)

DocDB/cgi/DocDBVersion.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
# along with DocDB; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2323

24-
$DocDBVersion = "8.8.9p1";
24+
$DocDBVersion = "8.8.9p2";
2525

2626
1;

DocDB/cgi/EmailLogin

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ $dbh = DBI->connect('DBI:mysql:'.$db_name.':'.$db_host,$db_rouser,$db_ropass);
3939
print $query -> header( -charset => $HTTP_ENCODING );
4040
&DocDBHeader("Personal Account Login");
4141

42+
if ($UserValidation eq "shibboleth" or $UserValidation eq "FNALSSO") {
43+
push @ErrorStack,"This page is not valid for single sign-on methods.";
44+
}
45+
EndPage();
46+
4247
print "<p/>\n";
4348
print "<b>This page is used to log into or create a personal $Project DocDB account. You
4449
can use this account to set e-mail notifications. DocDB will e-mail

DocDB/cgi/ShibbolethUtilities.pm

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,50 @@ sub FetchEmailUserIDForShib () {
6868

6969
my ($EmailUserID) = $EmailUserSelect -> fetchrow_array;
7070

71+
if (!$EmailUserID and $Preferences{Security}{AutoCreateShib}) {
72+
$EmailUserID = CreateShibUser();
73+
}
74+
7175
if ($EmailUserID) {
7276
FetchEmailUser($EmailUserID)
7377
}
7478

7579
return $EmailUserID;
7680
}
7781

78-
1;
82+
sub CreateShibUser() {
83+
my ($FQUN, $UserName, $Email, $Name) = GetUserInfoShib();
84+
if ($FQUN eq 'Unknown') {
85+
push @DebugStack, 'Username is Unknown. Not inserting. SSO may not be set up correctly.';
86+
return;
87+
}
88+
89+
push @DebugStack, "Creating Shibboleth SSO user in EmailUser with Username=$FQUN, Email=$Email, Name=$Name";
90+
CreateConnection(-type => "rw"); # Can't rely on connection setup by top script, may be read-only
91+
my $UserInsert = $dbh_rw->prepare(
92+
"insert into EmailUser (EmailUserID,Username,Name,EmailAddress,Password,Verified) " .
93+
"values (0, ?, ?, ?, ?, 1)");
94+
$UserInsert->execute($FQUN, $Name, $Email, 'x');
95+
my $EmailUserID = $UserInsert -> {mysql_insertid}; # Works with MySQL only
96+
DestroyConnection($dbh_rw);
97+
push @DebugStack, "Created EmailUserID $EmailUserID for SSO";
98+
return $EmailUserID;
99+
}
100+
101+
sub GetUserInfoShib() {
102+
my $Username = "Unknown";
103+
my $EmailAddress = "Unknown";
104+
my $Name = "Unknown";
105+
106+
if (exists $ENV{'ADFS_LOGIN'}) {
107+
$Name = $ENV{ADFS_FULLNAME};
108+
$EmailAddress = $ENV{ADFS_EMAIL};
109+
$Username = $ENV{ADFS_LOGIN};
110+
}
111+
112+
push @DebugStack, "GetUserInfoShib returning $Username, $Username, $EmailAddress, $Name";
113+
114+
return ($Username, $Username, $EmailAddress, $Name);
115+
}
116+
117+
1;

DocDB/doc/CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
8.8.9p2
2+
Add an option $Preferences{Security}{AutoCreateShib} (defaults to $FALSE) to automatically create shibboleth accounts
3+
(following what was done for Fermilab SSO). Fixes a regression where it was difficult or impossible to make an account
4+
15
8.8.9p1
26
Fix the author searching JS for old cases where first or last name may not exist
37
Include a patch from 8.7 branch that was never included

DocDB/html/js/OldCMS.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// This code was in the CMS DocDB but was preventing the author fields from being pre-filled. It was removed as it doesn't
2+
// seem to provide real value. Originally written by Vidmantis
3+
4+
5+
var docDB_temp_hacks = 0;
6+
7+
8+
function extended_author_search(){
9+
jQuery.extend(jQuery.expr[':'], {
10+
'containsi': function(elem, i, match, array)
11+
{
12+
return (elem.textContent || elem.innerText || '').toLowerCase()
13+
.indexOf((match[3] || "").toLowerCase()) >= 0;
14+
}
15+
});
16+
jQuery.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
17+
while(x<c.length){var m=r.exec(c.substr(x));
18+
if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
19+
}else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
20+
o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
21+
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
22+
while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
23+
t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
24+
});
25+
26+
27+
// extract url parameter
28+
jQuery.extend({
29+
getUrlVars: function(){
30+
var vars = [], hash;
31+
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
32+
for(var i = 0; i < hashes.length; i++)
33+
{
34+
hash = hashes[i].split('=');
35+
vars.push(hash[0]);
36+
vars[hash[0]] = hash[1];
37+
}
38+
return vars;
39+
},
40+
getUrlVar: function(name){
41+
return jQuery.getUrlVars()[name];
42+
}
43+
});
44+
45+
var author_search = jQuery.getUrlVar('author');
46+
47+
48+
if (author_search){
49+
jQuery('h3').html(jQuery('<a href="#">show all authors</a>').click(function(){jQuery('table tr td ul li, table tr td a, table tr th').show(); })).show();
50+
51+
52+
jQuery('table tr td ul li, table tr td a, table tr th').hide();
53+
54+
params = author_search.replace('.', ' ').replace('+', ' ').replace(',', ' ').split(' ')
55+
56+
filtered = jQuery('table tr td ul li a')
57+
58+
jQuery(params).each(function(i, param){
59+
//TODO: handle special chars and international names
60+
//console.log(param);
61+
62+
//clean up the string, leave only letters
63+
param = param.replace(/[^a-zA-Z]/g, '');
64+
if (!param)
65+
return;
66+
67+
filtered = filtered.filter(':containsi('+param+')');
68+
});
69+
items = filtered.show().parent().show().addClass('search_matched')
70+
71+
72+
//console.log(items)
73+
74+
/* If there was only one result, point to the documents by the author */
75+
if (items.length == 1){
76+
var target = items.find("a").first().attr('href');
77+
//console.log("Blah:"+target);
78+
location.href = target;
79+
}
80+
}
81+
82+
}
83+
84+
85+
function apply_cms_styles(){
86+
/* watermark the search */
87+
var searchField = jQuery('div#header-search-container input[type=text][name=simpletext]');
88+
/* we take the value of watermark from title attribute */
89+
searchField.watermark(searchField.attr('title'), {className: 'watermark-search'});
90+
91+
jQuery('div#header-search-container form').submit(function(e){
92+
//check if value has an ID
93+
var value =jQuery('input#header-search-input').val();
94+
//alert(value);
95+
var regexp = /id:(\\d+)/i;
96+
if (regexp.test(value)){
97+
//alert('ID');
98+
e.preventDefault();
99+
value.match(regexp);
100+
docid = RegExp.\$1;
101+
window.location.href = 'ShowDocument?docid=' + docid
102+
}
103+
});
104+
105+
106+
/* hide keywords */
107+
if (jQuery('form#documentadd input[name=keywords]')) {
108+
jQuery('form#documentadd input[name=keywords]').parents("tr").first().hide();
109+
}
110+
111+
/* fix styles */
112+
for (i=1; i<1000; i=i+2){
113+
if (!jQuery('input[name=upload'+i+']'))
114+
break;
115+
jQuery('input[name=upload'+i+']').parents('tr').first().addClass('FileUpload');
116+
jQuery('input[name=filedesc'+i+']').parents('tr').first().addClass('FileUpload');
117+
jQuery('input[name=fileid'+i+']').parents('tr').first().addClass('FileUpload');
118+
}
119+
120+
121+
122+
123+
if (docDB_temp_hacks){
124+
/* TODO: (temporaly) set up file input coloring */
125+
for (i=1; i<1000; i=i+2){
126+
if (!jQuery('input[name=upload'+i+']'))
127+
break;
128+
jQuery('input[name=upload'+i+']').parents('tr').first().addClass('file-upload-row-odd');
129+
jQuery('input[name=filedesc'+i+']').parents('tr').first().addClass('file-upload-row-odd');
130+
jQuery('input[name=fileid'+i+']').parents('tr').first().addClass('file-upload-row-odd');
131+
}
132+
133+
/* add select all button */
134+
if (jQuery('form#documentadd input[name=copyfile1]')){
135+
jQuery('form#documentadd input[name=copyfile1]').parents("td").first().append(' <a>copy all files<a>').toggle(function(evt){evt.preventDefault();jQuery('[name^="copyfile"]').val(["on"])}, function(evt){evt.preventDefault();jQuery('[name^="copyfile"]').val([""])})
136+
}
137+
138+
}
139+
140+
141+
}
142+
143+
/* ========== set up the validation =========== */
144+
function form_add_validation(){
145+
146+
jQuery.validator.messages.required = "";
147+
148+
/* pre-validate the form */
149+
jQuery("form#documentadd").validate({onfocusout: true, onkeyup: true});
150+
}
151+
152+
153+
if (!(typeof jQuery === 'undefined') && !(typeof jQuery.validator === 'undefined')){
154+
jQuery(document).ready(function() {
155+
/* Here we could customize the validation (again) */
156+
form_add_validation();
157+
});
158+
}
159+
160+
if (!(typeof jQuery === 'undefined')){
161+
jQuery(document).ready(function() {
162+
apply_cms_styles();
163+
extended_author_search();
164+
if (jQuery('form#documentadd select[name=security]').length == 1) { CmsTransformPermissions(); }
165+
});
166+
}
167+
168+

0 commit comments

Comments
 (0)