@@ -158,6 +158,7 @@ object OidcServer extends IOApp {
158158 } else IO .unit
159159
160160 // Test OBP API connection and verify all required roles
161+ roleCheckRef <- cats.effect.Ref .of[IO , Option [ObpApiCredentialsService .RoleCheckResult ]](None )
161162 _ <- {
162163 val requiredRoles = List .empty[String ] ++
163164 (config.verifyCredentialsMethod match {
@@ -179,7 +180,18 @@ object OidcServer extends IOApp {
179180 ).flatMap(msg => IO (println(msg))) *>
180181 // Step 2: Check all required roles (abort immediately if any are missing)
181182 ObpApiCredentialsService .checkRequiredRoles(config, requiredRoles).flatMap {
182- case Right (msg) => IO (println(msg))
183+ case Right (roleCheck) =>
184+ val username = config.obpApiUsername.getOrElse(" unknown" )
185+ val baseUrl = config.obpApiUrl.getOrElse(" unknown" )
186+ roleCheckRef.set(Some (roleCheck)) *>
187+ (if (roleCheck.allPresent) {
188+ IO (println(s " Role check passed: OBP API user ' $username' has all ${requiredRoles.size} required roles " ))
189+ } else {
190+ IO .raiseError(new RuntimeException (
191+ s " STARTUP ABORTED: OBP API user ' $username' is missing required role(s): ${roleCheck.missing.mkString(" , " )}. " +
192+ s " Please grant these roles to user ' $username' at $baseUrl and restart. "
193+ ))
194+ })
183195 case Left (error) => IO .raiseError(new RuntimeException (error))
184196 }
185197 } else {
@@ -951,13 +963,24 @@ object OidcServer extends IOApp {
951963 IO (println(s " USE_VERIFY_ENDPOINTS: ${config.useVerifyEndpoints}" )) *>
952964 (if (config.useVerifyEndpoints) {
953965 val username = config.obpApiUsername.getOrElse(" unknown" )
966+ val roleEndpoints = List (
967+ (" CanVerifyUserCredentials" , " POST /obp/v6.0.0/users/verify-credentials" ),
968+ (" CanGetAnyUser" , " GET /obp/v6.0.0/users/provider/PROVIDER/username/USERNAME" ),
969+ (" CanGetOidcClient" , " GET /obp/v6.0.0/oidc/clients/CLIENT_ID" ),
970+ (" CanGetConsumers" , " GET /obp/v6.0.0/management/consumers" )
971+ )
954972 IO (println(" All verification methods use OBP API endpoints" )) *>
955973 IO (println(s " OBP API Username: $username" )) *>
956974 IO (println(s " Required roles for OBP_API_USERNAME ' $username': " )) *>
957- IO (println(s " - CanVerifyUserCredentials (for POST /obp/v6.0.0/users/verify-credentials) " )) *>
958- IO (println(s " - CanGetAnyUser (for GET /obp/v6.0.0/users/provider/PROVIDER/username/USERNAME) " )) *>
959- IO (println(s " - CanGetOidcClient (for GET /obp/v6.0.0/oidc/clients/CLIENT_ID) " )) *>
960- IO (println(s " - CanGetConsumers (for GET /obp/v6.0.0/management/consumers) " )) *>
975+ roleCheckRef.get.flatMap { roleCheckOpt =>
976+ roleEndpoints.foldLeft(IO .unit) { case (acc, (role, endpoint)) =>
977+ val status = roleCheckOpt match {
978+ case Some (rc) => if (rc.roleStatus(role)) " OK" else " NOT OK"
979+ case None => " UNKNOWN"
980+ }
981+ acc *> IO (println(s " - $role (for $endpoint) ... $status" ))
982+ }
983+ } *>
961984 IO (println(s " No special role required for GET /obp/v6.0.0/providers (just authentication) " ))
962985 } else {
963986 IO (println(" Credential verification: v_oidc_users (database view)" )) *>
0 commit comments