Skip to content

Commit

Permalink
small change
Browse files Browse the repository at this point in the history
  • Loading branch information
bhtibrewal committed Mar 3, 2024
1 parent 222919c commit 5acb634
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class SecurityConfig {

private final AuthEntryPoint authEntryPoint;
private final CustomAccessDeniedHandler accessDeniedHandler;
private final String[] roles = Arrays.stream(UserRole.values()).map(role -> role.label).toArray(String[]::new);


public SecurityConfig(AuthEntryPoint authEntryPoint, CustomAccessDeniedHandler accessDeniedHandler) {
Expand All @@ -43,11 +42,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.cors(httpSecurityCorsConfigurer -> httpSecurityCorsConfigurer.configurationSource(corsConfigurationSource()))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/v1/endorsements/status").hasAuthority(UserRole.SUPERUSER.label)
.requestMatchers("/v1/endorsements/**").hasAnyAuthority(roles)
.requestMatchers("/v1/**").hasAnyAuthority(UserRole.getAllRoles())
.anyRequest().authenticated())
.exceptionHandling(ex -> ex.accessDeniedHandler(this.accessDeniedHandler).authenticationEntryPoint(this.authEntryPoint))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
// http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)

http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
return http.build();
}
Expand Down
4 changes: 4 additions & 0 deletions skill-tree/src/main/java/com/RDS/skilltree/User/UserRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.security.core.GrantedAuthority;

import java.util.Arrays;
import java.util.Collection;

public enum UserRole {
Expand All @@ -22,5 +23,8 @@ public static UserRole fromString(String text) {
}
return null;
}
public static String[] getAllRoles(){
return Arrays.stream(UserRole.values()).map(role -> role.label).toArray(String[]::new);
}

}

0 comments on commit 5acb634

Please sign in to comment.