nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: SAP/cloud-security-xsuaa-integration
Pull request #113 (2019-07-25 07:23:59)

Set scopes for OAuth2Authentication
Requiered to make the authentication work, even if it looks redudant.


Patch:
diff --git a/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/token/OAuth2AuthenticationConverter.java b/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/token/OAuth2AuthenticationConverter.java
index 2f9c5d04..0c79c318 100644
--- a/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/token/OAuth2AuthenticationConverter.java
+++ b/spring-xsuaa/src/main/java/com/sap/cloud/security/xsuaa/token/OAuth2AuthenticationConverter.java
@@ -25,7 +25,8 @@ public class OAuth2AuthenticationConverter extends TokenAuthenticationConverter
 	public OAuth2Authentication convert(Jwt jwt) {
 		AuthenticationToken authenticationToken = (AuthenticationToken) super.convert(jwt);
 		String clientId = jwt.getClaimAsString(CLAIM_CLIENT_ID);
-		AuthorizationRequest authorizationRequest = new AuthorizationRequest(clientId, null);
+		AuthorizationRequest authorizationRequest = new AuthorizationRequest(clientId,
+				authenticationToken.getAuthorities().stream().map(Objects::toString).collect(Collectors.toList()));
 		authorizationRequest.setApproved(true);
 		authorizationRequest.setAuthorities(authenticationToken.getAuthorities());
 


Test patch:
diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/OAuth2TokenAuthenticationConverterTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/OAuth2TokenAuthenticationConverterTest.java
index 6c49089d..310c8140 100644
--- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/OAuth2TokenAuthenticationConverterTest.java
+++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/OAuth2TokenAuthenticationConverterTest.java
@@ -38,5 +38,6 @@ public class OAuth2TokenAuthenticationConverterTest {
 		assertThat(authenticationToken.getAuthorities(), hasItem(new SimpleGrantedAuthority(scopeOther)));
 
 		assertTrue(authenticationToken instanceof OAuth2Authentication);
+		assertThat(((OAuth2Authentication) authenticationToken).getOAuth2Request().getScope(), hasItem(scopeRead));
 	}
 }
Repository: SAP/cloud-security-xsuaa-integration
Pull request #446 (2021-01-04 15:43:10)

spring-xsuaa token-client usage for multi-tenant usage
replacement for this one
https://github.com/SAP/cloud-security-xsuaa-integration/pull/441/files


Patch:
diff --git a/java-security/pom.xml b/java-security/pom.xml
index e361b996..67649fdb 100644
--- a/java-security/pom.xml
+++ b/java-security/pom.xml
@@ -71,6 +71,12 @@
 			<artifactId>junit</artifactId>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.junit.vintage</groupId>
+			<artifactId>junit-vintage-engine</artifactId>
+			<version>5.7.0</version>
+			<scope>test</scope>
+		</dependency>
 		<dependency>
 			<groupId>org.junit.jupiter</groupId>
 			<artifactId>junit-jupiter-engine</artifactId>


Test patch:
diff --git a/samples/spring-security-xsuaa-usage/src/main/java/sample/spring/xsuaa/TestController.java b/samples/spring-security-xsuaa-usage/src/main/java/sample/spring/xsuaa/TestController.java
index ea497bfe..f54a47ac 100644
--- a/samples/spring-security-xsuaa-usage/src/main/java/sample/spring/xsuaa/TestController.java
+++ b/samples/spring-security-xsuaa-usage/src/main/java/sample/spring/xsuaa/TestController.java
@@ -146,13 +146,14 @@ public class TestController {
      * <p>
      *
      *
-     * @param jwt - the Jwt as a result of authentication.
+     * @param token - the Jwt as a result of authentication.
      * @throws TokenFlowException in case of any errors.
      */
     @GetMapping("/v3/requestUserToken")
-    public String requestUserToken(@AuthenticationPrincipal Jwt jwt) throws TokenFlowException {
+    public String requestUserToken(@AuthenticationPrincipal Token token) throws TokenFlowException {
         OAuth2TokenResponse userTokenResponse = tokenFlows.userTokenFlow()
-                .token(jwt.getTokenValue())
+                .token(token.getAppToken())
+                .subdomain(token.getSubdomain())
                 .execute();
 
         logger.info("Got the exchanged token for 3rd party service: {}", userTokenResponse);
Repository: SAP/cloud-security-xsuaa-integration
Pull request #555 (2021-06-30 07:47:31)

fix HttpHeaders toString method #549


Patch:
diff --git a/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeader.java b/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeader.java
index 78b82443..0fd39a22 100644
--- a/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeader.java
+++ b/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeader.java
@@ -40,4 +40,9 @@ public class HttpHeader {
 	public int hashCode() {
 		return Objects.hash(getName(), getValue());
 	}
+
+	@Override
+	public String toString() {
+		return "\"" + name + ": " + value + "\"";
+	}
 }
diff --git a/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeaders.java b/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeaders.java
index d5476205..6abe9bdf 100644
--- a/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeaders.java
+++ b/token-client/src/main/java/com/sap/cloud/security/xsuaa/http/HttpHeaders.java
@@ -52,8 +52,9 @@ public class HttpHeaders {
 
 	@Override
 	public String toString() {
-		return "HttpHeaders{" +
-				"headers=" + headers +
-				'}';
+		return "HttpHeaders: [ " +
+				headers.stream().map(HttpHeader::toString)
+						.collect(Collectors.joining(", ")) +
+				" ]";
 	}
 }


Test patch:
diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java
index 65993597..73965b2b 100644
--- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java
+++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java
@@ -12,9 +12,9 @@ import static org.assertj.core.util.Lists.newArrayList;
 
 public class HttpHeadersTest {
 
-	private HttpHeader header = new HttpHeader("a", "a_value");
-	private HttpHeader anotherHeader = new HttpHeader("b", "b_value");
-	private HttpHeader sameKeyDifferentValue = new HttpHeader("a", "different_value");
+	private final HttpHeader header = new HttpHeader("a", "a_value");
+	private final HttpHeader anotherHeader = new HttpHeader("b", "b_value");
+	private final HttpHeader sameKeyDifferentValue = new HttpHeader("a", "different_value");
 
 	@Test
 	public void equals_sameHeaders_isEqual() {
@@ -38,9 +38,13 @@ public class HttpHeadersTest {
 		HttpHeaders headers2 = new HttpHeaders(anotherHeader);
 		HttpHeaders headers3 = new HttpHeaders(sameKeyDifferentValue);
 
-		assertThat(headers1).isNotEqualTo(headers2);
-		assertThat(headers1).isNotEqualTo(headers3);
+		assertThat(headers1).isNotEqualTo(headers2).isNotEqualTo(headers3);
 		assertThat(headers2).isNotEqualTo(headers3);
 	}
 
+	@Test
+	public void toStringTest() {
+		HttpHeaders headers = new HttpHeaders(header, anotherHeader);
+		assertThat(headers).hasToString("HttpHeaders: [ \"a: a_value\", \"b: b_value\" ]");
+	}
 }
\ No newline at end of file