Anonymous Login after 6.5 to 6.10 upgrade

I’ve searched the forum for duplicates, but there are none that come to a useful conclusion.

I am running into a issue when upgrading a Cuba app from 6.5.x to 6.10.x:

We used to have an App.java that extended com.haulmont.cuba.web.DefaultApp class and did an @Override on the loadOnStartup() method as follows:

package com.mycompany.web;

import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.UserSessionSource;
import com.haulmont.cuba.security.global.LoginException;
import com.haulmont.cuba.web.DefaultApp;
import com.haulmont.charts.web.gui.ChartComponentPalette;
import com.haulmont.cuba.web.auth.ExternallyAuthenticatedConnection;
import com.haulmont.cuba.web.gui.WebUIPaletteManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.Locale;

public class App extends DefaultApp {
    @Inject
    protected Messages messages;

    private Logger log = LoggerFactory.getLogger(App.class);
    @Override
    protected boolean loginOnStart() {
        if (tryLoginOnStart &&
                principal != null
                && webAuthConfig.getExternalAuthentication()) {

            int slashPos = principal.getName().indexOf('\\');
            slashPos++;
            String userName = principal.getName().substring(slashPos /* domain name length plus 1 */);
            log.debug("Trying to login after external authentication as " + userName);
            try {
                Locale locale = messages.getTools().getDefaultLocale();
                ((ExternallyAuthenticatedConnection) connection).loginAfterExternalAuthentication(userName, locale);

                return true;
            } catch (LoginException e) {
                log.trace("Unable to login on start", e);
            } finally {
                tryLoginOnStart = false;
            }
        }
        return false;
    }
}

But the variables tryLoginOnStart and principal, which were in the extended classes are no longer available. How do I accomplish the equivalent functionality in the Cuba 6.8+, particularly 6.10?

I’ve commented out the spring configuration for this bean to remove it from the equasion to see if the app would just work, and I get this exception when trying to reach the login screen (which gives the hourglass spinner and then just dies with a “Retry” button:

java.lang.RuntimeException: Unable to login as anonymous!
	at com.haulmont.cuba.web.DefaultApp.loginOnStart(DefaultApp.java:218) ~[cuba-web-6.10.11.jar:6.10.11]


The full stack trace is:

2019-07-24 10:16:32.061 DEBUG [http-nio-9080-exec-6] com.haulmont.cuba.web.App - Initializing application
2019-07-24 10:16:32.064 DEBUG [http-nio-9080-exec-6] com.haulmont.cuba.web.security.listeners.LegacyLoginEventsForwarder - Trying to login after external authentication as mydomain\myuser
2019-07-24 10:16:32.068 INFO  [http-nio-9080-exec-6] com.haulmont.cuba.core.sys.remoting.ClusteredHttpInvokerRequestExecutor - Invocation of http://localhost:9080/app-core/remoting/cuba_AuthenticationService failed: java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [null]
2019-07-24 10:16:32.068 INFO  [http-nio-9080-exec-6] com.haulmont.cuba.core.sys.remoting.ClusteredHttpInvokerRequestExecutor - No more URL available
2019-07-24 10:16:32.069 DEBUG [http-nio-9080-exec-6] com.haulmont.cuba.web.security.WebAnonymousSessionHolder - Loading anonymous session
2019-07-24 10:16:32.070 INFO  [http-nio-9080-exec-6] com.haulmont.cuba.core.sys.remoting.ClusteredHttpInvokerRequestExecutor - Invocation of http://localhost:9080/app-core/remoting/cuba_TrustedClientService failed: java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [null]
2019-07-24 10:16:32.070 INFO  [http-nio-9080-exec-6] com.haulmont.cuba.core.sys.remoting.ClusteredHttpInvokerRequestExecutor - No more URL available
2019-07-24 10:16:32.071 ERROR [http-nio-9080-exec-6] com.haulmont.cuba.web.AppUI - Unable to init ui
java.lang.RuntimeException: Unable to login as anonymous!
	at com.haulmont.cuba.web.DefaultApp.loginOnStart(DefaultApp.java:218) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.AppUI.setupUI(AppUI.java:298) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.AppUI.init(AppUI.java:222) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.vaadin.ui.UI.doInit(UI.java:693) [vaadin-server-7.7.15.cuba.11.jar:7.7.15.cuba.11]
	at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222) [vaadin-server-7.7.15.cuba.11.jar:7.7.15.cuba.11]
	at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74) [vaadin-server-7.7.15.cuba.11.jar:7.7.15.cuba.11]
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) [vaadin-server-7.7.15.cuba.11.jar:7.7.15.cuba.11]
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1435) [vaadin-server-7.7.15.cuba.11.jar:7.7.15.cuba.11]
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:361) [vaadin-server-7.7.15.cuba.11.jar:7.7.15.cuba.11]
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:324) [cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:210) [cuba-web-6.10.11.jar:6.10.11]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) [catalina.jar:8.5.9]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [catalina.jar:8.5.9]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.5.9]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [catalina.jar:8.5.9]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [catalina.jar:8.5.9]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:107) [spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at jespa.http.HttpSecurityService.doFilter(HttpSecurityService.java:1596) [jespa-1.1.21.jar:na]
	at com.somepackage.web.JespaAuthProvider.doFilter(JespaAuthProvider.java:106) [app-web-0.1-SNAPSHOT.jar:na]
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:112) [spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:73) [spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:107) [cuba-web-6.10.11.jar:6.10.11]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [catalina.jar:8.5.9]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [catalina.jar:8.5.9]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [catalina.jar:8.5.9]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:8.5.9]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) [catalina.jar:8.5.9]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:8.5.9]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.5.9]
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) [catalina.jar:8.5.9]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:8.5.9]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [catalina.jar:8.5.9]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-coyote.jar:8.5.9]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:8.5.9]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789) [tomcat-coyote.jar:8.5.9]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437) [tomcat-coyote.jar:8.5.9]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:8.5.9]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_212]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_212]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.5.9]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]
Caused by: com.haulmont.cuba.security.global.InternalAuthenticationException: Exception is thrown by login provider
	at com.haulmont.cuba.web.security.ConnectionImpl.loginInternal(ConnectionImpl.java:206) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.security.ConnectionImpl.login(ConnectionImpl.java:89) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.DefaultApp.loginOnStart(DefaultApp.java:216) ~[cuba-web-6.10.11.jar:6.10.11]
	... 41 common frames omitted
Caused by: org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [cuba_TrustedClientService]; nested exception is java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [null]
	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:226) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:153) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at com.sun.proxy.$Proxy29.getAnonymousSession(Unknown Source) ~[na:na]
	at com.haulmont.cuba.web.security.WebAnonymousSessionHolder.getAnonymousSessionFromService(WebAnonymousSessionHolder.java:74) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.security.WebAnonymousSessionHolder.initializeAnonymousSession(WebAnonymousSessionHolder.java:65) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.security.WebAnonymousSessionHolder.checkInitialized(WebAnonymousSessionHolder.java:54) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.security.WebAnonymousSessionHolder.getAnonymousSession(WebAnonymousSessionHolder.java:43) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.security.providers.AnonymousLoginProvider.login(AnonymousLoginProvider.java:51) ~[cuba-web-6.10.11.jar:6.10.11]
	at com.haulmont.cuba.web.security.ConnectionImpl.loginInternal(ConnectionImpl.java:190) ~[cuba-web-6.10.11.jar:6.10.11]
	... 43 common frames omitted
Caused by: java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [null]
	at org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor.validateResponse(SimpleHttpInvokerRequestExecutor.java:188) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at com.haulmont.cuba.core.sys.remoting.ClusteredHttpInvokerRequestExecutor.doExecuteRequest(ClusteredHttpInvokerRequestExecutor.java:79) ~[cuba-global-6.10.11.jar:6.10.11]
	at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:137) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:202) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:184) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:150) ~[spring-web-4.3.23.RELEASE.jar:4.3.23.RELEASE]
	... 52 common frames omitted

Hello @jason.hodge

Authentication mechanism is refactored - new abstractions introduced:

  • LoginProvider - handles custom Credentials (objects that represent current auth request)
  • HttpRequestFilter - enables you to pre-handle requests and responses to implement custom authentication.

I suggest you to take a look at our reference: Web Login.

I’ve commented out the spring configuration for this bean to remove it from the equasion to see if the app would just work

The given stacktrace is related to some remote invocation problem. Unfortunately I cannot suggest what’s happened.

Please share a demo project if possible.

Regards,
Daniil