@@ -15,31 +15,37 @@ import (
1515 "github.com/gin-gonic/gin"
1616)
1717
18+ const requiredGroupPermission = "soarca_admin"
19+
1820func Setup (app * gin.Engine ) {
1921 app .GET ("/404-page" , handlers .ErrorPage )
2022 app .NoRoute (func (ctx * gin.Context ) {
2123 ctx .Redirect (http .StatusTemporaryRedirect , "/404-page" )
2224 })
2325
2426 authEnabled , _ := strconv .ParseBool (utils .GetEnv ("AUTH_ENABLED" , "false" ))
25-
2627 reporter := soarca .NewReport (utils .GetEnv ("SOARCA_URI" , "http://localhost:8080" ), & http.Client {}, authEnabled )
2728 status := soarca .NewStatus (utils .GetEnv ("SOARCA_URI" , "http://localhost:8080" ), & http.Client {}, authEnabled )
2829
29- auth , err := gauth .New (gauth .OIDCRedirectConfig ())
30- authHandler := handlers .NewOIDCAuthHandler (auth )
31- if err != nil {
32- log .Fatal ("could not configure oidc redirect config: " , err )
33- }
30+ var auth * gauth.Authenticator
31+ var authHandler * handlers.OIDCAuthHandler
32+ var err error
33+
3434 publicRoutes := app .Group ("/" )
3535 protectedRoutes := app .Group ("/" )
36- protectedRoutes .Use (auth .LoadAuthContext ())
3736
38- PublicRoutes (publicRoutes , authEnabled , authHandler )
37+ if authEnabled {
38+ auth , err = gauth .New (gauth .OIDCRedirectConfig ())
39+ if err != nil {
40+ log .Fatal ("could not configure oidc redirect config: " , err )
41+ }
42+ authHandler = handlers .NewOIDCAuthHandler (auth )
43+ PublicRoutes (publicRoutes , authEnabled , authHandler )
44+ protectedRoutes .Use (auth .LoadAuthContext ())
45+ protectedRoutes .Use (auth .Middleware ([]string {requiredGroupPermission }))
46+ }
3947
40- protectedRoutes .Use (auth .Middleware ([]string {"soarca_admin" }))
4148 DashboardRoutes (protectedRoutes , authHandler )
42-
4349 ReportingRoutes (reporter , protectedRoutes , authEnabled )
4450 StatusRoutes (status , protectedRoutes , authEnabled )
4551 SettingsRoutes (protectedRoutes )
0 commit comments