AnsweredAssumed Answered

AbstractWebscript cannot redirect without prompting

Question asked by akring on Nov 23, 2015
Hi,

I working on an amp which implements the following behaviour:

<ol>
<li>An already logged in user clicks a custom (folder-browse) action on a folder in the document library for a given site</li>
<li>This will take him to a third party server where he receives an OAuth2 token</li>
<li>This OAuth2 token is given back to Alfresco by having the third party server call back to an share page using an URL like this: http://example.org:8081/share/page/callback-page?nodeRef=...#token=…</li>
<li>The share page then calls an AbstractWebscript using a url like this: http://example.org:8081/share/proxy/alfresco/store-token?token=…</li>
<li>The token is then stored by the AbstractWebscript</li>
<li>The AbstractWebscript should then redirect the user to a page on the share side</li>
</ol>

But the user is presented with the standard share login prompt (even though he was already logged in before the first step in the list above), before the redirect takes place?

And if I comment out the two redirect lines in the Java class below and replace them with the line

resp.getWriter().write("test");


then the word "test" is written fine in the browser without any Alfresco login prompts?

The webscript looks something like this:


public class StoreOAuth2Token extends AbstractWebScript {

   OAuth2CredentialsStoreService oAuth2CredentialsStoreService;
   
   @Override
   public void execute(WebScriptRequest req, WebScriptResponse resp) throws IOException {

                … code to store token and other details …

                        
      // resp.getWriter().write("test");
      
      resp.setStatus(302);
      resp.setHeader("Location", "http://example.org:8081/share/page/hdp/ws/sbsys-case-search?nodeRef=" + URLEncoder.encode(nodeRefStr, "UTF-8") + "&finalRedirect=" + URLEncoder.encode(finalRedirect, "UTF-8") + "&fragment=" + URLEncoder.encode(fragment, "UTF-8"));
      
   }
   
   public void setoAuth2CredentialsStoreService(OAuth2CredentialsStoreService oAuth2CredentialsStoreService) {
      this.oAuth2CredentialsStoreService = oAuth2CredentialsStoreService;
    }
}


Any ideas on how to fix this?

Regards
Andreas

Outcomes