简体   繁体   中英

How to Add Authentication to JSP Page on Alfresco Share

So for the project I'm currently working on, prior to taking the Alfresco developers course, we had created a custom JSP page that we call from within the course of our workflow that is located at: C:\\Alfresco\\tomcat\\webapps\\share\\custom . Currently anyone can access this jsp page. However, when we move the location to C:\\Alfresco\\tomcat\\webapps\\alfresco\\jsp\\custom , a log on is always required to acces the page, which seems strange to me. However the issue here is we do not want to allow the user access to both Share and Explorer, thus we are not looking to configure an SSO here. We'd like to only allow people of group “Manager”, or the currently logged in user from the group "Manager" to access this page, while it is located on the share side. We've tried adding the following into the

C:\\Alfresco\\tomcat\\webapps\\share\\WEB-INF\\web.xml file:

<security-constraint>
        <web-resource-collection>
            <web-resource-name>All</web-resource-name>
            <url-pattern>/custom /*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>Manager</role-name>
        </auth-constraint>
    </security-constraint>

But this did not work. Does anyone have a suggestion as to how we might get the desired authentication?

Thanks

Authentication in Share is controlled by the Surf framework, and specifically it is set at the page level.

The JSP page site-index.jsp provides an example JSP-based page which processes authenticated users for you to copy, but you must also wire it in to the framework.

To do this, you'll need to create a page definition similar to the following

<?xml version='1.0' encoding='UTF-8'?>
<page>
   <title>My page</title>
   <description>What the page is for</description>
   <template-instance>my-page</template-instance>
   <authentication>user</authentication>
</page>

Add this file under WEB-INF/classes/alfresco/site-data/pages/site-index.xml .

You'll see that the page references a template instance my-page , which must be declared in a second XML file under WEB-INF/classes/alfresco/site-data/template-instances , eg

<?xml version='1.0' encoding='UTF-8'?>
<template-instance>
   <template-type>my-page</template-type>
</template-instance>

The name of the template-instance XML file (without the .xml suffix) must match the name specified in the page's <template-instance> property.

Lastly create a template type file my-page.xml (this name must match the <template-type> property in the template instance file) under WEB-INF/classes/alfresco/site-data/template-types , eg

<?xml version="1.0" encoding="UTF-8"?>
<template-type>
        <title>Site index landing page template type</title>
        <description>Site index landing page JSP Template Type</description>

        <!-- Define the rendering processors for this template type -->
        <processor mode="view">
                <id>jsp</id>
                <jsp-path>/my-page.jsp</jsp-path>
        </processor>

</template-type>

The file my-page.jsp will contain your JSP code. As I mention look at the core file site-index.jsp for an example.

When you have all of this working you should package up your customisations in an AMP file. You can use either Ant or Maven to do this depending on your preference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM