Skip to content

Commit

Permalink
Fix error messages in browser console, and ignore cookies with no cac…
Browse files Browse the repository at this point in the history
…he entry.
  • Loading branch information
at88mph committed Feb 6, 2024
1 parent 8a9a7f1 commit 75e6adb
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# tags with and without build number so operators use the versioned
# tag but we always keep a timestamped tag in case a semantic tag gets
# replaced accidentally
VER=0.2.1
VER=0.2.2
TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")"
unset VER
8 changes: 6 additions & 2 deletions public/dev/js/science_portal_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@
return parseFloat(matches.map(m => m[1])[0]).toFixed(2)
}

function zeroPrefix(value) {
return ("0" + value).slice(-2)
}

function loadPlatformUsage(refreshHandler) {
var statsURL = _selfPortalSess.sessionServiceURL + "?view=stats"
Promise.resolve(_getAjaxData(statsURL, {}))
Expand All @@ -312,8 +316,8 @@
var nowDate = new Date()
var month = nowDate.getUTCMonth() + 1
_selfPortalSess._platformUsage.updated = nowDate.getUTCFullYear() + "-"
+ ("0" + month).slice(-2) + "-" + ("0" + nowDate.getUTCDate()).slice(-2)
+ " " + nowDate.getUTCHours() + ":" + nowDate.getMinutes()
+ zeroPrefix(month) + "-" + zeroPrefix(nowDate.getUTCDate())
+ " " + zeroPrefix(nowDate.getUTCHours()) + ":" + zeroPrefix(nowDate.getMinutes())

_selfPortalSess._platformUsage.cpu = {
"used" : platformUsage.cores.requestedCPUCores,
Expand Down
1 change: 0 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class SciencePortalApp extends React.Component {
<Card>
<Card.Body>
<Row><Col>
<div className="sp-title sp-panel-heading">New Session <span class="sp-header-button small"><a class="small" href="https://www.opencadc.org/science-containers/">Help</a></span></div>
<div className="sp-title sp-panel-heading">New Session <span className="sp-header-button small"><a className="small" href="https://www.opencadc.org/science-containers/">Help</a></span></div>
{ this.state.pageState.spForm.progressBar.animated === true && <ProgressBar variant={this.state.pageState.spForm.progressBar.type} now={100}
animated className="sp-progress-bar" /> }
{ this.state.pageState.spForm.progressBar.animated === false && <ProgressBar variant={this.state.pageState.spForm.progressBar.type} now={100} className="sp-progress-bar" /> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@
import ca.nrc.cadc.rest.InlineContentHandler;
import ca.nrc.cadc.rest.RestAction;
import ca.nrc.cadc.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opencadc.token.Client;

import javax.security.auth.Subject;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.NoSuchElementException;

/**
* Base class to support storing the OIDC Access Token in a cookie.
Expand All @@ -93,6 +96,8 @@
* TODO: jenkinsd 2023.10.20
*/
public abstract class SciencePortalAuthAction extends RestAction {
private static final Logger LOGGER = LogManager.getLogger(SciencePortalAuthAction.class);

protected final ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();

protected Client getOIDCClient() throws IOException {
Expand All @@ -116,15 +121,20 @@ protected Subject getCurrentSubject() throws Exception {
// Only split on the first "=" symbol, and trim any wrapping double quotes
final String encryptedCookieValue =
cookie.split("=", 2)[1].replaceAll("\"", "");
final String accessToken = getOIDCClient().getAccessToken(encryptedCookieValue);

subject.getPrincipals().add(new AuthorizationTokenPrincipal(AuthenticationUtil.AUTHORIZATION_HEADER,
AuthenticationUtil.CHALLENGE_TYPE_BEARER
+ " " + accessToken));
subject.getPublicCredentials().add(
new AuthorizationToken(AuthenticationUtil.CHALLENGE_TYPE_BEARER, accessToken,
Collections.singletonList(
URI.create(syncInput.getRequestURI()).getHost())));
try {
final String accessToken = getOIDCClient().getAccessToken(encryptedCookieValue);

subject.getPrincipals().add(new AuthorizationTokenPrincipal(AuthenticationUtil.AUTHORIZATION_HEADER,
AuthenticationUtil.CHALLENGE_TYPE_BEARER
+ " " + accessToken));
subject.getPublicCredentials().add(
new AuthorizationToken(AuthenticationUtil.CHALLENGE_TYPE_BEARER, accessToken,
Collections.singletonList(
URI.create(syncInput.getRequestURI()).getHost())));
} catch (NoSuchElementException noTokenForKeyInCacheException) {
LOGGER.warn("Cookie found and decrypted but no value in cache. Ignoring cookie...");
}
}

if (!subject.getPrincipals(AuthorizationTokenPrincipal.class).isEmpty()) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
final ApplicationConfiguration configuration = new ApplicationConfiguration();
final String sessionsResourceID = configuration.getResourceID();
final String sessionsStandardID = configuration.getStandardID();
final String themeName = configuration.getThemeName();
String bannerText = configuration.getBannerMessage();
String headerURLJSON = configuration.getHeaderURLs().toString();
Expand Down Expand Up @@ -46,9 +47,11 @@
<script type="text/javascript" src="https://www.canfar.net/cadcJS/javascript/cadc.user.js"></script>
<script type="text/javascript" src="https://www.canfar.net/canfar/javascript/cadc.redirect.util.js"></script>

<% if ("canfar".equals(themeName)) { %>
<!-- Adding gdpr cookie banner -->
<script type="text/javascript" src="https://www.canfar.net/cadcJS/javascript/cadc.gdpr.cookie.js"></script>
<link type="text/css" href="https://www.canfar.net/canfar/css/cadc.gdpr.cookie.css" rel="stylesheet" media="screen">
<% } %>

<!--[if lt IE 9]>
<!-- <script src="/html5shiv.googlecode.com/svn/trunk/html5.js"></script>-->
Expand Down Expand Up @@ -99,10 +102,9 @@
baseURL: window.location.origin,
sessionsResourceID: '<%= sessionsResourceID %>',
sessionsStandardID: '<%= sessionsStandardID %>',
themeName: '<%= configuration.getThemeName() %>',
themeName: '<%= themeName %>',
bannerText: '<%= bannerText %>',
contentBase: "${contextPath}/dist",
themeName: '<%= configuration.getThemeName() %>',
headerURLs: JSON.parse('<%= headerURLJSON %>')
})
Expand Down
2 changes: 1 addition & 1 deletion src/react/canfar/CanfarLoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CanfarLoginModal extends React.Component {
{errMsg}
<a href={this.state.modalURLs.passreset}
className="account_access_info"
tabIndex="5" className="account_access_info" title="Forgot Password">
tabIndex="5" title="Forgot Password">
Forgot your Account information?</a>
<br/>
<a href={this.state.modalURLs.acctrequest}
Expand Down
2 changes: 1 addition & 1 deletion src/react/src/SRCLoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SRCLoginModal extends React.Component {
<Modal.Title className="sp-modal-header">Authentication required</Modal.Title>
</Modal.Header>
<Modal.Body className="sp-auth-form-body">
<a class="btn btn-primary" href="/science-portal/oidc-login">Sign In to OpenID Connect</a>
<a className="btn btn-primary" href="/science-portal/oidc-login">Sign In to OpenID Connect</a>
</Modal.Body>
</Modal>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/react/src/SRCNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SRCNavbar extends React.Component {
<Navbar.Brand><img src="/science-portal/images/SRCNetLogo.png" style={{maxWidth: 256 + 'px'}}></img></Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
{this.state.isAuthenticated === true &&
<span class="display-name" align="end">{this.state.authenticatedUser}</span>
<span className="display-name" align="end">{this.state.authenticatedUser}</span>
}
</Container>
</Navbar>
Expand Down

0 comments on commit 75e6adb

Please sign in to comment.