Skip to content

Commit

Permalink
fix: UAA login page breaks when the product logo images is over 10000…
Browse files Browse the repository at this point in the history
…0 characters

- UAA log contained the following message:
```
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1078E: Concatenated string is too long, exceeding the threshold of '100,000' characters
```
- Moved the concatenation code from html templates, that are subject to Spring Expression Language, to Java code.

[#185950696]
[original story: #185894942]

Co-authored-by: Peter Chen <peterch@vmware.com>
Co-authored-by: Danny Faught <dfaught@vmware.com>
Co-authored-by: Alicia Yingling <yalicia@vmware.com>
Co-authored-by: Bruce Ricard <bricard@vmware.com>
  • Loading branch information
5 people committed Sep 14, 2023
1 parent 149d081 commit 96f6f08
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public String getProductLogo() {
return tryGet(IdentityZoneHolder.get(), BrandingInformationSource::getProductLogo).orElse(null);
}

public String getInlinedBase64PngLogo() {
String logo = getProductLogo();
if ( logo != null ) {
logo = "data:image/png;base64," + logo;
}
return logo;
}

@Override
public String getSquareLogo() {
return resolve(BrandingInformationSource::getSquareLogo);
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/resources/templates/web/layouts/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
copyrightCompanyName=${branding.getCompanyName() ?: 'CloudFoundry.org Foundation, Inc. '},
copyrightFallback=${'Copyright &#169; ' + copyrightCompanyName + ' ' + #dates.year(#dates.createNow()) + '. All Rights Reserved.'},
copyright=${branding.getFooterLegalText() ?: copyrightFallback},
brandingLogo=${branding.getProductLogo()},
brandingLogo=${branding.getInlinedBase64PngLogo()},
fallbackLogo=${isUaa ? assetBaseUrl+'/images/product-logo.png' : null},
logo=${brandingLogo != null ? 'data:image/png;base64,'+#strings.replace(brandingLogo,T(java.lang.System).getProperty('line.separator'),'') : fallbackLogo}" >
logo=${brandingLogo != null ? #strings.replace(brandingLogo,T(java.lang.System).getProperty('line.separator'),'') : fallbackLogo}" >
<head>
<title th:text="${isUaa ? companyName : zoneName}" th:inline="text"></title>
<link href='/resources/oss/images/square-logo.png' th:with="icon=${branding.getSquareLogo()}" th:href="@{${icon != null ? 'data:image/png;base64,'+icon : (assetBaseUrl + '/images/square-logo.png')}}" rel='shortcut icon' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="login-email panel panel-basic bg-neutral-11 mvxl paxl">
<div class="panel-body">
<div class="txt-c paxl">
<img class="img-responsive logo" th:with="logo=${branding.getProductLogo()},defaultLogo=@{${assetBaseUrl+'/images/product-logo.png'}}" th:src="${logo != null ? 'data:image/png;base64,'+logo : defaultLogo}" src="/resources/oss/images/product-logo.png"/>
<img class="img-responsive logo" th:with="logo=${branding.getInlinedBase64PngLogo()},defaultLogo=@{${assetBaseUrl+'/images/product-logo.png'}}" th:src="${logo != null ? logo : defaultLogo}" src="/resources/oss/images/product-logo.png"/>
<h1 class="img-responsive" th:if="!${isUaa}" th:text="${zone_name}">Cloud Foundry</h1>
</div>
<div layout:fragment="page-content"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="mfa panel panel-basic bg-neutral-11 mvxl paxl">
<div class="panel-body">
<div class="txt-c paxl">
<img class="img-responsive logo" th:with="logo=${branding.getProductLogo()},defaultLogo=@{${assetBaseUrl+'/images/product-logo.png'}}" th:src="${logo != null ? 'data:image/png;base64,'+logo : defaultLogo}" src="/resources/oss/images/product-logo.png"/>
<img class="img-responsive logo" th:with="logo=${branding.getInlinedBase64PngLogo()},defaultLogo=@{${assetBaseUrl+'/images/product-logo.png'}}" th:src="${logo != null ? logo : defaultLogo}" src="/resources/oss/images/product-logo.png"/>
<h1 class="img-responsive" th:if="!${isUaa}" th:text="${zone_name}">Cloud Foundry</h1>
</div>
<div layout:fragment="page-content"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,15 @@ void testCustomFavIcon() throws Exception {
.andExpect(content().string(allOf(containsString("<link href='data:image/png;base64,/sM4lL==' rel='shortcut icon' />"), not(containsString("square-logo.png")))));
}

@Test
void testProductLogoOver100kChars() throws Exception {
String bigLogo = new String(new char[150000]).replace('\0', 'x');
setZoneFavIconAndProductLogo(webApplicationContext, identityZoneConfiguration, null, bigLogo);

mockMvc.perform(get("/login"))
.andExpect(content().string(allOf(containsString("<style>.header-image {background-image: url(data:image/png;base64," + bigLogo + ");}</style>"), not(containsString("product-logo.png")))));
}

@Test
void testCustomFavIcon_With_LineBreaks() throws Exception {
setZoneFavIconAndProductLogo(webApplicationContext, identityZoneConfiguration, "/sM4\n\nlL==", "/sM4\n\nlL==");
Expand Down

0 comments on commit 96f6f08

Please sign in to comment.