1. Customize webscripts-framework-config.xml (Alfresco <>or share-config-custom (Alfresco 3.2 >)
1.1. Define an Authenticator
<authenticator>
<id>alfresco-custom-ticket</id>
<name>Alfresco Authenticator</name>
<description>Alfresco Authenticator</description>
<class>com.westernacher.wps.share.authenticate.customAuthenticator</class>
</authenticator>
Where the customAuthenticator Class encloses the logic of our customized authentication.
Its however important to remind that in alfresco 3.2 > the classes for the connector were mostly ported to the spring framework package.<connector><id>external-alfresco</id><name>Simple Http Connector</name><description>Simple Alfresco - HTTP Connector</description><class>org.alfresco.connector.AlfrescoConnector</class><authenticator-id>alfresco-custom-ticket</authenticator-id>
</connector>
example:
the class org.alfresco.connector.AlfrescoConnector should be replaced with org.springframework.extensions.webscripts.connector.AlfrescoConnector in alfresco 3.2 and more.
1.3. Define the endpoint
<endpoint>
<id>my-custom-end-point</id>
<name>Custom Endpoint</name>
<description>System account access to Alfresco</description>
<connector-id>http</connector-id>
<endpoint-url>url-tha-prefixes-the-scripts-to-be-called</endpoint-url>
<unsecure>true</unsecure>
</endpoint>
In alfresco by example the end point URL is standardly known as : http://localhost:8080/alfresco/s
1.4. Implement our CustomAuthenticator class
public class CustomAuthenticator extends AbstractAuthenticator {
public final staticStringCS_PARAM_ALF_TICKET= "alfTicket";
private staticLoglogger = LogFactory.getLog(CustomAuthenticator.class);
@Override
public ConnectorSession authenticate(String endpoint, Credentials credentials, ConnectorSession connectorSession) throws AuthenticationException {
ConnectorSession cs = null;
if (credentials != null) {
//get a valid ticket from Alfresco via a standard or custom method
finalStringurl = endpoint + "/getTicket";
GetMethodget = new GetMethod(url);
// username and coockie
StringaCoockie = (String) credentials.getProperty(Credentials.CREDENTIAL_PASSWORD);
get.setRequestHeader("Cookie", aCoockie);
HttpClientclient = new HttpClient();
try {
intres = client.executeMethod(get);
// read back the ticket
if (res == 200) {
Stringticket;
try {
ticket = get.getResponseBodyAsString();
} catch (Throwableerr) {
logger.error("Error to obtain ticket for custom authorization", err);
// the ticket that came back could not be parsed
// this will cause the entire handshake to fail
throw newAuthenticationException("Unable to retrieve login ticket from Alfresco");
}
if (logger.isDebugEnabled()) {
logger.debug("Parsed ticket:" + ticket);
}
// place the ticket back into the connector session
if (connectorSession != null) {
connectorSession.setParameter(CS_PARAM_ALF_TICKET, ticket);
// signal that this succeeded
cs = connectorSession;
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Authentication failed, received response code: " + res);
}
}
} catch (Throwablee) {
logger.error("Error to authenticate by custom Authentication", e);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Authentication failed, no credentials provided");
}
}
return cs;
}
@Override
publicbooleanisAuthenticated(String endpoint, ConnectorSession connectorSession) {
return (connectorSession.getParameter(CS_PARAM_ALF_TICKET) != null);
}
}