The Helma code-snippets provided here http://www.sorua.net/stories/776023/ are just intented for demonstration purpose, and are not expected to work out-of-the-box. I attached the adapted UserServer, which hopefully works for Antville-installations.
So you probably need the following steps to enable UserServer for Antville:
* download the commons-httpclient-3.0-rc2.jar from http://jakarta.apache.org/site/downloads/downloads_commons-httpclient... and put it into your code-repository (or to [HelmaDir]/lib/ext)
* put the attacht file modSoruaUserServer.js into [AntvilleDir]/MemberMgr
* Adapt function Root.modSoruaUserServerGetArrayOfKnownAuthServers to define your list of known AuthServers.
* Include the following lines somewhere into the MemberMgr/login Skin:
----------------------
<tr>
<td valign="top"><% input id="isusersorua" type="radio" name="isuser" value="sorua" %></td>
<td>
I am registered at another Service with <b>SORUA</b>-Authentification.<br />
<% MemberMgr.modSoruaUserServerKnownAuthServers width="100" as="dropdown" onChange="document.getElementById('isusersorua').checked='checked'" %>
</td>
</tr>
----------------------
* And include the following lines into the MemberMgr/login_action:
--------------------
function login_action() {
...
if (req.data.login && req.data.isuser == "sorua") {
var redUrl = this.href("modSoruaUserServer") + "?submit=1";
if (req.data.name) redUrl += "&name=" + req.data.name;
redUrl += "&authuri=" + escape(req.data.modSoruaAuthServerAuthUri);
if (req.data.remember || req.data.remembersorua) redUrl += "&remember=1";
res.redirect(redUrl);
}else if (req.data.login) {
...
--------------------
hope this works, but cant tell for sure.
greets,
michi
--
DI Michael Platzer
technical director
--------------------------------------
knallgrau new media solutions gmbh
pezzlgasse 7|1, A-1170 wien
phone: +43 - 1 - 522 76 37
fax: +43 - 1 - 522 76 38
http://www.knallgrau.at
/**
* SORUA UserServer
* Handles submitted login form, which performs redirect to AuthServer for authentication.
* Handles returned UserClient and asks AuthServer for verification.
*
*/
function modSoruaUserServer_action() {
// UserClient is returned by AuthServer
if (req.data.token && session.data.modSoruaAuthUri) {
// use the Apache-Commons-HTTPClient for the verification request
var pkg = Packages.org.apache.commons.httpclient;
var client = new pkg.HttpClient();
// create a GET request
var authUri = session.data.modSoruaAuthUri;
var ch = (authUri.indexOf("?") != -1) ? "&" : "?";
authUri += ch + "sorua-action=verify";
var returnUrl = this.href("modSoruaUserServer") + "?token=" + req.data.token;
if (req.data.remember) returnUrl += "&remember=" + req.data.remember;
authUri += "&sorua-return-url=" + escape(returnUrl);
var method = new pkg.methods.GetMethod(authUri);
// send the GET request
client.executeMethod(method);
// get the status code
var status = method.getStatusCode();
if (status == 200) { // handle successful authentication
var responseBody = method.getResponseBodyAsString();
if (responseBody && responseBody.substring(0, 5) == "user:") {
var responseLines = responseBody.split("\n");
// fetch userName from response
var userName = responseLines[0].substring(5);
// read additional (optional) user data from response
var userData = new Object();
if (responseLines.length > 1) {
for (var i=0; i<responseLines.length-1; i++) {
var line = responseLines[i+1];
if (line.contains(":") == false) continue;
userData[line.substring(0, line.indexOf(":"))] = line.substring(line.indexOf(":") + 1);
}
}
var authServerName = this.modSoruaUserServerGetNameForAuthUri(session.data.modSoruaAuthUri);
var userId = authServerName + ":" +userName;
if (root.users.get(userId)) {
var msg = this.evalLogin(root.users.get(userId).name, root.users.get(userId).password);
} else {
var newUser = this.modSoruaUserServerNewUser(session.data.modSoruaAuthUri, authServerName, userName);
var msg = this.evalLogin(newUser.name, newUser.password);
}
if (userData.email != null) session.user.email = userData.email; // set 'email:'-value from response
if (userData.url != null) session.user.url = userData.url; // set 'url:'-value from response
res.message = msg;
}
} else if (status == 403) {
;
}
session.data.modSoruaAuthUri = null;
method.releaseConnection();
method.recycle();
// perform redirect
if (session.data.referrer) {
var url = session.data.referrer;
session.data.referrer = null;
} else {
var url = this._parent.href();
}
res.redirect(url);
/**
* Returns the name/id for a given authuri.
* The name is either defined via modSoruaUserServerKnownAuthServers or extracted from the authuri itself
*
* @param authuri String
* @return String
*/
function modSoruaUserServerGetNameForAuthUri(authuri) {
if (!authuri) return;
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
for (var i in knownAuthServers) {
if (authuri == knownAuthServers[i][0]) {
return knownAuthServers[i][1];
}
}
// extract the domain from the authuri
return authuri.substring(authuri.indexOf("/") + 2,
authuri.indexOf("/", authuri.indexOf("/") + 2));
}
/**
* Creates and adds a new User.
*
* @param authUri
* @param authServerName
* @param userName
* @return User
*/
function modSoruaUserServerNewUser(authUri, authServerName, userName) {
var newUser = new User();
newUser.name = authServerName + ":" + userName;
newUser.password = (Math.random()).toString().md5(); // generate random password
newUser.registered = new Date();
root.users.add(newUser);
return newUser;
}
/**
* Renders a list of known AuthServers.
* Either as textarea (as="editor") for the SysMgr.setup
* Or as DropDown, Radiobuttons or Links
*
* @param as String "editor", "dropdown", "radio", "links"
* @return String
*/
function modSoruaUserServerKnownAuthServers_macro(param) {
if (param.as == "dropdown") {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
param.name = "modSoruaAuthServerAuthUri";
Html.dropDown(param, knownAuthServers, null, param.firstOption);
} else if (param.as == "radios") {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
param.name = "modSoruaAuthServerAuthUri";
for (var i in knownAuthServers) {
param.value = knownAuthServers[i][0];
Html.radioButton(param, knownAuthServers, null, param.firstOption);
res.write(" " + knownAuthServers[i][1]);
}
} else if (param.as == "links") {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
param.name = "modSoruaAuthServerAuthUri";
for (var i in knownAuthServers) {
var url = root.members.href("modSoruaUserServer") + "?action=login" +
"&modSoruaAuthServerAuthUri=" + escape(knownAuthServers[i][0]);
Html.link({href: url}, knownAuthServers[i][1]);
}
} else {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
res.write(knownAuthServers.toSource());
}
return;
}
/**
* Returns Array of Array representations of known AuthServers.
* arr[n][0] is the authuri;
* arr[n][1] is the name;
*
* @param str Optional String, if not Root.modSoruaUserServerKnownAuthServers should be parsed
*
* @return Array of Arrays representing AuthServers
*/
function modSoruaUserServerGetArrayOfKnownAuthServers(str) {
var arr = [];
> The Helma code-snippets provided here > http://www.sorua.net/stories/776023/ are just intented for > demonstration purpose, and are not expected to work out-of-the-box. I > attached the adapted UserServer, which hopefully works for > Antville-installations.
> So you probably need the following steps to enable UserServer for > Antville:
> * download the commons-httpclient-3.0-rc2.jar from > http://jakarta.apache.org/site/downloads/downloads_commons-httpclient... > and put it into your code-repository (or to [HelmaDir]/lib/ext)
> * put the attacht file modSoruaUserServer.js into [AntvilleDir]/MemberMgr
> * Adapt function Root.modSoruaUserServerGetArrayOfKnownAuthServers to > define your list of known AuthServers.
> * Include the following lines somewhere into the MemberMgr/login Skin:
> ----------------------
> <tr>
> <td valign="top"><% input id="isusersorua" type="radio" name="isuser" > value="sorua" %></td>
> <td>
> I am registered at another Service with > <b>SORUA</b>-Authentification.<br />
> <% MemberMgr.modSoruaUserServerKnownAuthServers width="100" > as="dropdown" > onChange="document.getElementById('isusersorua').checked='checked'" %>
> </td>
> </tr>
> ----------------------
> * And include the following lines into the MemberMgr/login_action:
> --------------------
> function login_action() {
> ...
> if (req.data.login && req.data.isuser == "sorua") {
> var redUrl = this.href("modSoruaUserServer") + "?submit=1";
> if (req.data.name) redUrl += "&name=" + req.data.name;
> redUrl += "&authuri=" + escape(req.data.modSoruaAuthServerAuthUri);
> if (req.data.remember || req.data.remembersorua) redUrl += > "&remember=1";
> res.redirect(redUrl);
> }else if (req.data.login) {
> ...
> --------------------
* Did you restart Helma? Which Helma-version are you using?
* Can you set debug=true in app.properties and send the full error trace
* Can you trace down the line that particular bug occurs by inserting res.debug-statements into the action/functions. That is necessary for me to be able to tell you what is going wrong.
>> * Did you restart Helma? Which Helma-version are you using?
yes, i did restart it and helma is using both commons extensions. the helmaversion is 1.4.3 on java 1.5.0_02.
>> * Can you set debug=true in app.properties and send the full error trace
yes. here (prefixed with > to prevent linewraps by google groups):
>Error in Script: [object Object] >org.mozilla.javascript.JavaScriptException: anmeldung fehlgeschlagen! hast du dich vertippt? (antville:MemberMgr/objectFunctions.js#12) > at org.mozilla.javascript.gen.c98._c1(antville:MemberMgr/objectFunctions.js:12 ) > at org.mozilla.javascript.gen.c98.call(antville:MemberMgr/objectFunctions.js) > at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1442) > at org.mozilla.javascript.gen.c101._c1(antville:MemberMgr/modSoruaUserServer.j s:49) > at org.mozilla.javascript.gen.c101.call(antville:MemberMgr/modSoruaUserServer. js) > at helma.scripting.rhino.RhinoEngine.invoke(RhinoEngine.java:283) > at helma.framework.core.RequestEvaluator.run(RequestEvaluator.java:346) > at java.lang.Thread.run(Thread.java:595)
i would assume that the error occurs in line 49 of modSoruaUserServer.js which is the following:
> var msg = this.evalLogin(newUser.name, newUser.password); >> * Can you trace down the line that particular bug occurs by inserting res.debug-statements into the action/functions. That is necessary for me to be able to tell you what is going wrong.
just like "res.debug('1');" or something like that? where would those debug messages appear? in the console output? or in the eventlog?
>i would assume that the error occurs in line 49 of
>modSoruaUserServer.js which is the following:
attached you will find a new version of MemberMgr/modSoruaUserServer.js which is hopefully less dependent on the existence/logic of other functions. hopefully it will work out now.
>>* Can you trace down the line that particular bug occurs by inserting res.debug-statements into the action/functions. That is necessary for me to be able to tell you what is going wrong.
>just like "res.debug('1');" or something like that? where would those
>debug messages appear? in the console output? or in the eventlog?
yes, shtg like that. a yellow message would then appear at the end of the response itself. but this is not necessary, since the error trace had all the necessary information.
/**
* SORUA UserServer
* Handles submitted login form, which performs redirect to AuthServer for authentication.
* Handles returned UserClient and asks AuthServer for verification.
*
*/
function modSoruaUserServer_action() {
// UserClient is returned by AuthServer
if (req.data.token && session.data.modSoruaAuthUri) {
// use the Apache-Commons-HTTPClient for the verification request
var pkg = Packages.org.apache.commons.httpclient;
var client = new pkg.HttpClient();
// create a GET request
var authUri = session.data.modSoruaAuthUri;
var ch = (authUri.indexOf("?") != -1) ? "&" : "?";
authUri += ch + "sorua-action=verify";
var returnUrl = this.href("modSoruaUserServer") + "?token=" + req.data.token;
if (req.data.remember) returnUrl += "&remember=" + req.data.remember;
authUri += "&sorua-return-url=" + escape(returnUrl);
var method = new pkg.methods.GetMethod(authUri);
// send the GET request
client.executeMethod(method);
// get the status code
var status = method.getStatusCode();
if (status == 200) { // handle successful authentication
var responseBody = method.getResponseBodyAsString();
if (responseBody && responseBody.substring(0, 5) == "user:") {
var responseLines = responseBody.split("\n");
// fetch userName from response
var userName = responseLines[0].substring(5);
// read additional (optional) user data from response
var userData = new Object();
if (responseLines.length > 1) {
for (var i=0; i<responseLines.length-1; i++) {
var line = responseLines[i+1];
if (line.contains(":") == false) continue;
userData[line.substring(0, line.indexOf(":"))] = line.substring(line.indexOf(":") + 1);
}
}
var authServerName = this.modSoruaUserServerGetNameForAuthUri(session.data.modSoruaAuthUri);
var userId = authServerName + ":" +userName;
var usr = root.users.get(userId);
if (!usr) {
var usr = this.modSoruaUserServerNewUser(session.data.modSoruaAuthUri, authServerName, userName);
}
session.login(usr);
session.user.lastVisit = new Date();
if (req.data.remember) {
res.setCookie("avUsr", session.user.name, 365);
res.setCookie("avPw", Packages.helma.util.MD5Encoder.encode(session.user.password+req.data.http_r emotehost), 365);
}
if (userData.email != null) session.user.email = userData.email; // set 'email:'-value from response
if (userData.url != null) session.user.url = userData.url; // set 'url:'-value from response
res.message = new Message("welcome", [res.handlers.context.getTitle(), session.user.name]);
}
} else if (status == 403) {
;
}
session.data.modSoruaAuthUri = null;
method.releaseConnection();
method.recycle();
// perform redirect
if (session.data.referrer) {
var url = session.data.referrer;
session.data.referrer = null;
} else {
var url = this._parent.href();
}
res.redirect(url);
/**
* Returns the name/id for a given authuri.
* The name is either defined via modSoruaUserServerKnownAuthServers or extracted from the authuri itself
*
* @param authuri String
* @return String
*/
function modSoruaUserServerGetNameForAuthUri(authuri) {
if (!authuri) return;
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
for (var i in knownAuthServers) {
if (authuri == knownAuthServers[i][0]) {
return knownAuthServers[i][1];
}
}
// extract the domain from the authuri
return authuri.substring(authuri.indexOf("/") + 2,
authuri.indexOf("/", authuri.indexOf("/") + 2));
}
/**
* Creates and adds a new User.
*
* @param authUri
* @param authServerName
* @param userName
* @return User
*/
function modSoruaUserServerNewUser(authUri, authServerName, userName) {
var newUser = new User();
newUser.name = authServerName + ":" + userName;
newUser.password = (Math.random()).toString().md5(); // generate random password
newUser.registered = new Date();
root.users.add(newUser);
return newUser;
}
/**
* Renders a list of known AuthServers.
* Either as textarea (as="editor") for the SysMgr.setup
* Or as DropDown, Radiobuttons or Links
*
* @param as String "editor", "dropdown", "radio", "links"
* @return String
*/
function modSoruaUserServerKnownAuthServers_macro(param) {
if (param.as == "dropdown") {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
param.name = "modSoruaAuthServerAuthUri";
Html.dropDown(param, knownAuthServers, null, param.firstOption);
} else if (param.as == "radios") {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
param.name = "modSoruaAuthServerAuthUri";
for (var i in knownAuthServers) {
param.value = knownAuthServers[i][0];
Html.radioButton(param, knownAuthServers, null, param.firstOption);
res.write(" " + knownAuthServers[i][1]);
}
} else if (param.as == "links") {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
param.name = "modSoruaAuthServerAuthUri";
for (var i in knownAuthServers) {
var url = root.members.href("modSoruaUserServer") + "?action=login" +
"&modSoruaAuthServerAuthUri=" + escape(knownAuthServers[i][0]);
Html.link({href: url}, knownAuthServers[i][1]);
}
} else {
var knownAuthServers = this.modSoruaUserServerGetArrayOfKnownAuthServers();
res.write(knownAuthServers.toSource());
}
return;
}
/**
* Returns Array of Array representations of known AuthServers.
* arr[n][0] is the authuri;
* arr[n][1] is the name;
*
* @param str Optional String, if not Root.modSoruaUserServerKnownAuthServers should be parsed
*
* @return Array of Arrays representing AuthServers
*/
function modSoruaUserServerGetArrayOfKnownAuthServers(str) {
var arr = [];
> attached you will find a new version of MemberMgr/modSoruaUserServer.js
> which is hopefully less dependent on the existence/logic of other
> functions. hopefully it will work out now.
yes! i just tested it and it works fine! thanks!
> yes, shtg like that. a yellow message would then appear at the end of
> the response itself. but this is not necessary, since the error trace
> had all the necessary information.
ah.. that would have been kinda not helpful then, since the response
was not really shown to the user.. the client got just redirected to
another page.