Skip to content

Commit

Permalink
- Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani authored and offtherailz committed Nov 13, 2024
1 parent 9013fa0 commit 44becb1
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 136 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

</project>
21 changes: 19 additions & 2 deletions src/modules/rest/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,20 @@
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>

<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<version>5.9.1</version>
<scope>test</scope>
</dependency>

<!-- Mockito for JUnit 5 -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.8.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -294,8 +304,15 @@
</executions>
</plugin>
-->
<!-- Maven Surefire Plugin -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ protected SessionToken doRefresh(
boolean success = false;

// Setup HTTP headers and body for the request
RestTemplate restTemplate = new RestTemplate();
// Use restTemplate() method to get RestTemplate instance
OAuth2RestTemplate restTemplate = restTemplate();
HttpHeaders headers = getHttpHeaders(accessToken, configuration);
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("grant_type", "refresh_token");
Expand Down Expand Up @@ -271,7 +272,7 @@ private SessionToken sessionToken(String accessToken, String refreshToken, Date

// Builds an authentication instance out of the passed values.
// Sets it to the cache and to the SecurityContext to be sure the new token is updates.
private void updateAuthToken(
protected void updateAuthToken(
String oldToken,
OAuth2AccessToken newToken,
OAuth2RefreshToken refreshToken,
Expand Down Expand Up @@ -304,7 +305,11 @@ private void updateAuthToken(
}
}

private OAuth2AccessToken retrieveAccessToken(String accessToken) {
protected TokenDetails getTokenDetails(Authentication authentication) {
return OAuth2Utils.getTokenDetails(authentication);
}

protected OAuth2AccessToken retrieveAccessToken(String accessToken) {
Authentication authentication = cache() != null ? cache().get(accessToken) : null;
OAuth2AccessToken result = null;
if (authentication != null) {
Expand All @@ -322,6 +327,14 @@ private OAuth2AccessToken retrieveAccessToken(String accessToken) {
return result;
}

protected HttpServletRequest getRequest() {
return OAuth2Utils.getRequest();
}

protected HttpServletResponse getResponse() {
return OAuth2Utils.getResponse();
}

@Override
public void doLogout(String sessionId) {
HttpServletRequest request = getRequest();
Expand Down Expand Up @@ -502,7 +515,7 @@ protected boolean deleteCookie(javax.servlet.http.Cookie c) {
|| c.getName().equalsIgnoreCase(REFRESH_TOKEN_PARAM);
}

private TokenAuthenticationCache cache() {
protected TokenAuthenticationCache cache() {
return GeoStoreContext.bean("oAuth2Cache", TokenAuthenticationCache.class);
}

Expand Down
Loading

0 comments on commit 44becb1

Please sign in to comment.