Rohan Bhatte
Rohan Bhatte

Reputation: 95

Alfresco with custom authentication webservice

We have a custom authentication service which accepts a parameter over a REST service and provides a json response. Based on the response we redirect the user. I wish to integrate this webservice with our new Alfresco Box.

Is there a way to do custom base authentication instead of using LDAP or inbuilt SSO plugin?

Upvotes: 1

Views: 299

Answers (1)

kinjelom
kinjelom

Reputation: 6450

If I understood correctly...

  1. Implement your custom remote user mapper:

    package best.package.ever;
    import org.alfresco.repo.security.authentication.external.DefaultRemoteUserMapper;
    
    public class CustomRemoteUserMapper extends DefaultRemoteUserMapper {
        public boolean canHandle(HttpServletRequest request) {
            return true; // TODO
        }   
        public String getTrustedUserId(HttpServletRequest request) {
            // TODO: validate & authorize... e.g. based on trusted Json Web Token
            return "trusted.user.id"; // TODO
        }
        public String getRemoteUser(HttpServletRequest request) {
            if (canHandle(request)) {
                return getTrustedUserId(request);
            } else {
                return super.getRemoteUser(request);
            }
        }
    }
    
  2. Put your library best-package-ever.jar into tomcat\webapps\alfresco\WEB-INF\lib

  3. Declare your custom bean and inject it into RemoteUserMapper bean: tomcat\shared\classes\alfresco\extension\authentication-custom-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> 
        <bean id="customRemoteUserMapper" class="best.package.ever.CustomRemoteUserMapper">
            <property name="personService" ref="PersonService"/>
            <property name="authorityService" ref="AuthorityService" />
        </bean>
        <bean id="RemoteUserMapper" class="org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory">
            <property name="applicationContextManager">
                <ref bean="Authentication" />
            </property>
            <property name="interfaces">
                <list>
                    <value>org.alfresco.repo.security.authentication.external.RemoteUserMapper</value>
                    <value>org.alfresco.repo.management.subsystems.ActivateableBean</value>
                </list>
            </property>
            <property name="sourceBeanName">
                <value>customRemoteUserMapper</value> <!-- extending remoteUserMapper -->
            </property>
        </bean>
    </beans>
    

Upvotes: 1

Related Questions