'401 Unauthorized' when accessing to webscript from indicator in Alfresco Share
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2013 05:42 PM
import org.alfresco.web.evaluator.BaseEvaluator;import org.json.simple.JSONObject;import org.springframework.extensions.surf.ServletUtil;import org.springframework.extensions.surf.exception.ConnectorServiceException;import org.springframework.extensions.surf.support.ThreadLocalRequestContext;import org.springframework.extensions.webscripts.connector.Connector;public class CustomEvaluator extends BaseEvaluator{ @Override public boolean evaluate(JSONObject node) { try { Connector conn = ThreadLocalRequestContext.getRequestContext().getServiceRegistry().getConnectorService().getConnector("alfresco"); return conn.call("/some/webscript/run?nodeRef=" + (String) node.get("nodeRef")).getResponse().equals("YES"); } catch (ConnectorServiceException ex) { return false; } }}
However, when the evaluator gets executed, Alfresco returns a 401 Unauthorized HTTP response status code every time.
Other observations:
<ul>
<li>If I try to access the webscript directly from the browser (since it's a simple GET method), it works fine.
<li>If I access the webscript as a Share document library action, it works fine.
<li>In the last two observations, cookies are sent in the HTTP request (JSESSION, something starting with "alf", some PHP-specific). In the evaluator one, no cookies are sent.
</ul>
So, the problem must be in the way I'm trying to access it from an evaluator.
Is there any way to include the authentication information of the current session using the Connector Service to access webscripts which require authentication?
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013 07:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013 07:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013 09:44 AM
I tried to get the Alfresco ticket of the current session, but to no avail. Is there a way to get it without asking users to type their credentials again?
Below are some snippets of my current code. The evaluator is being executed, but it keeps giving the 401 status code. All of them are deployed in Share using a JAR file.
alfresco/web-extension/evaluator-context.xml
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'><beans> <!– No problems with this one –> <bean id="evaluator.doclib.action.isPdf" parent="evaluator.doclib.action.isMimetype"> <property name="mimetypes"> <list> <value>application/pdf</value> </list> </property> </bean> <!– This is the problematic one –> <bean id="evaluator.doclib.action.isItReady" class="some.internal.package.CustomEvaluator" /></beans>
alfresco/web-extension/share-config-custom.xml
<alfresco-config> … <config evaluator="string-compare" condition="DocumentLibrary" replace="true"> … <indicators> <indicator id="indicator.doclib.action.isItReady" icon="myicon-16.png" index="100" label="Yea!"> <evaluator>evaluator.doclib.action.isItReady</evaluator> </indicator> </indicators> </config></alfresco-config>
This one <em>is</em> deployed in Alfresco: the webscript I'm trying to contact from the evaluator in Share. I'll include just the webscript descriptor, since the authentication configuration is there.
alfresco/extension/templates/webscipts/some/folder
<webscript> <shortname>Some name</shortname> <description>Some description</description> <url>/some/folder/isItReady</url> <authentication>user</authentication> <format default="json">argument</format> <family>Custom</family></webscript>
The authentication=user is needed. It won't do if it's changed to "none" or "guest".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013 06:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2013 05:29 PM
I enabled a webscript in Alfresco which does this and it works, but still requires "user" authentication, which takes me back to square one.
I tried to get it from some objects in Share, but to no avail.
Is there any other way to get the current session's ticket in Share from a Java evaluator?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2013 01:23 PM
Use the following code snippet for Authentication.
<java>
import org.springframework.extensions.surf.ServletUtil;
Connector conn = ThreadLocalRequestContext.getRequestContext().getServiceRegistry().getConnectorService().getConnector("alfresco", ServletUtil.getSession());
</java>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2013 05:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2013 05:39 PM
Request made by the evaluator through the "alfresco" connector in Share:
GET /alfresco/s/some/folder/isItReady?nodeRef=workspace://SpacesStore/2d4e61ab-8508-4f7f-834c-1f49170d096c HTTP/1.1User-Agent: Jakarta Commons-HttpClient/3.1Host: localhost:8080
The response from Alfresco:
HTTP/1.1 401 UnauthorizedServer: Apache-Coyote/1.1WWW-Authenticate: Basic realm="Alfresco"Content-Type: text/html;charset=utf-8Content-Length: 951Date: Thu, 14 Nov 2013 22:23:54 GMT(Some HTML…)This request requires HTTP authentication.(Some more HTML…)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2013 10:13 AM
Can you tell me what are you doing in /folder/isItReady Webscript??
