Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Resolve Backend Deprecation Warnings #917 #918

Merged
merged 15 commits into from
Jan 31, 2025
10 changes: 5 additions & 5 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
jobs:
formatting:
name: Formatting
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:

build:
name: Build
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -64,14 +64,14 @@ jobs:
build-root-directory: backend
- name: Upload artifacts
if: github.event.pull_request.head.repo.full_name == github.repository
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: backend
path: backend/build

test:
name: Test
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
checks: write
contents: read
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
- name: Upload JaCoCo coverage report
if: github.event.pull_request.head.repo.full_name == github.repository
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: backend/build/jacoco-report/
2 changes: 1 addition & 1 deletion .github/workflows/badges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
add: '*.svg'

- name: Upload Jacoco coverage report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: target/site/jacoco/
2 changes: 1 addition & 1 deletion .github/workflows/docs-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Build
run: npm run docs:build
- uses: actions/configure-pages@v2
- uses: actions/upload-pages-artifact@v1
- uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
- name: Deploy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: npm run build
- name: Upload artifacts
if: github.event.pull_request.head.repo.full_name == github.repository
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: frontend
path: frontend/dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.diveni.backend.service.projectmanagementproviders.ProjectManagementProviderOAuth2;
import lombok.Getter;
import lombok.val;
import org.apache.tomcat.util.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -32,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Base64;

@Service
public class AzureDevOpsService implements ProjectManagementProviderOAuth2 {
Expand Down Expand Up @@ -82,7 +82,8 @@ public ResponseEntity<String> executeRequest(
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
headers.setContentType(contentType);
String token = ":" + accessToken;
headers.add("Authorization", "Basic " + new String(new Base64().encode(token.getBytes())));
headers.add(
"Authorization", "Basic " + new String(Base64.getEncoder().encode(token.getBytes())));
HttpEntity<Object> request = new HttpEntity<>(body, headers);
LOGGER.debug("<-- executeRequest()");
return restTemplate.exchange(url, method, request, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Base64;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.api.client.util.Base64;

import io.diveni.backend.Utils;
import io.diveni.backend.model.Project;
Expand Down Expand Up @@ -126,7 +126,7 @@ public TokenIdentifier getAccessToken(String authorizationCode, String origin) {
LOGGER.debug("--> getAccessToken()");
RestTemplate restTemplate = new RestTemplate();
String credentials = CLIENT_ID + ":" + CLIENT_SECRET;
String encodedCredentials = new String(Base64.encodeBase64(credentials.getBytes()));
String encodedCredentials = new String(Base64.getEncoder().encode(credentials.getBytes()));

HttpHeaders headers = new HttpHeaders();
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
package io.diveni.backend.service.projectmanagementproviders.jiraserver;

import com.google.api.client.auth.oauth.OAuthRsaSigner;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.util.Base64;
import com.google.api.client.http.javanet.NetHttpTransport;

import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;

import java.util.Base64;

public class JiraOAuthTokenFactory {
protected final String accessTokenUrl;
protected final String requestTokenUrl;
Expand Down Expand Up @@ -42,7 +43,7 @@ public JiraOAuthGetAccessToken getJiraOAuthGetAccessToken(
JiraOAuthGetAccessToken accessToken = new JiraOAuthGetAccessToken(accessTokenUrl);
accessToken.consumerKey = consumerKey;
accessToken.signer = getOAuthRsaSigner(privateKey);
accessToken.transport = new ApacheHttpTransport();
accessToken.transport = new NetHttpTransport();
accessToken.verifier = secret;
accessToken.temporaryToken = tmpToken;
return accessToken;
Expand All @@ -65,7 +66,7 @@ public JiraOAuthGetAccessToken getJiraOAuthGetAccessToken(
JiraOAuthGetAccessToken accessToken = new JiraOAuthGetAccessToken(accessTokenUrl);
accessToken.consumerKey = consumerKey;
accessToken.signer = getOAuthRsaSigner(privateKey);
accessToken.transport = new ApacheHttpTransport();
accessToken.transport = new NetHttpTransport();
accessToken.temporaryToken = tmpToken;
return accessToken;
}
Expand All @@ -86,7 +87,7 @@ public JiraOAuthGetTemporaryToken getTemporaryToken(String consumerKey, String p
new JiraOAuthGetTemporaryToken(requestTokenUrl);
oAuthGetTemporaryToken.consumerKey = consumerKey;
oAuthGetTemporaryToken.signer = getOAuthRsaSigner(privateKey);
oAuthGetTemporaryToken.transport = new ApacheHttpTransport();
oAuthGetTemporaryToken.transport = new NetHttpTransport();
oAuthGetTemporaryToken.callback = "oob";
return oAuthGetTemporaryToken;
}
Expand Down Expand Up @@ -114,7 +115,7 @@ private OAuthRsaSigner getOAuthRsaSigner(String privateKey)
*/
private PrivateKey getPrivateKey(String privateKey)
throws NoSuchAlgorithmException, InvalidKeySpecException {
byte[] privateBytes = Base64.decodeBase64(privateKey);
byte[] privateBytes = Base64.getDecoder().decode(privateKey);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privateBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(keySpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

import java.util.HashMap;
Expand All @@ -30,7 +30,7 @@ public class AiControllerTest {

@Autowired private MockMvc mockMvc;

@MockBean private AiService service;
@MockitoBean private AiService service;

@BeforeEach
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.web.client.RestClientException;
Expand All @@ -35,7 +35,7 @@ public class NewsControllerTest {

@Autowired private MockMvc mockMvc;

@MockBean private RestTemplate client;
@MockitoBean private RestTemplate client;

@Test
public void getPRs_InvalidState_returnsException() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private String getWsPath(String format, String sessionID, String principalID) {

private StompSession getAdminSession(String sessionID, String adminID) throws Exception {
return webSocketStompClient
.connect(
.connectAsync(
getWsPath(WS_ADMIN_PATH, sessionID, adminID),
new StompSessionHandlerAdapter() {
@Override
Expand All @@ -139,7 +139,7 @@ public void handleException(

private StompSession getMemberSession(String sessionID, String memberID) throws Exception {
return webSocketStompClient
.connect(
.connectAsync(
getWsPath(WS_MEMBER_PATH, sessionID, memberID), new StompSessionHandlerAdapter() {})
.get();
}
Expand Down