Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
- Apply IntelliJ sanitizations
- Pull giant strings into resources

[#163746990] https://www.pivotaltracker.com/story/show/163746990
  • Loading branch information
joshuatcasey committed Feb 6, 2019
1 parent b479089 commit 849e43d
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 149 deletions.
Expand Up @@ -32,7 +32,7 @@ public static void setProvisioning(IdentityZoneProvisioning provisioning) {
private static final ThreadLocal<IdentityZoneWithKeyManager> THREADLOCAL = new InheritableThreadLocal<IdentityZoneWithKeyManager>() { private static final ThreadLocal<IdentityZoneWithKeyManager> THREADLOCAL = new InheritableThreadLocal<IdentityZoneWithKeyManager>() {
@Override @Override
protected IdentityZoneWithKeyManager initialValue() { protected IdentityZoneWithKeyManager initialValue() {
if (provisioning==null) { if (provisioning == null) {
return new IdentityZoneWithKeyManager(IdentityZone.getUaa(), null); return new IdentityZoneWithKeyManager(IdentityZone.getUaa(), null);
} }
IdentityZone zone = getUaaZone(); IdentityZone zone = getUaaZone();
Expand All @@ -46,9 +46,9 @@ public static IdentityZone get() {


public static KeyManager getSamlSPKeyManager() { public static KeyManager getSamlSPKeyManager() {
IdentityZoneWithKeyManager withKeyManager = THREADLOCAL.get(); IdentityZoneWithKeyManager withKeyManager = THREADLOCAL.get();
if (withKeyManager.getManager()==null) { if (withKeyManager.getManager() == null) {
KeyManager keyManager = SamlKeyManagerFactory.getKeyManager(withKeyManager.getZone().getConfig().getSamlConfig()); KeyManager keyManager = SamlKeyManagerFactory.getKeyManager(withKeyManager.getZone().getConfig().getSamlConfig());
if (keyManager==null) { if (keyManager == null) {
keyManager = SamlKeyManagerFactory.getKeyManager(getUaaZone().getConfig().getSamlConfig()); keyManager = SamlKeyManagerFactory.getKeyManager(getUaaZone().getConfig().getSamlConfig());
} }
withKeyManager.setManager(keyManager); withKeyManager.setManager(keyManager);
Expand All @@ -57,7 +57,7 @@ public static KeyManager getSamlSPKeyManager() {
} }


public static IdentityZone getUaaZone() { public static IdentityZone getUaaZone() {
if (provisioning==null) { if (provisioning == null) {
return IdentityZone.getUaa(); return IdentityZone.getUaa();
} }
return provisioning.retrieve(IdentityZone.getUaa().getId()); return provisioning.retrieve(IdentityZone.getUaa().getId());
Expand Down Expand Up @@ -89,7 +89,7 @@ public static class IdentityZoneWithKeyManager {
private IdentityZone zone; private IdentityZone zone;
private KeyManager manager; private KeyManager manager;


public IdentityZoneWithKeyManager(IdentityZone zone, KeyManager manager) { IdentityZoneWithKeyManager(IdentityZone zone, KeyManager manager) {
this.zone = zone; this.zone = zone;
this.manager = manager; this.manager = manager;
} }
Expand Down Expand Up @@ -140,19 +140,20 @@ public Map<String, String> getFooterLinks() {


private static <T> T resolve(Function<BrandingInformationSource, T> brandingProperty) { private static <T> T resolve(Function<BrandingInformationSource, T> brandingProperty) {
return return
tryGet(get(), brandingProperty) tryGet(get(), brandingProperty)
.orElse(tryGet(getUaaZone(), brandingProperty) .orElse(tryGet(getUaaZone(), brandingProperty)
.orElse(null)); .orElse(null));
} }


private static <T> Optional<T> tryGet(IdentityZone zone, Function<BrandingInformationSource, T> brandingProperty) { private static <T> Optional<T> tryGet(IdentityZone zone, Function<BrandingInformationSource, T> brandingProperty) {
return ofNullable(zone.getConfig()) return ofNullable(zone.getConfig())
.flatMap(c -> ofNullable(c.getBranding())) .flatMap(c -> ofNullable(c.getBranding()))
.flatMap(b -> ofNullable(brandingProperty.apply(b))); .flatMap(b -> ofNullable(brandingProperty.apply(b)));
} }
} }


private static final BrandingInformationSource brandingResolver = new MergedZoneBrandingInformation(); private static final BrandingInformationSource brandingResolver = new MergedZoneBrandingInformation();

public static BrandingInformationSource resolveBranding() { public static BrandingInformationSource resolveBranding() {
return brandingResolver; return brandingResolver;
} }
Expand Down
Expand Up @@ -14,11 +14,15 @@
*/ */
package org.cloudfoundry.identity.uaa.zone; package org.cloudfoundry.identity.uaa.zone;


import org.apache.commons.io.IOUtils;
import org.cloudfoundry.identity.uaa.util.JsonUtils; import org.cloudfoundry.identity.uaa.util.JsonUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;


import java.io.IOException;
import java.nio.charset.Charset;

import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;


Expand All @@ -29,13 +33,10 @@ public class IdentityZoneHolderTest {
private IdentityZone fakeUaa; private IdentityZone fakeUaa;


@Before @Before
public void setUp() throws Exception { public void setUp() {
defaultZoneBranding = new BrandingInformation(); defaultZoneBranding = new BrandingInformation();
defaultZoneBranding.setProductLogo("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABSUlEQVQ4EaVTO04DMRB9YdOTC+QcK46w" + final String productLogo = getResourceAsString("IdentityZoneHolderTest_ProductLogo");
"FU3apclKuQMH4AYUkUxFmyY0PgLac3AB6ImM3kyePYkQDZZ27Zl58+aNP8A/x2J7ixI5Xr6wiHaMX8eIW/L3/tlStisUAZm8fx1acMxWTPFK0BBOR" + defaultZoneBranding.setProductLogo(productLogo);
"hL5ukP2ZQ9UsjHXIqZA4LuVrwjsPjxxenRfAtAh47QenCiQgFL5fb8NpTyjlAf/5KOfa/llk/pG1WvV2T3T0We1wLh8jNAmaSUwyTMMRGC6dxDXIl" +
"ExtUd7SZb0BKhXU3LIRrTfKKXNpsLU+R7VTWTFKJEpuzGbktNmuFiLjnEj4M52s4OnMVt/CedTYLWjx9Artc1269hG3MSohMps9LAjVCqrc9QWaJg" +
"SZCRWOp+GoX5J5u3lvan3nioIphIOnQr711BVXf0LAoGuieRnMt8A438SKEFEsuMDirEf/oirUgza/ucAAAAASUVORK5CYII=");


zoneBranding = new BrandingInformation(); zoneBranding = new BrandingInformation();
zoneBranding.setProductLogo("zoneBrandingString==="); zoneBranding.setProductLogo("zoneBrandingString===");
Expand Down Expand Up @@ -78,138 +79,18 @@ public void getProductLogoForDefaultZoneReturnsDefaultLogo() {
} }


@Test @Test
public void deserialize() throws Exception { public void deserialize() {
String json = "{\n" + final String sampleIdentityZone = getResourceAsString("sampleIdentityZone.json");
" \"id\": \"f7758816-ab47-48d9-9d24-25b10b92d4cc\",\n" +
" \"subdomain\": \"demo\",\n" + JsonUtils.readValue(sampleIdentityZone, IdentityZone.class);
" \"config\": {\n" + }
" \"clientSecretPolicy\": {\n" +
" \"minLength\": -1,\n" + private String getResourceAsString(String s) {
" \"maxLength\": -1,\n" + try {
" \"requireUpperCaseCharacter\": -1,\n" + return IOUtils.toString(getClass().getResourceAsStream(s), Charset.defaultCharset());
" \"requireLowerCaseCharacter\": -1,\n" + } catch (IOException e) {
" \"requireDigit\": -1,\n" + e.printStackTrace();
" \"requireSpecialCharacter\": -1\n" + throw new RuntimeException(e);
" },\n" + }
" \"tokenPolicy\": {\n" +
" \"accessTokenValidity\": -1,\n" +
" \"refreshTokenValidity\": -1,\n" +
" \"jwtRevocable\": false,\n" +
" \"refreshTokenUnique\": false,\n" +
" \"refreshTokenFormat\": \"jwt\",\n" +
" \"activeKeyId\": null\n" +
" },\n" +
" \"samlConfig\": {\n" +
" \"assertionSigned\": true,\n" +
" \"requestSigned\": true,\n" +
" \"wantAssertionSigned\": true,\n" +
" \"wantAuthnRequestSigned\": false,\n" +
" \"assertionTimeToLiveSeconds\": 600,\n" +
" \"keys\": {\n" +
" },\n" +
" \"disableInResponseToCheck\": true\n" +
" },\n" +
" \"corsPolicy\": {\n" +
" \"xhrConfiguration\": {\n" +
" \"allowedOrigins\": [\n" +
" \".*\"\n" +
" ],\n" +
" \"allowedOriginPatterns\": [\n" +
"\n" +
" ],\n" +
" \"allowedUris\": [\n" +
" \".*\"\n" +
" ],\n" +
" \"allowedUriPatterns\": [\n" +
"\n" +
" ],\n" +
" \"allowedHeaders\": [\n" +
" \"Accept\",\n" +
" \"Authorization\",\n" +
" \"Content-Type\"\n" +
" ],\n" +
" \"allowedMethods\": [\n" +
" \"GET\"\n" +
" ],\n" +
" \"allowedCredentials\": false,\n" +
" \"maxAge\": 1728000\n" +
" },\n" +
" \"defaultConfiguration\": {\n" +
" \"allowedOrigins\": [\n" +
" \".*\"\n" +
" ],\n" +
" \"allowedOriginPatterns\": [\n" +
"\n" +
" ],\n" +
" \"allowedUris\": [\n" +
" \".*\"\n" +
" ],\n" +
" \"allowedUriPatterns\": [\n" +
"\n" +
" ],\n" +
" \"allowedHeaders\": [\n" +
" \"Accept\",\n" +
" \"Authorization\",\n" +
" \"Content-Type\"\n" +
" ],\n" +
" \"allowedMethods\": [\n" +
" \"GET\"\n" +
" ],\n" +
" \"allowedCredentials\": false,\n" +
" \"maxAge\": 1728000\n" +
" }\n" +
" },\n" +
" \"links\": {\n" +
" \"logout\": {\n" +
" \"redirectUrl\": \"/login\",\n" +
" \"redirectParameterName\": \"redirect\",\n" +
" \"disableRedirectParameter\": false,\n" +
" \"whitelist\": null\n" +
" },\n" +
" \"selfService\": {\n" +
" \"selfServiceLinksEnabled\": true,\n" +
" \"signup\": null,\n" +
" \"passwd\": null\n" +
" }\n" +
" },\n" +
" \"prompts\": [\n" +
" {\n" +
" \"name\": \"username\",\n" +
" \"type\": \"text\",\n" +
" \"text\": \"Email\"\n" +
" },\n" +
" {\n" +
" \"name\": \"password\",\n" +
" \"type\": \"password\",\n" +
" \"text\": \"Password\"\n" +
" },\n" +
" {\n" +
" \"name\": \"passcode\",\n" +
" \"type\": \"password\",\n" +
" \"text\": \"Temporary Authentication Code (Get on at /passcode)\"\n" +
" }\n" +
" ],\n" +
" \"idpDiscoveryEnabled\": false,\n" +
" \"accountChooserEnabled\": false,\n" +
" \"userConfig\": {\n" +
" \"defaultGroups\": [\n" +
" \"openid\",\n" +
" \"password.write\",\n" +
" \"uaa.user\",\n" +
" \"approvals.me\",\n" +
" \"profile\",\n" +
" \"roles\",\n" +
" \"user_attributes\",\n" +
" \"uaa.offline_token\"\n" +
" ]\n" +
" }\n" +
" },\n" +
" \"name\": \"Demo Login Page\",\n" +
" \"version\": 1,\n" +
" \"description\": \"{\\\"plan_display_name\\\":\\\"Demo\\\",\\\"plan_description\\\":\\\"Demo SSO Plan\\\"}\",\n" +
" \"created\": 1503504273000,\n" +
" \"last_modified\": 1504898224000\n" +
"}";
IdentityZone zone = JsonUtils.readValue(json, IdentityZone.class);
} }
} }
@@ -0,0 +1 @@
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABSUlEQVQ4EaVTO04DMRB9YdOTC+QcK46wFU3apclKuQMH4AYUkUxFmyY0PgLac3AB6ImM3kyePYkQDZZ27Zl58+aNP8A/x2J7ixI5Xr6wiHaMX8eIW/L3/tlStisUAZm8fx1acMxWTPFK0BBORhL5ukP2ZQ9UsjHXIqZA4LuVrwjsPjxxenRfAtAh47QenCiQgFL5fb8NpTyjlAf/5KOfa/llk/pG1WvV2T3T0We1wLh8jNAmaSUwyTMMRGC6dxDXIlExtUd7SZb0BKhXU3LIRrTfKKXNpsLU+R7VTWTFKJEpuzGbktNmuFiLjnEj4M52s4OnMVt/CedTYLWjx9Artc1269hG3MSohMps9LAjVCqrc9QWaJgSZCRWOp+GoX5J5u3lvan3nioIphIOnQr711BVXf0LAoGuieRnMt8A438SKEFEsuMDirEf/oirUgza/ucAAAAASUVORK5CYII=
@@ -0,0 +1,127 @@
{
"id": "f7758816-ab47-48d9-9d24-25b10b92d4cc",
"subdomain": "demo",
"config": {
"clientSecretPolicy": {
"minLength": -1,
"maxLength": -1,
"requireUpperCaseCharacter": -1,
"requireLowerCaseCharacter": -1,
"requireDigit": -1,
"requireSpecialCharacter": -1
},
"tokenPolicy": {
"accessTokenValidity": -1,
"refreshTokenValidity": -1,
"jwtRevocable": false,
"refreshTokenUnique": false,
"refreshTokenFormat": "jwt",
"activeKeyId": null
},
"samlConfig": {
"assertionSigned": true,
"requestSigned": true,
"wantAssertionSigned": true,
"wantAuthnRequestSigned": false,
"assertionTimeToLiveSeconds": 600,
"keys": {
},
"disableInResponseToCheck": true
},
"corsPolicy": {
"xhrConfiguration": {
"allowedOrigins": [
".*"
],
"allowedOriginPatterns": [
],
"allowedUris": [
".*"
],
"allowedUriPatterns": [
],
"allowedHeaders": [
"Accept",
"Authorization",
"Content-Type"
],
"allowedMethods": [
"GET"
],
"allowedCredentials": false,
"maxAge": 1728000
},
"defaultConfiguration": {
"allowedOrigins": [
".*"
],
"allowedOriginPatterns": [
],
"allowedUris": [
".*"
],
"allowedUriPatterns": [
],
"allowedHeaders": [
"Accept",
"Authorization",
"Content-Type"
],
"allowedMethods": [
"GET"
],
"allowedCredentials": false,
"maxAge": 1728000
}
},
"links": {
"logout": {
"redirectUrl": "/login",
"redirectParameterName": "redirect",
"disableRedirectParameter": false,
"whitelist": null
},
"selfService": {
"selfServiceLinksEnabled": true,
"signup": null,
"passwd": null
}
},
"prompts": [
{
"name": "username",
"type": "text",
"text": "Email"
},
{
"name": "password",
"type": "password",
"text": "Password"
},
{
"name": "passcode",
"type": "password",
"text": "Temporary Authentication Code (Get on at /passcode)"
}
],
"idpDiscoveryEnabled": false,
"accountChooserEnabled": false,
"userConfig": {
"defaultGroups": [
"openid",
"password.write",
"uaa.user",
"approvals.me",
"profile",
"roles",
"user_attributes",
"uaa.offline_token"
]
}
},
"name": "Demo Login Page",
"version": 1,
"description": "{\"plan_display_name\":\"Demo\",\"plan_description\":\"Demo SSO Plan\"}",
"created": 1503504273000,
"last_modified": 1504898224000
}

0 comments on commit 849e43d

Please sign in to comment.