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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ private List<App> 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()
Expand All @@ -60,8 +64,11 @@ private Optional<App> toApp(LaunchpadConfigProperties.App app) {
private Optional<URL> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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<String> appUrls(LaunchpadServiceImpl service, Authentication authentication) {
return service.getLaunchpad(authentication).getApps().stream()
.map(app -> app.getUrl().toString())
Expand Down