What is the best practice for allowing anonymous access to one screen.
In this case it will be a form.
When the user clicks ok, they should not be brought back to browse.
Hello @tommeacham
We are working on anonymous access now (GitHub) that will enable to combine public pages with new URL routing feature.
Now you can solve the task with LinkHandler mechanism:
- Add custom address with
cuba.web.linkHandlerActions
app property inweb-app.properties
file:
cuba.web.linkHandlerActions = open|o|form
It will enable us to open our screen by a link: /form?show
.
The ?show
param is required to enable LinkHandler mechanism.
- Extend
LinkHandler
and overridecanHandleLink
andhandle
methods:
public class FormLinkHandler extends LinkHandler {
public FormLinkHandler(App app, String action, Map<String, String> requestParams) {
super(app, action, requestParams);
}
@Override
public boolean canHandleLink() {
return "form".equals(action) || super.canHandleLink();
}
@Override
public void handle() {
if ("form".equals(action)) {
// open custom main window
App.getInstance().navigateTo("form-demo");
action = null;
requestParams.clear();
WrappedSession wrappedSession = VaadinSession.getCurrent().getSession();
wrappedSession.removeAttribute(LAST_REQUEST_PARAMS_ATTR);
} else {
super.handle();
}
}
}
- Create custom main window with a form:
public class FormDemo extends AbstractMainWindow {
@Override
public void init(Map<String, Object> params) {
super.init(params);
showNotification("Show form page!");
}
}
- Register custom
LinkHandler
inweb-spring.xml
:
<bean id="cuba_LinkHandler"
class="com.company.demo.web.FormLinkHandler"
scope="prototype"/>
And now we are able to open custom screen with form by link: http://localhost:8080/app/form?show.
Example code can be found on GitHub: link.
Regards,
Daniil
1 Like
Iām going to dive into this and check it out. Thanks for all the hard work you do.