diff --git a/src/main/java/de/focus_shift/launchpad/core/LaunchpadServiceImpl.java b/src/main/java/de/focus_shift/launchpad/core/LaunchpadServiceImpl.java index aae076d..c4d9087 100644 --- a/src/main/java/de/focus_shift/launchpad/core/LaunchpadServiceImpl.java +++ b/src/main/java/de/focus_shift/launchpad/core/LaunchpadServiceImpl.java @@ -40,6 +40,10 @@ private List getApplications(Authentication authentication) { } private boolean isAllowed(App app, Authentication authentication) { + // null when nobody is logged in + if (authentication == null) { + return app.getAuthority().isEmpty(); + } return app.getAuthority() .map(authority -> authentication.getAuthorities().stream() @@ -60,8 +64,11 @@ private Optional toApp(LaunchpadConfigProperties.App app) { private Optional getAppUrl(LaunchpadConfigProperties.App app) { try { return Optional.of(appUrlCustomizer.customize(app.getUrl())); - } catch (MalformedURLException e) { - LOG.info("ignoring launchpad app: could not build URL for app={}", app, e); + } catch (MalformedURLException | IllegalArgumentException e) { + LOG.warn( + "ignoring launchpad app: could not build URL from url={}: {}", + app.getUrl(), + e.getMessage()); return Optional.empty(); } } diff --git a/src/test/java/de/focus_shift/launchpad/core/LaunchpadServiceImplTest.java b/src/test/java/de/focus_shift/launchpad/core/LaunchpadServiceImplTest.java index d552aa1..b6f9945 100644 --- a/src/test/java/de/focus_shift/launchpad/core/LaunchpadServiceImplTest.java +++ b/src/test/java/de/focus_shift/launchpad/core/LaunchpadServiceImplTest.java @@ -15,6 +15,15 @@ class LaunchpadServiceImplTest { private final LaunchpadServiceImpl sut = service(app("https://public.example.org", null), app("https://admin.example.org", "ADMIN")); + @Test + void ignoresAppsWhoseUrlCannotBeBuilt() { + final LaunchpadServiceImpl service = + service(app("no-scheme.example.org", null), app("https://public.example.org", null)); + + assertThat(appUrls(service, new TestingAuthenticationToken("user", "", "USER"))) + .containsExactly("https://public.example.org"); + } + @Test void showsAppsWithAuthorityToUsersWithThatAuthority() { assertThat(appUrls(sut, new TestingAuthenticationToken("admin", "", "ADMIN"))) @@ -27,6 +36,11 @@ void hidesAppsWithAuthorityFromUsersWithoutThatAuthority() { .containsExactly("https://public.example.org"); } + @Test + void hidesAppsWithAuthorityFromAnonymousUsers() { + assertThat(appUrls(sut, null)).containsExactly("https://public.example.org"); + } + private static List appUrls(LaunchpadServiceImpl service, Authentication authentication) { return service.getLaunchpad(authentication).getApps().stream() .map(app -> app.getUrl().toString())