Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Aug 20, 2024
1 parent 0ac7093 commit 51b5733
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,28 @@
@Configuration
public class SecurityConfiguration {

public SecurityConfiguration(){
Security.addProvider(new BouncyCastleProvider());
}

@Bean
SecurityFilterChain app(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.saml2Login(Customizer.withDefaults());
// @formatter:on

return http.build();
}

@Bean
RelyingPartyRegistrationResolver relyingPartyRegistrationResolver(
RelyingPartyRegistrationRepository registrations) {
return new DefaultRelyingPartyRegistrationResolver(registrations);
}

@Bean
FilterRegistrationBean<Saml2MetadataFilter> metadata(RelyingPartyRegistrationResolver registrations) {
Saml2MetadataFilter metadata = new Saml2MetadataFilter(registrations, new OpenSamlMetadataResolver());
FilterRegistrationBean<Saml2MetadataFilter> filter = new FilterRegistrationBean<>(metadata);
filter.setOrder(-101);
return filter;
}
public SecurityConfiguration() {
Security.addProvider(new BouncyCastleProvider());
}

@Bean
SecurityFilterChain app(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated()).saml2Login(Customizer.withDefaults());
return http.build();
}

@Bean
RelyingPartyRegistrationResolver relyingPartyRegistrationResolver(
RelyingPartyRegistrationRepository registrations) {
return new DefaultRelyingPartyRegistrationResolver(registrations);
}

@Bean
FilterRegistrationBean<Saml2MetadataFilter> metadata(RelyingPartyRegistrationResolver registrations) {
Saml2MetadataFilter metadata = new Saml2MetadataFilter(registrations, new OpenSamlMetadataResolver());
FilterRegistrationBean<Saml2MetadataFilter> filter = new FilterRegistrationBean<>(metadata);
filter.setOrder(-101);
return filter;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @author Lucas Alber
*/
public class NewsItem {
private String title;
private String content;
private final String title;
private final String content;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void parseCSVs() {
.map(Path::toFile)
.filter(e -> e.getName().endsWith(".csv"))
.sorted()
.collect(Collectors.toList());
.toList();

} catch (IOException e) {
logger.warn("CSVs could not be parsed.", e);
Expand All @@ -62,20 +62,20 @@ public void parseCSVs() {
for (File file : files) {
logger.debug("Parsing " + file.getAbsolutePath());
try {
for (CSVRecord record : format.parse(new FileReader(file))) {
if (record.size() != 2) {
logger.warn("Expected exactly two columns, but record " + record + " had " + record.size() + ". Skipping!");
for (CSVRecord csvRecord : format.parse(new FileReader(file))) {
if (csvRecord.size() != 2) {
logger.warn("Expected exactly two columns, but record " + csvRecord + " had " + csvRecord.size() + ". Skipping!");
continue;
}

final String key = record.get(0);
final String key = csvRecord.get(0);
if (!news.containsKey(key)) {
news.put(key, new LinkedList<>());
}


String title = file.getName().substring(0, file.getName().length() - 4).replaceAll("[_]", "");
String content = record.get(1);
String content = csvRecord.get(1);
news.get(key).add(new NewsItem(title, content));
}

Expand Down
39 changes: 19 additions & 20 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity5" lang="en">
<head>
<title>News List</title>
<meta charset="utf-8" />
<link th:rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}" />
<style>
</style>
<meta charset="utf-8"/>
<link th:rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"/>
</head>
<body>
<main role="main" class="container">
<h1 class="mt-5">SDQ-NewsList</h1>
<p class="lead">You are successfully identified as <b th:text="${emailAddress}"></b>. Looking for News via '<b th:text="${saml2key}"></b>'.</p>
<h2 class="mt-2">Your News</h2>
<div class="list-group" th:each="newsItem : ${news}">
<a href="#" class="list-group-item">
<div class="d-flex gap-2">
<div>
<div class="fw-bold" th:text="${newsItem.getTitle()}"></div>
<p class="mb-0 opacity-75" th:text="${newsItem.getContent()}"></p>
</div>
<main role="main" class="container">
<h1 class="mt-5">SDQ-NewsList</h1>
<p class="lead">You are successfully identified as <b th:text="${emailAddress}"></b>. Looking for News via '<b
th:text="${saml2key}"></b>'.</p>
<h2 class="mt-2">Your News</h2>
<div class="list-group" th:each="newsItem : ${news}">
<a href="#" class="list-group-item">
<div class="d-flex gap-2">
<div>
<div class="fw-bold" th:text="${newsItem.getTitle()}"></div>
<p class="mb-0 opacity-75" th:text="${newsItem.getContent()}"></p>
</div>
</a>
</div>
</main>
</div>
</div>
</a>
</div>
</main>
</body>
</html>

0 comments on commit 51b5733

Please sign in to comment.