Screen link and anonymous access

I have created a simple screen with just 1 textfield.

I want to call this screen anonymously from an external application with a screen link.

I created an “Anonymous” role and assigned this role to the “Anonymous” user and gave access to just this specific screen. Unfortunately I am still required to login.

What am I missing?

Hi Torben,

At the moment, you can use LinkHandler to open custom Windows in anonymous mode only if you extend it. In order to show custom window for anonymous by a screen link you can do the following:

  1. Add your custom action name to cuba.web.linkHandlerActions property in web-app.properties file:
cuba.web.linkHandlerActions = open|o|demo

We will use http://localhost:8080/app/demo URL to show custom main window.

  1. Extend LinkHandler class and override handle (and canHandleLink, if needed) methods
public class DemoLinkHandler extends LinkHandler {
    public DemoLinkHandler(App app, String action, Map<String, String> requestParams) {
        super(app, action, requestParams);
    }

    @Override
    public boolean canHandleLink() {
        if ("demo".equals(action)) {
            return true;
        }

        return super.canHandleLink();
    }

    @Override
    public void handle() {
        if ("demo".equals(action)) {
            try {
                // open custom main window
                app.navigateTo("demo-screen");
            } finally {
                VaadinRequest request = VaadinService.getCurrentRequest();
                WrappedSession wrappedSession = request.getWrappedSession();
                wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
                wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
            }
        } else {
            super.handle();
        }
    }
}
  1. Create a custom window based on Blank Screen template and change the base class of it to AbstractMainWindow
public class DemoScreen extends AbstractMainWindow {

}
  1. Let’s show a simple table with users as the content of this demo window (I’ve created it in Studio Screen Designer):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://caption"
        class="com.company.demo.web.screens.DemoScreen"
        messagesPack="com.company.demo.web.screens">

    <dsContext>
        <collectionDatasource id="usersDs"
                              class="com.haulmont.cuba.security.entity.User"
                              view="user.browse">
            <query>
                select u from sec$User u
            </query>
        </collectionDatasource>
    </dsContext>

    <layout spacing="true"
            expand="table"
            margin="true">
        <label stylename="h1"
               value="Demo Screen"/>

        <table id="table" width="100%">
            <columns>
                <column id="active"/>
                <column id="login"/>
                <column id="name"/>
                <column id="position"/>
            </columns>
            <rows datasource="usersDs"/>
        </table>
    </layout>
</window>
  1. Register your custom LinkHandler implementation in web-spring.xml file:
<bean id="cuba_LinkHandler"
          class="com.company.demo.web.DemoLinkHandler"
          scope="prototype"/>

If we restart the application and open http://localhost:8080/app/demo URL and login then application will show us custom main window instead of default.

Moreover, we can navigate to this screen from our application screens using the same approach:

App.getInstance().navigateTo("demo-screen");

Using this approach you will be able to create screens visually using CUBA Studio and use all the features of CUBA: entities, services, etc.

Please note, that if you embed this page to a client faced web site - web browsers will download all the web resources required for web application including widget set with size of 1+ MB (it will be cached, but usually it is not suitable for public web sites). If you want to embed your application to public facing portal I’d recommend that you have a look at portal module where you will be able to use traditional Spring Web MVC approach to generate web pages.

Also, there is one known drawback - standard main / login window will be initialized before your custom window.

Complete demo code is located here: GitHub - cuba-labs/embeddable-screen-link

2 Likes

Perfect - It just works !

Thanks for the very detailed explanation. It will be used on the intranet, so I don’t expect problems with the size of the widget set.