cancel
Showing results for 
Search instead for 
Did you mean: 

Share webscript redirect to Login Page if not authenticated in Alfresco 5.0.2

kavilash23
Champ on-the-rise
Champ on-the-rise
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.

1 REPLY 1

muralidharand
Star Contributor
Star Contributor
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.

C:\Alfresco5\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\blog\blog-post.get.js

if (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