Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/frontend/icons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import archiveBox from 'heroicons/24/outline/archive-box.svg';
import adjustmentsHorizontal from 'heroicons/24/outline/adjustments-horizontal.svg';
import arrowDownTray from 'heroicons/24/outline/arrow-down-tray.svg';
import arrowPath from 'heroicons/24/outline/arrow-path.svg';
import arrowLeft from 'heroicons/24/outline/arrow-left.svg';
import arrowRightEndOnRectangle from 'heroicons/24/outline/arrow-right-end-on-rectangle.svg';
import arrowRightStartOnRectangle from 'heroicons/24/outline/arrow-right-start-on-rectangle.svg';
import arrowRight from 'heroicons/24/outline/arrow-right.svg';
Expand Down Expand Up @@ -52,6 +53,7 @@ import shieldExclamation from 'heroicons/24/outline/shield-exclamation.svg';
import squares2x2 from 'heroicons/24/outline/squares-2x2.svg';
import tableCells from 'heroicons/24/outline/table-cells.svg';
import trash from 'heroicons/24/outline/trash.svg';
import identification from 'heroicons/24/outline/identification.svg';
import userCircle from 'heroicons/24/outline/user-circle.svg';
import userPlus from 'heroicons/24/outline/user-plus.svg';
import users from 'heroicons/24/outline/users.svg';
Expand All @@ -67,6 +69,7 @@ export const ICONS = {
'arrow-down-tray': arrowDownTray,
'arrow-path': arrowPath,
'arrow-right-end-on-rectangle': arrowRightEndOnRectangle,
'arrow-left': arrowLeft,
'arrow-right-start-on-rectangle': arrowRightStartOnRectangle,
'arrow-right': arrowRight,
'arrow-up': arrowUp,
Expand Down Expand Up @@ -115,6 +118,7 @@ export const ICONS = {
sun,
'table-cells': tableCells,
trash,
'identification': identification,
'user-circle': userCircle,
'user-plus': userPlus,
users,
Expand Down
6 changes: 6 additions & 0 deletions src/main/frontend/s3webui.css
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@
@apply border-t;
}
/* The card is a flex column capped to the viewport: header and footer stay pinned, only the body scrolls. */
.session-search-bar {
@apply sticky -top-4 z-10 -mx-4 bg-white px-4 pb-3 pt-1;
}
html[data-theme='dark'] .session-search-bar {
@apply bg-slate-900;
}
.modal-body {
@apply min-h-0 overflow-y-auto overscroll-contain p-4;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/frontend/s3webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ window.ensureS3ConfigDialog = ensureS3SessionDialog;
window.openS3SessionDialog = async () => { const status = await loadS3SessionStatus(); if (status) renderS3SessionDialog(status, true); };
function renderS3SessionDialog(status, dismissible) {
const list = document.getElementById('s3SessionKeyList'); list.innerHTML = '';
status.credentials.forEach(credential => { const item = document.createElement('div'); item.className='session-key'; if (credential.id === status.activeCredentialId) item.classList.add('active'); const select = document.createElement('button'); select.type='button'; select.className='session-key-select'; select.onclick=()=>switchCredential(credential.id); select.innerHTML=`<i data-icon="${credential.builtIn?'server-stack':'key'}"></i><span><strong>${escapeMarkup(credential.name)}</strong><small>${escapeMarkup([credential.endpointUrl,credential.region].filter(Boolean).join(' · '))}</small></span>`; item.appendChild(select); if (status.allowUsersToRevealKeys || credential.allowReveal) { const reveal = document.createElement('button'); reveal.type='button'; reveal.className='btn-icon shrink-0'; reveal.title='Reveal access and secret key'; reveal.setAttribute('aria-label', reveal.title); reveal.innerHTML='<i data-icon="eye"></i>'; reveal.onclick=()=>revealS3Credential(credential.id); item.appendChild(reveal); } list.appendChild(item); });
document.getElementById('s3SessionKeys')?.classList.toggle('hidden', !status.credentials.length); document.getElementById('s3SessionNoKeys')?.classList.toggle('hidden', !!status.credentials.length); document.getElementById('s3SessionOwn')?.classList.toggle('hidden', !status.allowOwnCredentials); document.getElementById('s3SessionClose')?.classList.toggle('hidden', !dismissible); hideS3SessionError(); openDialog('s3SessionModal'); refreshIcons();
status.credentials.forEach(credential => { const item = document.createElement('div'); item.className='session-key'; item.dataset.search=[credential.name,credential.endpointUrl,credential.region,status.accessKeys?.[credential.id]].filter(Boolean).join(' ').toLowerCase(); if (credential.id === status.activeCredentialId) item.classList.add('active'); const select = document.createElement('button'); select.type='button'; select.className='session-key-select'; select.onclick=()=>switchCredential(credential.id); select.innerHTML=`<i data-icon="${credential.builtIn?'server-stack':'key'}"></i><span><strong>${escapeMarkup(credential.name)}</strong><small>${escapeMarkup([credential.endpointUrl,credential.region].filter(Boolean).join(' · '))}</small></span>`; item.appendChild(select); if (status.allowUsersToRevealKeys || credential.allowReveal) { const reveal = document.createElement('button'); reveal.type='button'; reveal.className='btn-icon shrink-0'; reveal.title='Reveal access and secret key'; reveal.setAttribute('aria-label', reveal.title); reveal.innerHTML='<i data-icon="eye"></i>'; reveal.onclick=()=>revealS3Credential(credential.id); item.appendChild(reveal); } list.appendChild(item); });
document.getElementById('s3SessionKeys')?.classList.toggle('hidden', !status.credentials.length); document.getElementById('s3SessionNoKeys')?.classList.toggle('hidden', !!status.credentials.length); document.getElementById('s3SessionClose')?.classList.toggle('hidden', !dismissible); hideS3SessionError(); const search=document.getElementById('s3SessionSearch'); if (search) { search.value=''; search.parentElement.classList.toggle('hidden', status.credentials.length<2); } filterS3SessionKeys(); const hasKeys=status.credentials.length>0; document.getElementById('s3SessionOwnToggle')?.classList.toggle('hidden', !(status.allowOwnCredentials && hasKeys)); setS3OwnMode(status.allowOwnCredentials && !hasKeys); openDialog('s3SessionModal'); refreshIcons(); if (!s3OwnMode && search && status.credentials.length>=2) search.focus();
}
let s3OwnMode=false;
function setS3OwnMode(on) { s3OwnMode=on; document.getElementById('s3SessionPick')?.classList.toggle('hidden', on); document.getElementById('s3SessionOwn')?.classList.toggle('hidden', !on); document.getElementById('s3SessionOwnIcon')?.classList.toggle('hidden', on); document.getElementById('s3SessionKeysIcon')?.classList.toggle('hidden', !on); const label=document.getElementById('s3SessionOwnToggleLabel'); if (label) label.textContent=on?'Back to stored keys':'Use your own credentials'; hideS3SessionError(); }
window.toggleS3OwnCredentials = () => { setS3OwnMode(!s3OwnMode); if (s3OwnMode) document.getElementById('s3AccessKey')?.focus(); };
window.filterS3SessionKeys = () => { const query=(document.getElementById('s3SessionSearch')?.value||'').trim().toLowerCase(); const items=[...document.querySelectorAll('#s3SessionKeyList .session-key')]; let visible=0; items.forEach(item => { const show=!query||(item.dataset.search||'').includes(query); item.classList.toggle('hidden',!show); if(show)visible++; }); document.getElementById('s3SessionNoMatch')?.classList.toggle('hidden', !items.length||visible>0); };
async function switchCredential(credentialId, options={}) { try { const response=await apiFetch('/api/s3/session',{method:'POST',headers:{'Content-Type':'application/json',Accept:'application/json'},body:JSON.stringify({credentialId})}); if(response.ok)return location.reload(); const message=await getResponseErrorMessage(response,'Unable to select that S3 key'); options.silent?showToast(message,'danger'):showS3SessionError(message); } catch(error){showS3SessionError(error.message||'Unable to select that S3 key');} }
async function revealS3Credential(credentialId) { try { const response=await apiFetch(`/api/s3/session/credentials/${encodeURIComponent(credentialId)}/reveal`,{headers:{Accept:'application/json'}}); if(!response.ok) return showS3SessionError(await getResponseErrorMessage(response,'Unable to reveal that S3 key')); const credential=await response.json(); document.getElementById('s3RevealKeyTitle').textContent=`Keys for ${credential.name}`; document.getElementById('s3RevealedAccessKey').value=credential.accessKey; document.getElementById('s3RevealedSecretKey').value=credential.secretKey; openDialog('s3RevealKeyModal'); refreshIcons(); } catch(error){showS3SessionError(error.message||'Unable to reveal that S3 key');} }
window.closeS3RevealKeyDialog = () => closeDialog('s3RevealKeyModal');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import tech.wenisch.s3webui.service.GlobalSearchService;

import java.util.List;
import java.util.Map;

/**
* Drives the key picker shown after sign-in and the switcher in the navbar.
Expand All @@ -40,7 +41,8 @@ public SessionStatusResponse getStatus() {
s3ConnectionSettingsService.getActiveCredentialName(),
s3ConnectionSettingsService.isUserSuppliedCredentialsAllowed(),
s3ConnectionSettingsService.areUsersAllowedToRevealKeys(),
s3ConnectionSettingsService.listAvailableCredentials()
s3ConnectionSettingsService.listAvailableCredentials(),
s3ConnectionSettingsService.listSearchableAccessKeys()
);
}

Expand Down Expand Up @@ -89,7 +91,8 @@ public record SessionStatusResponse(
String activeCredentialName,
boolean allowOwnCredentials,
boolean allowUsersToRevealKeys,
List<S3CredentialView> credentials
List<S3CredentialView> credentials,
Map<String, String> accessKeys
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import tech.wenisch.s3webui.model.S3CredentialView;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* Holds the S3 key the current user picked for this browser session and turns it into the settings
Expand Down Expand Up @@ -44,6 +46,22 @@ public List<S3CredentialView> listAvailableCredentials() {
return credentialAccessService.listAccessible(currentAuthentication());
}

/**
* Access keys of the available keys, by key id, for the key picker's search box. Only keys the user may
* reveal are included, so searching never exposes an access key that the reveal setting withholds.
*/
public Map<String, String> listSearchableAccessKeys() {
Authentication authentication = currentAuthentication();
boolean revealForAll = appSettingsService.areUsersAllowedToRevealKeys();
Map<String, String> accessKeys = new LinkedHashMap<>();
for (S3CredentialView view : credentialAccessService.listAccessible(authentication)) {
if (revealForAll || view.allowReveal()) {
accessKeys.put(view.id(), credentialAccessService.resolve(authentication, view.id()).accessKey());
}
}
return accessKeys;
}

public boolean isUserSuppliedCredentialsAllowed() {
return appSettingsService.isUserSuppliedCredentialsAllowed();
}
Expand Down
49 changes: 46 additions & 3 deletions src/main/resources/templates/fragments/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
aria-modal="true"
aria-labelledby="s3SessionTitle"
>
<div class="modal-card">
<div class="modal-card max-w-2xl!">
<div class="modal-header">
<div>
<p class="eyebrow">Storage session</p>
Expand All @@ -147,12 +147,36 @@ <h2 id="s3SessionTitle" class="modal-title">Choose an S3 key</h2>
Select a key granted to your account, or connect with your own credentials when allowed.
</p>
<div id="s3SessionError" class="alert alert-error hidden mb-3"></div>
<div id="s3SessionKeys"><div id="s3SessionKeyList" class="grid gap-2"></div></div>
<div id="s3SessionPick">
<div id="s3SessionKeys">
<div class="session-search-bar">
<input
id="s3SessionSearch"
class="input"
type="search"
placeholder="Search keys by name, endpoint or access key"
aria-label="Search S3 keys"
autocomplete="off"
oninput="filterS3SessionKeys()"
/>
</div>
<div id="s3SessionKeyList" class="grid gap-2"></div>
<p id="s3SessionNoMatch" class="empty-state hidden p-4 text-sm">No keys match your search.</p>
</div>
<div id="s3SessionNoKeys" class="empty-state hidden p-6">
<i data-icon="key" class="mx-auto"></i>
<p class="mt-2 text-sm">No stored S3 keys are available to this account.</p>
<p class="mt-1 text-sm text-slate-500" th:if="${isAdmin}">
Add an S3 key in the
<a class="font-medium text-teal-700 underline hover:no-underline" th:href="@{/admin/settings}">settings</a>
to get started.
</p>
<p class="mt-1 text-sm text-slate-500" th:unless="${isAdmin}">
Ask an administrator to grant you a key.
</p>
</div>
</div>
<div id="s3SessionOwn" class="mt-5 border-t pt-5">
<div id="s3SessionOwn" class="hidden">
<h3 class="mb-3 text-base font-semibold">Use your own credentials</h3>
<div class="grid gap-3 sm:grid-cols-2">
<label>
Expand Down Expand Up @@ -188,6 +212,25 @@ <h3 class="mb-3 text-base font-semibold">Use your own credentials</h3>
</button>
</div>
</div>
<div id="s3SessionFooter" class="modal-footer flex-wrap border-t">
<button id="s3SessionOwnToggle" class="btn-secondary hidden" type="button" onclick="toggleS3OwnCredentials()">
<span id="s3SessionOwnIcon"><i data-icon="identification" aria-hidden="true"></i></span>
<span id="s3SessionKeysIcon" class="hidden"><i data-icon="arrow-left" aria-hidden="true"></i></span>
<span id="s3SessionOwnToggleLabel">Use your own credentials</span>
</button>
<div class="ml-auto flex flex-wrap items-center justify-end gap-2">
<a th:if="${isAdmin}" class="btn-secondary" th:href="@{/admin/settings}">
<i data-icon="cog-6-tooth" aria-hidden="true"></i>
Go to settings
</a>
<form th:if="${!authenticationDisabled}" th:action="@{/logout}" method="post">
<button class="btn-secondary" type="submit">
<i data-icon="arrow-right-start-on-rectangle" aria-hidden="true"></i>
Sign out
</button>
</form>
</div>
</div>
</div>
</div>

Expand Down
Loading