Skip to content

Commit

Permalink
Reapply security config
Browse files Browse the repository at this point in the history
  • Loading branch information
ssylver93 committed Sep 30, 2024
1 parent 6074cb4 commit cf1a551
Showing 1 changed file with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,81 @@
import jakarta.servlet.http.HttpServletRequest;

/**
* Default security configuration.
* Assumes all secure endpoints, bearer token, using existing Webade Authentication
* Default security configuration. Assumes all secure endpoints, bearer token,
* using existing Webade Authentication
*/

@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Value("${security.oauth.clientId}")
private String oauthClientId;

@Value("${security.oauth.clientSecret}")
private String oauthClientSecret;

@Value("${security.oauth.checkTokenUrl}")
private String oauthCheckTokenUrl;

@Value("${security.oauth.authTokenUrl}")
private String authTokenUrl;

@Bean
AuthenticationEntryPoint authenticationEntryPoint() {
BasicAuthenticationEntryPoint result;

result = new BasicAuthenticationEntryPoint();
result.setRealmName("wfim-incidents-api");

return result;
}

@Bean
public TokenService tokenServiceImpl() {
return new TokenServiceImpl(
oauthClientId,
oauthClientSecret,
oauthCheckTokenUrl,
authTokenUrl);
}

@Bean
public AuthenticationProvider authenticationProvider() {
return new WebadeOauth2AuthenticationProvider(tokenServiceImpl(), "WFIM.*");
}

@Bean
public AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver() {
return new AuthenticationManagerResolver<HttpServletRequest>() {
@Override
public AuthenticationManager resolve(HttpServletRequest httpServletRequest) {
return new AuthenticationManager() {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
return authenticationProvider().authenticate(authentication);
}};
}};
}

@Value("${security.oauth.clientId}")
private String oauthClientId;

@Value("${security.oauth.clientSecret}")
private String oauthClientSecret;

@Value("${security.oauth.checkTokenUrl}")
private String oauthCheckTokenUrl;

@Value("${security.oauth.authTokenUrl}")
private String authTokenUrl;

@Bean
AuthenticationEntryPoint authenticationEntryPoint() {
BasicAuthenticationEntryPoint result;

result = new BasicAuthenticationEntryPoint();
result.setRealmName("wfim-incidents-api");

return result;
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {

http.csrf().disable();

http.authorizeHttpRequests().anyRequest().permitAll();

// http
// .oauth2ResourceServer(oauth2 -> oauth2
// .authenticationManagerResolver(authenticationManagerResolver())
// )
// .httpBasic().and()
// .authorizeHttpRequests((authorize) -> authorize
// .anyRequest().authenticated()
// )
// .exceptionHandling()
// .authenticationEntryPoint(authenticationEntryPoint());

return http.build();
}
public TokenService tokenServiceImpl() {
return new TokenServiceImpl(
oauthClientId,
oauthClientSecret,
oauthCheckTokenUrl,
authTokenUrl);
}

@Bean
public AuthenticationProvider authenticationProvider() {
return new WebadeOauth2AuthenticationProvider(tokenServiceImpl(), "WFIM.*");
}

@Bean
public AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver() {
return new AuthenticationManagerResolver<HttpServletRequest>() {
@Override
public AuthenticationManager resolve(HttpServletRequest httpServletRequest) {
return new AuthenticationManager() {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
return authenticationProvider().authenticate(authentication);
}
};
}
};
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {

http.csrf().disable();

http
.oauth2ResourceServer(oauth2 -> oauth2
.authenticationManagerResolver(authenticationManagerResolver())
)
.httpBasic().and()
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint());

return http.build();
}

}

0 comments on commit cf1a551

Please sign in to comment.