diff --git a/src/main/frontend/icons.mjs b/src/main/frontend/icons.mjs index 5148e8b..fc45bac 100644 --- a/src/main/frontend/icons.mjs +++ b/src/main/frontend/icons.mjs @@ -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'; @@ -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'; @@ -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, @@ -115,6 +118,7 @@ export const ICONS = { sun, 'table-cells': tableCells, trash, + 'identification': identification, 'user-circle': userCircle, 'user-plus': userPlus, users, diff --git a/src/main/frontend/s3webui.css b/src/main/frontend/s3webui.css index 06add80..9e47f60 100644 --- a/src/main/frontend/s3webui.css +++ b/src/main/frontend/s3webui.css @@ -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; } diff --git a/src/main/frontend/s3webui.js b/src/main/frontend/s3webui.js index 2f0a11b..ecbc177 100644 --- a/src/main/frontend/s3webui.js +++ b/src/main/frontend/s3webui.js @@ -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=`${escapeMarkup(credential.name)}${escapeMarkup([credential.endpointUrl,credential.region].filter(Boolean).join(' · '))}`; 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=''; 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=`${escapeMarkup(credential.name)}${escapeMarkup([credential.endpointUrl,credential.region].filter(Boolean).join(' · '))}`; 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=''; 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'); diff --git a/src/main/java/tech/wenisch/s3webui/controller/S3SessionController.java b/src/main/java/tech/wenisch/s3webui/controller/S3SessionController.java index b7cd83a..9555c1e 100644 --- a/src/main/java/tech/wenisch/s3webui/controller/S3SessionController.java +++ b/src/main/java/tech/wenisch/s3webui/controller/S3SessionController.java @@ -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. @@ -40,7 +41,8 @@ public SessionStatusResponse getStatus() { s3ConnectionSettingsService.getActiveCredentialName(), s3ConnectionSettingsService.isUserSuppliedCredentialsAllowed(), s3ConnectionSettingsService.areUsersAllowedToRevealKeys(), - s3ConnectionSettingsService.listAvailableCredentials() + s3ConnectionSettingsService.listAvailableCredentials(), + s3ConnectionSettingsService.listSearchableAccessKeys() ); } @@ -89,7 +91,8 @@ public record SessionStatusResponse( String activeCredentialName, boolean allowOwnCredentials, boolean allowUsersToRevealKeys, - List credentials + List credentials, + Map accessKeys ) { } } diff --git a/src/main/java/tech/wenisch/s3webui/service/S3ConnectionSettingsService.java b/src/main/java/tech/wenisch/s3webui/service/S3ConnectionSettingsService.java index bad0eec..49efee5 100644 --- a/src/main/java/tech/wenisch/s3webui/service/S3ConnectionSettingsService.java +++ b/src/main/java/tech/wenisch/s3webui/service/S3ConnectionSettingsService.java @@ -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 @@ -44,6 +46,22 @@ public List 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 listSearchableAccessKeys() { + Authentication authentication = currentAuthentication(); + boolean revealForAll = appSettingsService.areUsersAllowedToRevealKeys(); + Map 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(); } diff --git a/src/main/resources/templates/fragments/shell.html b/src/main/resources/templates/fragments/shell.html index 2a78d93..ed9b42e 100644 --- a/src/main/resources/templates/fragments/shell.html +++ b/src/main/resources/templates/fragments/shell.html @@ -126,7 +126,7 @@ aria-modal="true" aria-labelledby="s3SessionTitle" > -