Skip to content

Commit

Permalink
PO-149: Authenticate API calls from frontend (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabahirfan authored Jan 29, 2024
1 parent 00bd3ae commit 0e4d6f9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@Ignore
@PO-130
Feature: Test the defendant account details API

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@Ignore
@PO-119
Feature: Test the defendant account search API

Expand Down
1 change: 1 addition & 0 deletions src/functionalTest/resources/features/notesAPI.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@Ignore
@Smoke
Feature: Notes API tests
Scenario: I post some data to the Notes API and the response contains the correct Data - null noteID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand All @@ -23,7 +22,6 @@
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter;
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
import org.springframework.security.oauth2.jose.jws.SignatureAlgorithm;
import org.springframework.security.oauth2.jwt.Jwt;
Expand All @@ -42,6 +40,8 @@
import uk.gov.hmcts.opal.authentication.config.internal.InternalAuthConfigurationProperties;
import uk.gov.hmcts.opal.authentication.config.internal.InternalAuthConfigurationPropertiesStrategy;
import uk.gov.hmcts.opal.authentication.config.internal.InternalAuthProviderConfigurationProperties;
import uk.gov.hmcts.opal.authentication.exception.AuthenticationError;
import uk.gov.hmcts.opal.exception.OpalApiException;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -70,36 +70,25 @@ public class SecurityConfig {
"/health/**",
"/mappings",
"/info",
"/api/**",
"/metrics",
"/metrics/**",
"/internal-user/login-or-refresh",
"/internal-user/logout",
"/internal-user/handle-oauth-code",
"/api/testing-support",
"/"
};

@Bean
@Order(1)
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public SecurityFilterChain patternFilterChain(HttpSecurity http) throws Exception {

@SuppressWarnings({"PMD.SignatureDeclareThrowsException", "squid:S4502"})
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
applyCommonConfig(http)
.authorizeHttpRequests(authorize ->
authorize.requestMatchers(PathRequest.toStaticResources().atCommonLocations())
.permitAll()
.requestMatchers(AUTH_WHITELIST)
.permitAll()
);

return http.build();
}

@Bean
@SuppressWarnings({"PMD.SignatureDeclareThrowsException", "squid:S4502"})
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
applyCommonConfig(http)
.addFilterBefore(new AuthorisationTokenExistenceFilter(), OAuth2LoginAuthenticationFilter.class)
)
.authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated())
.oauth2ResourceServer(oauth2 ->
oauth2.authenticationManagerResolver(jwtIssuerAuthenticationManagerResolver())
Expand Down Expand Up @@ -154,8 +143,7 @@ protected void doFilterInternal(HttpServletRequest request,
return;
}

response.sendRedirect(locator.locateAuthenticationConfiguration(req -> fallbackConfiguration).getLoginUri(
null).toString());
throw new OpalApiException(AuthenticationError.FAILED_TO_OBTAIN_ACCESS_TOKEN);
}
}

Expand Down

0 comments on commit 0e4d6f9

Please sign in to comment.