Repository: SAP/cloud-security-xsuaa-integration
Pull request #256 (2020-03-25 08:54:48)

Changes XSUserInfoException from Exception to RuntimeException
This reflects the current state of java-container-security.


Patch:
diff --git a/api/src/main/java/com/sap/xsa/security/container/XSUserInfoException.java b/api/src/main/java/com/sap/xsa/security/container/XSUserInfoException.java
index d004ca88..72358393 100644
--- a/api/src/main/java/com/sap/xsa/security/container/XSUserInfoException.java
+++ b/api/src/main/java/com/sap/xsa/security/container/XSUserInfoException.java
@@ -9,7 +9,7 @@ package com.sap.xsa.security.container;
 /**
  * deprecated with version 2.4.0 in favor of the new SAP Java Container library.
  */
-public class XSUserInfoException extends Exception {
+public class XSUserInfoException extends RuntimeException {
 
 	private static final long serialVersionUID = 1L;
 
diff --git a/java-api/src/main/java/com/sap/cloud/security/config/Environment.java b/java-security/src/main/java/com/sap/cloud/security/config/Environment.java
similarity index 84%
rename from java-api/src/main/java/com/sap/cloud/security/config/Environment.java
rename to java-security/src/main/java/com/sap/cloud/security/config/Environment.java
index 95d8764f..5470e644 100644
--- a/java-api/src/main/java/com/sap/cloud/security/config/Environment.java
+++ b/java-security/src/main/java/com/sap/cloud/security/config/Environment.java
@@ -47,8 +47,7 @@ public interface Environment {
 	 * returned.
 	 *
 	 * @return the service configuration to be used for token exchange
-	 *
-	 * @see <a href="https://github.com/SAP/cloud-security-xsuaa-integration/blob/master/token-client/src/main/java/com/sap/cloud/security/xsuaa/tokenflows/XsuaaTokenFlows.java">com.sap.cloud.security.xsuaa.tokenflows.XsuaaTokenFlows</a>
+	 *         {@link com.sap.cloud.security.xsuaa.tokenflows.XsuaaTokenFlows}
 	 */
 	@Nullable
 	OAuth2ServiceConfiguration getXsuaaConfigurationForTokenExchange();
diff --git a/java-api/src/main/java/com/sap/cloud/security/config/OAuth2ServiceConfiguration.java b/java-security/src/main/java/com/sap/cloud/security/config/OAuth2ServiceConfiguration.java
similarity index 100%
rename from java-api/src/main/java/com/sap/cloud/security/config/OAuth2ServiceConfiguration.java
rename to java-security/src/main/java/com/sap/cloud/security/config/OAuth2ServiceConfiguration.java
diff --git a/java-api/src/main/java/com/sap/cloud/security/config/cf/CFConstants.java b/java-security/src/main/java/com/sap/cloud/security/config/cf/CFConstants.java
similarity index 95%
rename from java-api/src/main/java/com/sap/cloud/security/config/cf/CFConstants.java
rename to java-security/src/main/java/com/sap/cloud/security/config/cf/CFConstants.java
index 47ae445b..e05dbf2c 100644
--- a/java-api/src/main/java/com/sap/cloud/security/config/cf/CFConstants.java
+++ b/java-security/src/main/java/com/sap/cloud/security/config/cf/CFConstants.java
@@ -38,7 +38,7 @@ public class CFConstants {
 
 	/**
 	 * Represents the service plans on CF marketplace.
-	 * The various plans are considered in {@code CFEnvironment#loadXsuaa()}
+	 * The various plans are considered in {@link CFEnvironment#loadXsuaa()}
 	 */
 	public enum Plan {
 		DEFAULT, BROKER, APPLICATION, SPACE;
diff --git a/java-security/src/main/java/com/sap/cloud/security/token/SapIdToken.java b/java-security/src/main/java/com/sap/cloud/security/token/SapIdToken.java
index d54e1bec..7ce99389 100644
--- a/java-security/src/main/java/com/sap/cloud/security/token/SapIdToken.java
+++ b/java-security/src/main/java/com/sap/cloud/security/token/SapIdToken.java
@@ -10,12 +10,15 @@ import java.security.Principal;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
-import static com.sap.cloud.security.token.TokenClaims.SAP_GLOBAL_USER_ID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * You can get further token claims from here: {@link TokenClaims}.
  */
 public class SapIdToken extends AbstractToken {
+	static final Logger LOGGER = LoggerFactory.getLogger(SapIdToken.class);
+
 	public SapIdToken(@Nonnull DecodedJwt decodedJwt) {
 		super(decodedJwt);
 	}
@@ -26,7 +29,8 @@ public class SapIdToken extends AbstractToken {
 
 	@Override
 	public Principal getPrincipal() {
-		return createPrincipalByName(getClaimAsString(SAP_GLOBAL_USER_ID));
+		// TODO IAS: should return SAP User ID (guid) if available in id token
+		return null;
 	}
 
 	@Override
diff --git a/samples/java-security-usage/pom.xml b/samples/java-security-usage/pom.xml
index 91d3d5a6..a787ad62 100755
--- a/samples/java-security-usage/pom.xml
+++ b/samples/java-security-usage/pom.xml
@@ -9,7 +9,7 @@
     <properties>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
-        <sap.cloud.security.version>2.5.2</sap.cloud.security.version>
+        <sap.security.client.version>2.5.2</sap.security.client.version>
         <apache.httpclient.version>4.5.8</apache.httpclient.version>
         <javax.servlet.api.version>3.1.0</javax.servlet.api.version>
         <wiremock.version>2.25.1</wiremock.version>
@@ -28,7 +28,7 @@
         <dependency>
             <groupId>com.sap.cloud.security</groupId>
             <artifactId>java-security</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${sap.security.client.version}</version>
         </dependency>
 
         <!-- can be removed when SAP Java Buildpack leverages java-security lib -->
@@ -57,7 +57,7 @@
         <dependency>
             <groupId>com.sap.cloud.security</groupId>
             <artifactId>java-security-test</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${sap.security.client.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/samples/java-tokenclient-usage/pom.xml b/samples/java-tokenclient-usage/pom.xml
index 9c2637bf..95fbb299 100755
--- a/samples/java-tokenclient-usage/pom.xml
+++ b/samples/java-tokenclient-usage/pom.xml
@@ -7,21 +7,42 @@
     <packaging>war</packaging>
 
     <properties>
-        <sap.cloud.security.version>2.5.2</sap.cloud.security.version>
+        <xsuaa.client.version>2.5.2</xsuaa.client.version>
         <apache.httpclient.version>4.5.8</apache.httpclient.version>
         <javax.servlet.api.version>3.0.1</javax.servlet.api.version>
     </properties>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <version>2.3</version>
+                <configuration>
+                    <warName>java-tokenclient-usage</warName>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>8</source>
+                    <target>8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
     <dependencies>
         <dependency>
             <groupId>com.sap.cloud.security.xsuaa</groupId>
             <artifactId>token-client</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${xsuaa.client.version}</version>
         </dependency>
         <dependency>
             <groupId>com.sap.cloud.security</groupId>
             <artifactId>java-security</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${xsuaa.client.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
@@ -36,25 +57,4 @@
             <scope>provided</scope>
         </dependency>
     </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-war-plugin</artifactId>
-                <version>2.3</version>
-                <configuration>
-                    <warName>java-tokenclient-usage</warName>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>8</source>
-                    <target>8</target>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
 </project>
diff --git a/samples/sap-java-buildpack-api-usage/pom.xml b/samples/sap-java-buildpack-api-usage/pom.xml
index 0abbce88..33f0ec5a 100755
--- a/samples/sap-java-buildpack-api-usage/pom.xml
+++ b/samples/sap-java-buildpack-api-usage/pom.xml
@@ -5,39 +5,33 @@
 	<artifactId>sap-java-buildpack-api-usage</artifactId>
 	<version>2.5.2</version>
 	<packaging>war</packaging>
-
-	<properties>
-		<sap.cloud.security.version>2.5.2</sap.cloud.security.version>
-		<javax.servlet.api.version>3.0.1</javax.servlet.api.version>
-	</properties>
-
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>2.3</version>
+				<configuration>
+					<warName>sap-java-buildpack-api-usage</warName>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 	<dependencies>
 		<!-- [OPTIONAL] only required when you need further user information (XSUserInfo) request.getUserPrincipal() -->
 		<dependency>
 			<groupId>com.sap.cloud.security.xsuaa</groupId>
 			<artifactId>api</artifactId>
-			<version>${sap.cloud.security.version}</version>
+			<version>2.5.2</version>
 			<scope>provided</scope>
 		</dependency>
 		<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
 		<dependency>
 			<groupId>javax.servlet</groupId>
 			<artifactId>javax.servlet-api</artifactId>
-			<version>${javax.servlet.api.version}</version>
+			<version>3.0.1</version>
 			<scope>provided</scope>
 		</dependency>
-	</dependencies>
 
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-war-plugin</artifactId>
-				<version>2.3</version>
-				<configuration>
-					<warName>sap-java-buildpack-api-usage</warName>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
+	</dependencies>
 </project>
diff --git a/samples/spring-security-basic-auth/pom.xml b/samples/spring-security-basic-auth/pom.xml
index e8da8f6d..067f3c16 100644
--- a/samples/spring-security-basic-auth/pom.xml
+++ b/samples/spring-security-basic-auth/pom.xml
@@ -18,7 +18,6 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 		<java.version>1.8</java.version>
-		<sap.cloud.security.version>2.5.2</sap.cloud.security.version>
 	</properties>
 
 	<dependencies>
@@ -33,7 +32,7 @@
 		<dependency>
 			<groupId>com.sap.cloud.security.xsuaa</groupId>
 			<artifactId>xsuaa-spring-boot-starter</artifactId>
-			<version>${sap.cloud.security.version}</version>
+			<version>${project.version}</version>
 		</dependency>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
diff --git a/samples/spring-security-xsuaa-usage/pom.xml b/samples/spring-security-xsuaa-usage/pom.xml
index 6093f207..71cb536d 100644
--- a/samples/spring-security-xsuaa-usage/pom.xml
+++ b/samples/spring-security-xsuaa-usage/pom.xml
@@ -27,7 +27,6 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 		<java.version>1.8</java.version>
-		<sap.cloud.security.version>2.5.2</sap.cloud.security.version>
 	</properties>
 
     <dependencies>
@@ -38,7 +37,7 @@
         <dependency>
             <groupId>com.sap.cloud.security.xsuaa</groupId>
             <artifactId>xsuaa-spring-boot-starter</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${project.version}</version>
         </dependency>
 		
 		<!-- test dependencies-->
@@ -50,7 +49,7 @@
 		<dependency>
 			<groupId>com.sap.cloud.security</groupId>
 			<artifactId>java-security-test</artifactId>
-			<version>${sap.cloud.security.version}</version>
+			<version>2.5.2</version>
 			<scope>test</scope>
 		</dependency>
 	</dependencies>
diff --git a/samples/spring-webflux-security-xsuaa-usage/pom.xml b/samples/spring-webflux-security-xsuaa-usage/pom.xml
index 4af8e4d8..19fe9c0e 100644
--- a/samples/spring-webflux-security-xsuaa-usage/pom.xml
+++ b/samples/spring-webflux-security-xsuaa-usage/pom.xml
@@ -17,7 +17,6 @@
 
     <properties>
         <java.version>1.8</java.version>
-        <sap.cloud.security.version>2.5.2</sap.cloud.security.version>
     </properties>
 
     <dependencies>
@@ -39,20 +38,20 @@
         <dependency>
             <groupId>com.sap.cloud.security.xsuaa</groupId>
             <artifactId>spring-xsuaa</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${project.version}</version>
         </dependency>
 
         <dependency>
             <groupId>com.sap.cloud.security.xsuaa</groupId>
             <artifactId>spring-xsuaa-test</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
 
         <dependency>
             <groupId>com.sap.cloud.security.xsuaa</groupId>
             <artifactId>spring-xsuaa-mock</artifactId>
-            <version>${sap.cloud.security.version}</version>
+            <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
 


Test patch:
diff --git a/java-security-test/src/main/java/com/sap/cloud/security/test/JwtGenerator.java b/java-security-test/src/main/java/com/sap/cloud/security/test/JwtGenerator.java
index c3bb5aec..a1498929 100644
--- a/java-security-test/src/main/java/com/sap/cloud/security/test/JwtGenerator.java
+++ b/java-security-test/src/main/java/com/sap/cloud/security/test/JwtGenerator.java
@@ -46,7 +46,7 @@ public class JwtGenerator {
 
 	private JwtSignatureAlgorithm signatureAlgorithm;
 	private PrivateKey privateKey;
-	private String appId; // this is specific to XSUAA service
+	private String appId;
 	private List<String> scopes = new ArrayList<>();
 	private List<String> localScopes = new ArrayList<>();
 
@@ -243,7 +243,7 @@ public class JwtGenerator {
 	/**
 	 * Works like {@link #withScopes(String...)}} but prefixes the scopes with
 	 * "appId.". For example if the appId is "xsapp", the scope "Read" will be
-	 * converted to "xsapp.Read". Make sure the appId has been set via
+	 * converted to "xsapp.Read". Make sure the appId has been via
 	 * {@link #withAppId(String)} before calling this method. Consecutive calls of
 	 * this method will overwrite the data that has previously been set. Calls of
 	 * this method however do not overwrite the data set via
@@ -310,9 +310,9 @@ public class JwtGenerator {
 	}
 
 	private void putScopesInJsonPayload() {
-		String[] resultingScopes = Stream.concat(localScopes.stream(), scopes.stream())
-				.collect(Collectors.toList()).toArray(new String[]{});
-		withClaimValues(TokenClaims.XSUAA.SCOPES, resultingScopes);
+		List<String> resultingScopes = Stream.concat(localScopes.stream(), scopes.stream())
+				.collect(Collectors.toList());
+		jsonPayload.put(TokenClaims.XSUAA.SCOPES, resultingScopes);
 	}
 
 	private void createAudienceClaim() {
diff --git a/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java b/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java
index f3d913f3..2a50a2e0 100644
--- a/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java
+++ b/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java
@@ -94,7 +94,6 @@ public class JwtGeneratorTest {
 				.withClaimValue("first_name", "john")
 				.withClaimValue("last_name", "doe")
 				.withClaimValue("email", "john.doe@email.org")
-				.withClaimValue(TokenClaims.SAP_GLOBAL_USER_ID, "1234567890")
 				.withPrivateKey(keys.getPrivate());
 		Token token = cut.createToken();
 
@@ -102,7 +101,6 @@ public class JwtGeneratorTest {
 		assertThat(token.getClaimAsString(TokenClaims.AUDIENCE)).isEqualTo("T000310");
 		assertThat(token.getClaimAsString(TokenClaims.XSUAA.CLIENT_ID)).isEqualTo("T000310");
 		assertThat(token.getExpiration()).isEqualTo(JwtGenerator.NO_EXPIRE_DATE);
-		assertThat(token.getPrincipal().getName()).isEqualTo("1234567890");
 		String encodedModulusN = Base64.getUrlEncoder()
 				.encodeToString(((RSAPublicKeyImpl) keys.getPublic()).getModulus().toByteArray());
 		assertThat(encodedModulusN).startsWith("AJtUGmczI7RHx3");
diff --git a/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java b/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java
index bfc4ee2e..abf2c02b 100644
--- a/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java
+++ b/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java
@@ -2,10 +2,12 @@ package com.sap.cloud.security.token;
 
 import com.sap.cloud.security.config.Service;
 import org.apache.commons.io.IOUtils;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.security.Principal;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -31,8 +33,11 @@ public class SapIdTokenTest {
 	}
 
 	@Test
+	@Ignore // TODO IAS : principal should return SAP User ID (guid)
 	public void getPrincipal() {
-		assertThat(cut.getPrincipal().getName()).isEqualTo("1234567890");
+		Principal principal = cut.getPrincipal();
+
+		assertThat(principal).isNull();
 	}
 
 	@Test
diff --git a/java-security/src/test/resources/iasOidcTokenRSA256.txt b/java-security/src/test/resources/iasOidcTokenRSA256.txt
index 4ee5ba0c..cd28f447 100644
--- a/java-security/src/test/resources/iasOidcTokenRSA256.txt
+++ b/java-security/src/test/resources/iasOidcTokenRSA256.txt
@@ -1,1 +1,1 @@
-eyJraWQiOiJkZWZhdWx0LWtpZCIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJQMTc2OTQ1IiwiYXVkIjoiVDAwMDMxMCIsInNjb3BlIjoiam9obi5kb2UiLCJpc3MiOiJodHRwczovL2FwcGxpY2F0aW9uLm15YXV0aC5jb20iLCJsYXN0X25hbWUiOiJkb2UiLCJzYXBfdWlkIjoiMTIzNDU2Nzg5MCIsImV4cCI6Njk3NDAzMTYwMCwiZmlyc3RfbmFtZSI6ImpvaG4iLCJlbWFpbCI6ImpvaG4uZG9lQGVtYWlsLm9yZyIsImNpZCI6IlQwMDAzMTAifQ.IcKxFfqGintW8MEcHr-8jEfGnfmLpTw2XfSJIjtME2dpLBaLPoPNslWCC2XUFzqweAvOvBoi9vY-rg76-BE_A3NV6PTsMCCQq_37kDQKWsUFNQdUcqSnWMmX5BMCDneBzbT4_DiVRLcCu44azlg5gKx95sa6Ef0akHTRYGK3pFQcSEdrylQBBYyrelVHYWStn_Ty76_JaK1AYk4a1GOyuUzgx_aMGXHrMcKHX20t3r49mfFBp9v24Sg5HXJOrjfLOy_c-a91BUFsiiJl43wPrkvf2RSrpdvyGxAmOBFM1ELTx6ykRHF57QcCEqE7z7iaeuf_GKhpw6nfhPdcHP3ijw
\ No newline at end of file
+eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJQMTc2OTQ1IiwiYXVkIjoiVDAwMDMxMCIsInNjb3BlIjoiam9obi5kb2UiLCJpc3MiOiJodHRwczovL2FwcGxpY2F0aW9uLm15YXV0aC5jb20iLCJsYXN0X25hbWUiOiJkb2UiLCJleHAiOjY5NzQwMzE2MDAsImZpcnN0X25hbWUiOiJqb2huIiwiZW1haWwiOiJqb2huLmRvZUBlbWFpbC5vcmciLCJjaWQiOiJUMDAwMzEwIn0.LmnUbrrCq0yLO0d6Y-ZEd4oz4oB26CI54950o94LkDeDK-rfskhNVJUvzUDSchCgpouG2rzT4OG_ud26VmJZpUfGr0Yz3vLHM367KH2Tt1CArYRyp4bif7BcDIESphbVOo7kWBQgQHkJVi9adBYNEWJl87I6yASiEimo7Bg64LhyB-PIZmeeHmfyIhUDKIN_kDpyjFqtzHQgAgyajZYmrlzUlcqfrbf8bO3HtPMm5SyM9ZUVpdTA4TIPMgSnrq5aBMVJxELkens-R08OwxdC6WcRARQbgp-xQ0zysuG0JyuuHy507_4OpRCRo9p_4KQI66muUVIHDUqcmPD3GhJi3A
\ No newline at end of file