Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
encyclopedia-gui
Commits
478e0d3e
Commit
478e0d3e
authored
Jul 22, 2020
by
Lauri Himanen
Browse files
Simplified KeyCloak authentication, enabled the error reporting tab in GUI.
parent
a8382fd0
Pipeline
#79143
skipped with stage
Changes
6
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
client/bundle.js
View file @
478e0d3e
This diff is collapsed.
Click to expand it.
client/index.html
View file @
478e0d3e
...
...
@@ -12,7 +12,6 @@
<script
defer
src=
"conf.js"
></script>
<script
defer
src=
"keycloak.min.js"
></script>
<script
defer
src=
"loadkeycloak.js"
></script>
<script
defer
src=
"lib/3d-viewers/three.min.js"
></script>
<script
defer
src=
"lib/3d-viewers/orthographiccontrols.js"
></script>
<script
defer
src=
"lib/3d-viewers/matviewer.min.js"
></script>
...
...
client/loadkeycloak.js
deleted
100644 → 0
View file @
a8382fd0
// This separate script is used to handle the login procedure before loading
// the application. As of 0.8.3 nomad-FAIR is using KeyCloak 7.0.0, which does
// not support the "silentCheckSsoRedirectUri" option. This option enables a
// silent login check that does not enforce reloads. In order to do such silent
// login, the Javascript adapter for KeyCloak 8.0.0 is used instead. This is
// against the best practice of directly downloading the Javascript adapter
// from the authentication server (window.nomadEnv.keycloakBase +
// "js/keycloak.min.js"), but is in this case acceptable as it result is a much
// smoother user experience.
var
keycloak
=
new
Keycloak
({
url
:
window
.
nomadEnv
.
keycloakBase
,
realm
:
window
.
nomadEnv
.
keycloakRealm
,
clientId
:
window
.
nomadEnv
.
keycloakClientId
});
let
loginButton
=
document
.
querySelector
(
'
#login-button
'
);
let
logoutButton
=
document
.
querySelector
(
'
#logout-button
'
);
let
userName
=
document
.
querySelector
(
'
#user-name
'
);
keycloak
.
init
({
onLoad
:
"
check-sso
"
,
silentCheckSsoRedirectUri
:
`
${
window
.
nomadEnv
.
guiRoot
}
silent-check-sso.html`
,
promiseType
:
"
native
"
,
}).
then
((
authenticated
)
=>
{
if
(
authenticated
)
{
keycloak
.
loadUserProfile
()
.
then
(
function
(
profile
)
{
userName
.
textContent
=
`
${
profile
.
firstName
}
${
profile
.
lastName
}
`
;
loginButton
.
style
.
display
=
'
none
'
;
logoutButton
.
style
.
display
=
'
inline
'
;
}).
catch
(
function
()
{
console
.
log
(
'
Failed to load user profile.
'
);
});
}
else
{
loginButton
.
style
.
display
=
'
inline
'
;
logoutButton
.
style
.
display
=
'
none
'
;
userName
.
textContent
=
"
Guest
"
;
}
});
loginButton
.
onclick
=
()
=>
{
keycloak
.
login
({
redirectUri
:
`
${
window
.
nomadEnv
.
guiRoot
}
#/search`
})
.
catch
(()
=>
{
console
.
log
(
"
Authentication error.
"
)})
};
logoutButton
.
onclick
=
()
=>
{
keycloak
.
logout
()
};
client/src/common/Router.js
View file @
478e0d3e
...
...
@@ -43,12 +43,6 @@ function route() {
if
(
hashPath
.
lastIndexOf
(
'
/
'
)
===
(
hashPath
.
length
-
1
))
hashPath
=
hashPath
.
substring
(
0
,
hashPath
.
length
-
1
);
// Remove state parameters from authentication
let
stateIndex
=
hashPath
.
indexOf
(
'
&state
'
);
if
(
stateIndex
!=
-
1
)
{
hashPath
=
hashPath
.
substring
(
0
,
stateIndex
);
}
if
(
hashPath
.
indexOf
(
'
/
'
)
>
0
){
let
a
=
hashPath
.
split
(
'
/
'
);
command
=
a
[
0
];
...
...
client/src/common/util.js
View file @
478e0d3e
...
...
@@ -86,12 +86,10 @@ function getCalcMapByFunctional(summaryCalcSet) {
if
(
functCalcMap
.
has
(
calc
.
functional_type
))
{
functCalcMap
.
get
(
calc
.
functional_type
).
add
(
calc
.
calc_id
);
}
else
{
// New functional, not build if value is unavailable
if
(
calc
.
functional_type
!==
"
unavailable
"
)
{
let
newFunctionalArray
=
new
Set
();
newFunctionalArray
.
add
(
calc
.
calc_id
);
functCalcMap
.
set
(
calc
.
functional_type
,
newFunctionalArray
);
}
}
else
{
// New functional
let
newFunctionalArray
=
new
Set
();
newFunctionalArray
.
add
(
calc
.
calc_id
);
functCalcMap
.
set
(
calc
.
functional_type
,
newFunctionalArray
);
}
});
return
functCalcMap
;
...
...
client/src/main.js
View file @
478e0d3e
...
...
@@ -41,16 +41,70 @@ let DataStore = require('./material-mod/DataStore.js');
let
contentElement
=
document
.
getElementById
(
'
content
'
);
let
titleElement
=
document
.
querySelector
(
'
title
'
);
// As of 0.8.3 nomad-FAIR is using KeyCloak 7.0.0, which does
// not support the "silentCheckSsoRedirectUri" option. This option enables a
// silent login check that does not enforce reloads. In order to do such silent
// login, the Javascript adapter for KeyCloak 8.0.0 is used instead. This is
// against the best practice of directly downloading the Javascript adapter
// from the authentication server (window.nomadEnv.keycloakBase +
// "js/keycloak.min.js"), but is in this case acceptable as it result is a much
// smoother user experience.
PubSub
.
subscribe
(
'
authenticated
'
,
data
=>
{
let
hashPath
=
document
.
location
.
hash
.
substring
(
2
);
if
(
hashPath
.
lastIndexOf
(
'
/
'
)
===
(
hashPath
.
length
-
1
))
hashPath
=
hashPath
.
substring
(
0
,
hashPath
.
length
-
1
);
if
(
hashPath
.
indexOf
(
'
/
'
)
>
0
){
let
command
=
hashPath
.
split
(
'
/
'
)[
0
];
if
(
command
===
"
material
"
)
{
flaggingTab
.
style
.
visibility
=
'
visible
'
;
}
}
});
var
keycloak
=
new
Keycloak
({
url
:
window
.
nomadEnv
.
keycloakBase
,
realm
:
window
.
nomadEnv
.
keycloakRealm
,
clientId
:
window
.
nomadEnv
.
keycloakClientId
});
let
loginButton
=
document
.
querySelector
(
'
#login-button
'
);
let
logoutButton
=
document
.
querySelector
(
'
#logout-button
'
);
let
userName
=
document
.
querySelector
(
'
#user-name
'
);
keycloak
.
init
({
onLoad
:
"
check-sso
"
,
silentCheckSsoRedirectUri
:
`
${
window
.
nomadEnv
.
guiRoot
}
silent-check-sso.html`
,
promiseType
:
"
native
"
,
}).
then
((
authenticated
)
=>
{
if
(
authenticated
)
{
keycloak
.
loadUserProfile
()
.
then
(
function
(
profile
)
{
userName
.
textContent
=
`
${
profile
.
firstName
}
${
profile
.
lastName
}
`
;
loginButton
.
style
.
display
=
'
none
'
;
logoutButton
.
style
.
display
=
'
inline
'
;
PubSub
.
publish
(
'
authenticated
'
);
}).
catch
(
function
()
{
console
.
log
(
'
Failed to load user profile.
'
);
});
//util.setAuthRequestHeader(data.user, data.token.data);
}
else
{
loginButton
.
style
.
display
=
'
inline
'
;
logoutButton
.
style
.
display
=
'
none
'
;
userName
.
textContent
=
"
Guest
"
;
}
});
loginButton
.
onclick
=
()
=>
{
keycloak
.
login
({
redirectUri
:
`
${
window
.
nomadEnv
.
guiRoot
}
#/search`
})
.
catch
(()
=>
{
console
.
log
(
"
Authentication error.
"
);});
};
logoutButton
.
onclick
=
()
=>
{
keycloak
.
logout
();
};
/********* User flagging side tab ****************/
/* This side vertical tab is hidden initially
but it has to be set up when the app starts */
let
flaggingTab
=
document
.
getElementById
(
'
calc-flagging-tab
'
);
flaggingTab
.
style
.
top
=
(
window
.
innerHeight
/
2
)
+
'
px
'
;
flaggingTab
.
addEventListener
(
'
click
'
,
e
=>
{
FlaggingFormPopup
.
show
(
MaterialModule
.
getCurrentPageStatus
());
});
...
...
@@ -188,14 +242,18 @@ PubSub.subscribe('show-material', data => {
// In case the app comes from the search module through the url (back button)
UserGuidance
.
show
(
false
);
//console.log('User data:',util.getUserData());
if
(
util
.
getUserData
()
!==
null
)
flaggingTab
.
style
.
visibility
=
'
visible
'
;
// When a logged user comes to a material page, the error reporting tab is shown.
if
(
keycloak
.
authenticated
)
{
flaggingTab
.
style
.
visibility
=
'
visible
'
;
}
});
PubSub
.
subscribe
(
'
show-search
'
,
search
=>
{
console
.
log
(
'
Handling event show-search:
'
+
search
);
// When a logged user comes to a material page, the error reporting tab is shown.
flaggingTab
.
style
.
visibility
=
'
hidden
'
;
titleElement
.
innerHTML
=
'
NOMAD Encyclopedia - Search
'
;
breadcrumb
.
setState
(
'
search
'
,
search
);
...
...
@@ -203,13 +261,10 @@ PubSub.subscribe('show-search', search => {
searchMod
.
showSearchPage
();
LoadingPopup
.
hide
();
// In case it comes from the result page
}
else
if
(
search
===
'
results
'
)
}
else
if
(
search
===
'
results
'
)
searchMod
.
showResultsPage
();
showModuleDOM
(
searchMod
.
element
);
if
(
flaggingTab
.
style
.
visibility
!==
'
hidden
'
)
flaggingTab
.
style
.
visibility
=
'
hidden
'
;
});
...
...
@@ -226,38 +281,16 @@ Router.route();
let
userNameElement
=
document
.
querySelector
(
'
#user-name
'
);
//function setAppAuthenticated(data){
//if (data.status === 'Authenticated'){
//userNameElement.innerHTML = data.user.username;
//document.querySelector('#guest-user').style.display = 'none';
//document.querySelector('#auth-user').style.display = 'inline';
//util.setAuthRequestHeader(data.user, data.token.data);
//if (currentModule === materialModDOM) flaggingTab.style.visibility = 'visible';
//}
//}
//function logout(){
//userNameElement.innerHTML = '';
//util.setAuthRequestHeader();
//if (flaggingTab.style.visibility !== 'hidden')
//flaggingTab.style.visibility = 'hidden';
//}
function
getCookie
(
name
)
{
let
value
=
"
;
"
+
document
.
cookie
;
let
parts
=
value
.
split
(
"
;
"
+
name
+
"
=
"
);
if
(
parts
.
length
===
2
)
return
parts
.
pop
().
split
(
"
;
"
).
shift
();
}
function
parseCookie
(
userData
)
{
return
userData
.
substring
(
1
,
userData
.
length
-
1
).
replace
(
/
\\
054/g
,
'
,
'
).
replace
(
/
\\
/g
,
''
);
}
let
userInfoCookie
=
getCookie
(
'
user_info
'
);
if
(
userInfoCookie
!==
undefined
){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment