@Test public void isForeignModeFalse_whenTrustedClientIdSuffixMatches() throws XSUserInfoException { String tokenClientId = "sb-clone1!b22|brokerplanmasterapp!b123"; String configurationAppId = "brokerplanmasterapp!b123"; XsuaaToken token = mock(XsuaaToken.class); when(token.getClaimAsString(TokenClaims.XSUAA.CLIENT_ID)).thenReturn(tokenClientId); when(token.getClaimAsString(TokenClaims.XSUAA.ZONE_ID)).thenReturn("otherIdentityZone"); OAuth2ServiceConfiguration configuration = OAuth2ServiceConfigurationBuilder.forService(Service.XSUAA) .withClientId(tokenClientId) .withProperty(CFConstants.CLIENT_ID, tokenClientId) .withProperty(CFConstants.XSUAA.APP_ID, configurationAppId) .withProperty(IDENTITY_ZONE, "uaa") .withProperty(TRUSTED_CLIENT_ID_SUFFIX, "|brokerplanmasterapp!b123") .build(); cut = new XSUserInfoAdapter(token, configuration); assertThat(cut.isInForeignMode()).isFalse(); }
@Override public boolean isInForeignMode() { if (configuration == null) { LOGGER.info("No configuration provided -> falling back to foreignMode = true!"); return true; } String tokenClientId, tokenIdentityZone; try { tokenClientId = getClientId(); tokenIdentityZone = getIdentityZone(); } catch (XSUserInfoException e) { LOGGER.warn("Tried to access missing attribute when checking for foreign mode", e); return true; } boolean clientIdsMatch = tokenClientId.equals(configuration.getClientId()); boolean identityZonesMatch = tokenIdentityZone .equals(configuration.getProperty(CFConstants.XSUAA.IDENTITY_ZONE)); boolean isApplicationPlan = tokenClientId.contains("!t"); boolean isBrokerPlan = tokenClientId.contains("!b"); if (clientIdsMatch && (identityZonesMatch || isApplicationPlan || isBrokerPlan)) { LOGGER.info( "Token not in foreign mode because because client ids match and identityZonesMatch={}, isApplicationPlan={} ", identityZonesMatch, isApplicationPlan); return false; } String bindingTrustedClientIdSuffix = configuration.getProperty(TRUSTED_CLIENT_ID_SUFFIX); if (bindingTrustedClientIdSuffix != null && tokenClientId.endsWith(bindingTrustedClientIdSuffix)) { LOGGER.info("Token not in foreign mode because token client id matches binding trusted client suffix"); return false; } LOGGER.info( "Token in foreign mode: clientIdsMatch={}, identityZonesMatch={}, isApplicationPlan={}, bindingTrustedClientIdSuffix={}", clientIdsMatch, identityZonesMatch, isApplicationPlan, bindingTrustedClientIdSuffix); return true; }
XSUserInfoAdapter implements XSUserInfo { @Override public boolean isInForeignMode() { if (configuration == null) { LOGGER.info("No configuration provided -> falling back to foreignMode = true!"); return true; } String tokenClientId, tokenIdentityZone; try { tokenClientId = getClientId(); tokenIdentityZone = getIdentityZone(); } catch (XSUserInfoException e) { LOGGER.warn("Tried to access missing attribute when checking for foreign mode", e); return true; } boolean clientIdsMatch = tokenClientId.equals(configuration.getClientId()); boolean identityZonesMatch = tokenIdentityZone .equals(configuration.getProperty(CFConstants.XSUAA.IDENTITY_ZONE)); boolean isApplicationPlan = tokenClientId.contains("!t"); boolean isBrokerPlan = tokenClientId.contains("!b"); if (clientIdsMatch && (identityZonesMatch || isApplicationPlan || isBrokerPlan)) { LOGGER.info( "Token not in foreign mode because because client ids match and identityZonesMatch={}, isApplicationPlan={} ", identityZonesMatch, isApplicationPlan); return false; } String bindingTrustedClientIdSuffix = configuration.getProperty(TRUSTED_CLIENT_ID_SUFFIX); if (bindingTrustedClientIdSuffix != null && tokenClientId.endsWith(bindingTrustedClientIdSuffix)) { LOGGER.info("Token not in foreign mode because token client id matches binding trusted client suffix"); return false; } LOGGER.info( "Token in foreign mode: clientIdsMatch={}, identityZonesMatch={}, isApplicationPlan={}, bindingTrustedClientIdSuffix={}", clientIdsMatch, identityZonesMatch, isApplicationPlan, bindingTrustedClientIdSuffix); return true; } }
XSUserInfoAdapter implements XSUserInfo { @Override public boolean isInForeignMode() { if (configuration == null) { LOGGER.info("No configuration provided -> falling back to foreignMode = true!"); return true; } String tokenClientId, tokenIdentityZone; try { tokenClientId = getClientId(); tokenIdentityZone = getIdentityZone(); } catch (XSUserInfoException e) { LOGGER.warn("Tried to access missing attribute when checking for foreign mode", e); return true; } boolean clientIdsMatch = tokenClientId.equals(configuration.getClientId()); boolean identityZonesMatch = tokenIdentityZone .equals(configuration.getProperty(CFConstants.XSUAA.IDENTITY_ZONE)); boolean isApplicationPlan = tokenClientId.contains("!t"); boolean isBrokerPlan = tokenClientId.contains("!b"); if (clientIdsMatch && (identityZonesMatch || isApplicationPlan || isBrokerPlan)) { LOGGER.info( "Token not in foreign mode because because client ids match and identityZonesMatch={}, isApplicationPlan={} ", identityZonesMatch, isApplicationPlan); return false; } String bindingTrustedClientIdSuffix = configuration.getProperty(TRUSTED_CLIENT_ID_SUFFIX); if (bindingTrustedClientIdSuffix != null && tokenClientId.endsWith(bindingTrustedClientIdSuffix)) { LOGGER.info("Token not in foreign mode because token client id matches binding trusted client suffix"); return false; } LOGGER.info( "Token in foreign mode: clientIdsMatch={}, identityZonesMatch={}, isApplicationPlan={}, bindingTrustedClientIdSuffix={}", clientIdsMatch, identityZonesMatch, isApplicationPlan, bindingTrustedClientIdSuffix); return true; } XSUserInfoAdapter(Object accessToken);  XSUserInfoAdapter(AccessToken accessToken);   XSUserInfoAdapter(Object accessToken, OAuth2ServiceConfiguration configuration); }
XSUserInfoAdapter implements XSUserInfo { @Override public boolean isInForeignMode() { if (configuration == null) { LOGGER.info("No configuration provided -> falling back to foreignMode = true!"); return true; } String tokenClientId, tokenIdentityZone; try { tokenClientId = getClientId(); tokenIdentityZone = getIdentityZone(); } catch (XSUserInfoException e) { LOGGER.warn("Tried to access missing attribute when checking for foreign mode", e); return true; } boolean clientIdsMatch = tokenClientId.equals(configuration.getClientId()); boolean identityZonesMatch = tokenIdentityZone .equals(configuration.getProperty(CFConstants.XSUAA.IDENTITY_ZONE)); boolean isApplicationPlan = tokenClientId.contains("!t"); boolean isBrokerPlan = tokenClientId.contains("!b"); if (clientIdsMatch && (identityZonesMatch || isApplicationPlan || isBrokerPlan)) { LOGGER.info( "Token not in foreign mode because because client ids match and identityZonesMatch={}, isApplicationPlan={} ", identityZonesMatch, isApplicationPlan); return false; } String bindingTrustedClientIdSuffix = configuration.getProperty(TRUSTED_CLIENT_ID_SUFFIX); if (bindingTrustedClientIdSuffix != null && tokenClientId.endsWith(bindingTrustedClientIdSuffix)) { LOGGER.info("Token not in foreign mode because token client id matches binding trusted client suffix"); return false; } LOGGER.info( "Token in foreign mode: clientIdsMatch={}, identityZonesMatch={}, isApplicationPlan={}, bindingTrustedClientIdSuffix={}", clientIdsMatch, identityZonesMatch, isApplicationPlan, bindingTrustedClientIdSuffix); return true; } XSUserInfoAdapter(Object accessToken);  XSUserInfoAdapter(AccessToken accessToken);   XSUserInfoAdapter(Object accessToken, OAuth2ServiceConfiguration configuration); @Override String getLogonName(); @Override String getGivenName(); @Override String getFamilyName(); @Override String getOrigin(); @Override String getIdentityZone(); @Override /** * "ext_attr": { "enhancer": "XSUAA", "subaccountid": "my-subaccount-1234" }, */ String getSubaccountId(); @Override String getZoneId(); @Override /** * "ext_attr": { "enhancer": "XSUAA", "zdn": "paas-subdomain" }, */ String getSubdomain(); @Override String getClientId(); @Override String getJsonValue(String attribute); @Override String getEmail(); @Override String getDBToken(); @Override String getHdbToken(); @Override String getAppToken(); @Override String getToken(String namespace, String name); @Override String[] getAttribute(String attributeName); @Override boolean hasAttributes(); @Override String[] getSystemAttribute(String attributeName); @Override boolean checkScope(String scope); @Override boolean checkLocalScope(String scope); @Override String getAdditionalAuthAttribute(String attributeName); @Override String getCloneServiceInstanceId(); @Override String getGrantType(); @Override boolean isInForeignMode(); @Override String requestTokenForClient(String clientId, String clientSecret, String baseUaaUrl); @Override String requestTokenForUser(String clientId, String clientSecret, String baseUaaUrl); @Override String requestToken(XSTokenRequest tokenRequest); }
XSUserInfoAdapter implements XSUserInfo { @Override public boolean isInForeignMode() { if (configuration == null) { LOGGER.info("No configuration provided -> falling back to foreignMode = true!"); return true; } String tokenClientId, tokenIdentityZone; try { tokenClientId = getClientId(); tokenIdentityZone = getIdentityZone(); } catch (XSUserInfoException e) { LOGGER.warn("Tried to access missing attribute when checking for foreign mode", e); return true; } boolean clientIdsMatch = tokenClientId.equals(configuration.getClientId()); boolean identityZonesMatch = tokenIdentityZone .equals(configuration.getProperty(CFConstants.XSUAA.IDENTITY_ZONE)); boolean isApplicationPlan = tokenClientId.contains("!t"); boolean isBrokerPlan = tokenClientId.contains("!b"); if (clientIdsMatch && (identityZonesMatch || isApplicationPlan || isBrokerPlan)) { LOGGER.info( "Token not in foreign mode because because client ids match and identityZonesMatch={}, isApplicationPlan={} ", identityZonesMatch, isApplicationPlan); return false; } String bindingTrustedClientIdSuffix = configuration.getProperty(TRUSTED_CLIENT_ID_SUFFIX); if (bindingTrustedClientIdSuffix != null && tokenClientId.endsWith(bindingTrustedClientIdSuffix)) { LOGGER.info("Token not in foreign mode because token client id matches binding trusted client suffix"); return false; } LOGGER.info( "Token in foreign mode: clientIdsMatch={}, identityZonesMatch={}, isApplicationPlan={}, bindingTrustedClientIdSuffix={}", clientIdsMatch, identityZonesMatch, isApplicationPlan, bindingTrustedClientIdSuffix); return true; } XSUserInfoAdapter(Object accessToken);  XSUserInfoAdapter(AccessToken accessToken);   XSUserInfoAdapter(Object accessToken, OAuth2ServiceConfiguration configuration); @Override String getLogonName(); @Override String getGivenName(); @Override String getFamilyName(); @Override String getOrigin(); @Override String getIdentityZone(); @Override /** * "ext_attr": { "enhancer": "XSUAA", "subaccountid": "my-subaccount-1234" }, */ String getSubaccountId(); @Override String getZoneId(); @Override /** * "ext_attr": { "enhancer": "XSUAA", "zdn": "paas-subdomain" }, */ String getSubdomain(); @Override String getClientId(); @Override String getJsonValue(String attribute); @Override String getEmail(); @Override String getDBToken(); @Override String getHdbToken(); @Override String getAppToken(); @Override String getToken(String namespace, String name); @Override String[] getAttribute(String attributeName); @Override boolean hasAttributes(); @Override String[] getSystemAttribute(String attributeName); @Override boolean checkScope(String scope); @Override boolean checkLocalScope(String scope); @Override String getAdditionalAuthAttribute(String attributeName); @Override String getCloneServiceInstanceId(); @Override String getGrantType(); @Override boolean isInForeignMode(); @Override String requestTokenForClient(String clientId, String clientSecret, String baseUaaUrl); @Override String requestTokenForUser(String clientId, String clientSecret, String baseUaaUrl); @Override String requestToken(XSTokenRequest tokenRequest);  }