Skip to content

Instantly share code, notes, and snippets.

@jrgleason
Created October 19, 2024 16:39
Show Gist options
  • Select an option

  • Save jrgleason/5a6a4d0e2985253b5a070cc6489d2d92 to your computer and use it in GitHub Desktop.

Select an option

Save jrgleason/5a6a4d0e2985253b5a070cc6489d2d92 to your computer and use it in GitHub Desktop.

Revisions

  1. jrgleason revised this gist Oct 19, 2024. 2 changed files with 36 additions and 0 deletions.
    File renamed without changes.
    36 changes: 36 additions & 0 deletions test.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http.csrf(AbstractHttpConfigurer::disable)
    .oauth2Login(AbstractHttpConfigurer::disable)
    .oauth2ResourceServer(AbstractHttpConfigurer::disable)
    .sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
    .oauth2ResourceServer((oauth2) -> oauth2
    .jwt((jwt) -> jwt.decoder(jwtDecoder()))
    )
    .authorizeHttpRequests((authz) -> authz
    .requestMatchers(
    new AntPathRequestMatcher("/actuator/**")
    ).hasAuthority("SCOPE_read:actuators")
    .requestMatchers(
    new AntPathRequestMatcher("/customer/**", "POST")
    ).hasAuthority("SCOPE_user:admin")
    .requestMatchers(
    new AntPathRequestMatcher("/chat"),
    new AntPathRequestMatcher("/chat/**"),
    new AntPathRequestMatcher("/app/chat"),
    new AntPathRequestMatcher("/app/chat/**"),
    new AntPathRequestMatcher("/topic/**"),
    new AntPathRequestMatcher("/heartbeat", "GET"),
    new AntPathRequestMatcher("/contact"),
    new AntPathRequestMatcher("/contact", "POST"),
    new AntPathRequestMatcher("/contact/**"),
    new AntPathRequestMatcher("/assistant", "GET"),
    new AntPathRequestMatcher("/user/stash")
    ).permitAll()
    .requestMatchers(
    new AntPathRequestMatcher("/finance")
    ).hasAuthority("SCOPE_finance")
    .anyRequest().authenticated()
    );
    return http.build();
    }
  2. jrgleason created this gist Oct 19, 2024.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@

    <Auth0Provider
    // @ts-ignore
    domain={domain}
    // @ts-ignore
    clientId={clientId}
    useRefreshTokens={true}
    cacheLocation={"localstorage"}
    // TODO: Avoid hardcoding these values
    advancedOptions={{defaultScope: 'email'}}
    authorizationParams={{
    redirect_uri: redirectUrl,
    audience: "https://cbusha.com",
    defaultScope: "email",
    }}
    >
    <Router>
    <CssBaseline/>
    <CBusAppBar/>
    <main style={{height: "100%"}}>
    <Splash/>
    </main>
    </Router>
    </Auth0Provider>