Share webscript redirect to Login Page if not authenticated in Alfresco 5.0.2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2015 02:03 AM
Hi Guys,
I have a Share webscript (/service/details/{dId}) which when called in turn makes a call to a Repository webscript. If the repo webscript returns a status 401 (which is returned when a user is not authenticated in alfresco) redirects the user to the share login page. See my code snippet below. While this code works in alfresco 4.2.x, the redirect to the share login page is not working. I just get the surf error "The Web Script /share/page/service/details/xxxx has responded with a status of 500 - Internal Error.
var webscript = "/seed/noderef/" + docId;
var connector = remote.connect("alfresco");
var result = connector.get(webscript);
if (result.status == 401) {
// if fail to login to alfresco
// should redirect to login page and retry
redirectUrl = url.context + "/page?alfRedirectUrl=" + url.full;
//redirectUrl = "http://192.168.0.8:8080/share/page/type/login"
payLoad["redirectUrl"] = redirectUrl;
model.output = packageInResponseJSON(false, status.code, "Redirecting to login page", payLoad);
// redirect
status.code = 307;
status.location = redirectUrl;
return;
}
Any advice much appreciated.
I have a Share webscript (/service/details/{dId}) which when called in turn makes a call to a Repository webscript. If the repo webscript returns a status 401 (which is returned when a user is not authenticated in alfresco) redirects the user to the share login page. See my code snippet below. While this code works in alfresco 4.2.x, the redirect to the share login page is not working. I just get the surf error "The Web Script /share/page/service/details/xxxx has responded with a status of 500 - Internal Error.
var webscript = "/seed/noderef/" + docId;
var connector = remote.connect("alfresco");
var result = connector.get(webscript);
if (result.status == 401) {
// if fail to login to alfresco
// should redirect to login page and retry
redirectUrl = url.context + "/page?alfRedirectUrl=" + url.full;
//redirectUrl = "http://192.168.0.8:8080/share/page/type/login"
payLoad["redirectUrl"] = redirectUrl;
model.output = packageInResponseJSON(false, status.code, "Redirecting to login page", payLoad);
// redirect
status.code = 307;
status.location = redirectUrl;
return;
}
Any advice much appreciated.
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2016 11:51 AM
I believe, you need to set status.redirect = true;
Take a look at the below webscript.
When the response status is not 200 (not OK), webscript is redirecting the users.
Take a look at the below webscript.
When the response status is not 200 (not OK), webscript is redirecting the users.
C:\Alfresco5\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\blog\blog-post.get.jsif (result.status.code == status.STATUS_OK) { // Strip out possible malicious code var post = JSON.parse(result.response); if (post && post.item && post.item.content) { post.item.content = stringUtils.stripUnsafeHTML(post.item.content); } return jsonUtils.toJSONString(post); } else { status.code = result.status.code; status.message = msg.get("message.failure"); status.redirect = true; }//Another one.C:\Alfresco5\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\wiki\page.get.js
