cancel
Showing results for 
Search instead for 
Did you mean: 

Change the landing page from site-index.jsp to landing-page.jsp

giasqui
Champ on-the-rise
Champ on-the-rise

Hi, I did the following steps.

 

C:\DATI\Macro\Java\projects-test\eclipse\alfresco>mvn archetype:generate -Dfilter=org.alfresco:

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 2

21: 4.8.0

...

Choose a number: 31: 21 

[INFO] Using property: version = 1.0-SNAPSHOT

 Define value for property 'groupId': it.puglia

 Define value for property 'artifactId': landing-page-and-url-injection

 Define value for property 'package' it.puglia: : it.puglia

Y: y

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time:  09:54 min

[INFO] Finished at: 2025-08-06T12:39:26 02:00

[INFO] ------------------------------------------------------------------------

 

C:\DATI\Macro\Java\projects-test\eclipse\alfresco>cd landing-page-and-url-injection

  • run.bat build_start for Windows.

 

 

A docker environment will be created and available at the following links:

http://localhost:8080/alfresco/

http://localhost:8180/share

No we can import the SDK on IDE.

Untitled.png

Now following these topics:

https://docs.alfresco.com/content-services/latest/tutorial/share/pages/#adding-a-new-surf-page-to-sh...

https://docs.alfresco.com/content-services/latest/tutorial/share/pages/#making-the-new-page-the-defa...

I have implemented a solution with a landing page different from the default one that is tomcat/webapps/share/site-index.jsp.

Here the details:

 

 

/src/main/resources/alfresco/web-extension/site-data/pages/landing-page.xml

 

<?xml version='1.0' encoding='UTF-8'?>

<page>

   <title>Welcome</title>

   <title-id>page.siteIndex.title</title-id>

   <description>Landing page for all users - will forward to user site dashboard</description>

   <description-id>page.siteIndex.description</description-id>

   <template-instance>landing-page</template-instance>

   <authentication>user</authentication>

</page>

 

 

/src/main/resources/alfresco/web-extension/site-data/template-instances/landing-page.xml

 

<?xml version='1.0' encoding='UTF-8'?>

<template-instance>

   <template-type>landing-page</template-type>

</template-instance>

 

 

/src/main/resources/alfresco/web-extension/site-data/template-types/landing-page.xml

 

<?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>/landing-page.jsp</jsp-path>

                </processor>

 

</template-type>

 

 

/src/main/resources/alfresco/web-extension/site-data/configurations/slingshot.site.configuration.xml

 

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

   <name>Slingshot Project</name>

   <description>Slingshot Project</description>

   <source-id>site</source-id>

   <properties>

      <theme>lightTheme</theme>

      <root-page>landing-page</root-page>

   </properties>

</configuration>

 

 

/src/main/webapp/jsp/landing-page.jsp

 

<%--

 

    Copyright 2005 - 2020 Alfresco Software Limited.

 

    This file is part of the Alfresco software.

    If the software was purchased under a paid Alfresco license, the terms of the paid license agreement will prevail.

    Otherwise, the software is provided under the following open source license terms:

 

    Alfresco is free software: you can redistribute it and/or modify

    it under the terms of the GNU Lesser General Public License as published by

    the Free Software Foundation, either version 3 of the License, or

    (at your option) any later version.

 

    Alfresco is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    GNU Lesser General Public License for more details.

 

    You should have received a copy of the GNU Lesser General Public License

    along with Alfresco. If not, see <http://www.gnu.org/licenses/>.

 

--%>

<%@ page import="org.alfresco.web.site.*" %>

<%@ page import="org.springframework.extensions.surf.*" %>

<%@ page import="org.springframework.extensions.surf.site.*" %>

<%@ page import="org.springframework.extensions.surf.util.*" %>

<%@ page import="java.util.*" %>

<%@ page import="java.util.regex.*" %>

<%@ page import="org.apache.http.client.methods.HttpGet" %>

<%@ page import="org.apache.http.impl.client.CloseableHttpClient" %>

<%@ page import="org.apache.http.impl.client.HttpClients" %>

<%@ page import="org.apache.http.util.EntityUtils" %>

<%

        // retrieve userId and context

        String userid = (String)session.getAttribute(SlingshotUserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);

        RequestContext context = (RequestContext)request.getAttribute(RequestContext.ATTR_REQUEST_CONTEXT);

 

        // no user dashboard page found! create initial dashboard for this user

        if (!context.getObjectService().hasPage("user/" + userid + "/dashboard")){

 

                Map<String, String> tokens = new HashMap<String, String>();

                tokens.put("userid", userid);

                FrameworkUtil.getServiceRegistry().getPresetsManager().constructPreset("user-dashboard", tokens);

        }

 

        // API call to retrieve sites

        String siteApiUrl = request.getScheme() + "://" +

                request.getServerName() +

                ":" + request.getServerPort() +

                request.getContextPath() +

                "/proxy/alfresco/api/people/" + URLEncoder.encode(userid) + "/sites";

 

        String siteApiUrlResponse = "";

 

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {

 

                HttpGet requestSites = new HttpGet(siteApiUrl);

                String jsessionid = session.getId();

 

                requestSites.setHeader("Cookie", "JSESSIONID=" + jsessionid);

                siteApiUrlResponse = EntityUtils.toString(httpClient.execute(requestSites).getEntity());

 

                System.out.println("Response JSON: " + siteApiUrlResponse);

        } catch (Exception e) {

                System.out.println("Error: " + e.getMessage());

        }

 

 

        Pattern pattern = Pattern.compile("\\\"shortName\\\"[ ]*:[ ]*\\\"([a-zA-Z0-9_-]+)\\\"");

        Matcher matcher = pattern.matcher(siteApiUrlResponse);

        List<String> sites = new ArrayList<>();

 

        while (matcher.find()) {

                sites.add(matcher.group(1));

        }

 

        System.out.println("Site available for user: " + sites);

 

 

        // if size sites == 1 redirect su http://localhost:8180/share/page/site/edottosgd/documentlibrary

        if(sites.size() == 1){

                // forward to demo site dashboard

                String siteName = sites.get(0);

                String target = request.getContextPath() + "/page/site/" + URLEncoder.encode(siteName) + "/documentlibrary";

                response.sendRedirect(target);

        } else {

                // if size sites > 1 redirect su http://localhost:8180/share/page/user/admin/user-sites

                String target = request.getContextPath() + "/page/user/user-sites";

                response.sendRedirect(target);

        }

 

%>

 

Rebuild the package and test the solution.

C:\DATI\Macro\Java\projects-test\eclipse\alfresco\landing-page-and-url-injection>run.bat build_start

 Please notice that the landing-page.jsp deploy is done manually in tomcat/webapps/share. 

Testing the solution, after the login the user will be redirected to the document library of the site where he is a member.

If the user is a member of more than one site than he will be redirected to the the page of all sites.

The dashboard will not be anymore the redirect page after login.

 

Up to now anything works on docker.

If I build the packages repo and share and deploy the amps on a standalone environment using the apply_amps.sh and after a tomcat restart the package will be available in the Module Deployment page:

Capture.JPG

But if I try the login I will be always redirect to the dashboard. So, the redirect to landing-page.jsp does not work.

In few words the solution works on docker but doesn't works on standalone env. 

May you please help?

Thanks.

Kind regards.

0 REPLIES 0