Changing management port fails on startup

When I change the management port of services the startup fails with java.lang.RuntimeException: Security bypass usage is not allowed after application has been initialized.

server:
    port: 7766
    servlet:
        context-path:
management:
    server:
        port: 7768
        servlet:
            context-path:

leads to

2021-05-25 18:26:26,277 [main                ][INFO ][ConditionEvaluationReportLoggingListener][u:] -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-05-25 18:26:26,285 [main                ][ERROR][g.springframework.boot.SpringApplication][u:] - Application run failed
java.lang.RuntimeException: Security bypass usage is not allowed after application has been initialized.
        at com.mgmtp.a12.uaa.authorization.security.UAASecurityBypass.runWithSecurityBypass(UAASecurityBypass.java:92)
        at com.mgmtp.a12.services.startup.ServicesCoreStartupListener.lambda$onApplicationEvent$6(ServicesCoreStartupListener.java:64)
        at com.mgmtp.a12.services.startup.ServicesCoreStartupListener.doWithUser(ServicesCoreStartupListener.java:97)
        at com.mgmtp.a12.services.startup.ServicesCoreStartupListener.onApplicationEvent(ServicesCoreStartupListener.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:305)
        at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:190)
        at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:153)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:410)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
        at org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.onApplicationEvent(ManagementContextAutoConfiguration.java:142)
        at org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.onApplicationEvent(ManagementContextAutoConfiguration.java:114)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:165)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
        at com.mgmtp.cosmo.GgwModuleUi.main(GgwModuleUi.java:24)
2021-05-25 18:26:26,292 [main                ][INFO ][uling.concurrent.ThreadPoolTaskScheduler][u:] - Shutting down ExecutorService 'taskScheduler'
2021-05-25 18:26:26,295 [main                ][INFO ][duling.concurrent.ThreadPoolTaskExecutor][u:] - Shutting down ExecutorService 'applicationTaskExecutor'
2021-05-25 18:26:28,407 [main                ][INFO ][a.LocalContainerEntityManagerFactoryBean][u:] - Closing JPA EntityManagerFactory for persistence unit 'default'
2021-05-25 18:26:28,414 [main                ][INFO ][com.zaxxer.hikari.HikariDataSource      ][u:] - sfa - Shutdown initiated...
2021-05-25 18:26:28,457 [main                ][INFO ][com.zaxxer.hikari.HikariDataSource      ][u:] - sfa - Shutdown completed.
2021-05-25 18:26:28,597 [task-1              ][INFO ][rvices.server.util.KernelCachesPreloader][u:] - Pre-loading of DomainCustomUser finished in 3431 ms

Am I doing something wrong?

Thanks in advance!

This error does not look like it has anything to do with your configuration change. It looks more like an issue with start-up sequence. Can you paste here full services and uaa configuration?

This is split throughout a couple of files. I collected all setting in these two blocks here:

mgm.services:
    core:
        business-models:
            path: classpath:/com/mgmtp/cosmo/models/overview
        search:
            analysis:
                fullText:
                    enableNgrams: true
            startup: rebuild_index
        document:
            computationEnabled: false
            validateData: false
        system-models:
            document-models: classpath*:/systemModels/*.xml
            custom-document-models: classpath*:/com/mgmtp/cosmo/models/picus/*.xml
            custom-ui-models: classpath*:/com/mgmtp/cosmo/models/melies/*.xml
        user.document-resources.access-rights: classpath*:/accessrights/accessRight*.xml
        user.document-resources.roles:  classpath*:/roles/role*.xml
        user:
            allowedLoginAttempts: 5
            password:
                <PASSWORD RULES>
    rest:
        actuatorSecurity.secured:
            info: false
            health: false
        security:
            additionalFilterConfiguration:
                - key: /api/user/data
                  value: anon
mgm:
  uaa:
    authentication:
      type: OAUTH2
      oauth2:
        client: false
        resource-server: true
      anonymous:
        access-urls:
          - /config
        enabled: true
      compatibility:
        enabled: false
      unsecured-urls: /actuator/health,/actuator/health/*,/actuator/info
      cors:
        allowed-origins: <APPLICATION URL>
    authorzation: # there is a typo in the `AuthorizationProperties` autoconfig
      disable-security-on-start-up: true

Setting mgm.uaa.authorzation.disable-security-on-start-up: true was a suggestion by a colleague. But it does not work with or without it. Error stays the same.

Thanks for taking a look!

Hey,

so do you have any idea why this fails?

Best,
Max

Hey @tomas-thin-gale,

do you happen to have any idea what could go wrong here?

Thanks in advance!

Best,
Max

What version of the services are you running? Do you use services extension points from the start up sequence like: ServicesCustomStartupEvent, ServicesModelsPreloadedEvent or ServicesStartupFinishedEvent? It is hard to tell from the stacktrace what is the issue.

Sorry for the late response.

We’re using version 29.0.3

And yes, we have some services listening for the ServicesCustomStartupEvent and request some data afterwards. Could this be a problem?