de.digitalcollections.iiif.bookshelf.config.SpringConfigSecurityMonitoring Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iiif-bookshelf-webapp Show documentation
Show all versions of iiif-bookshelf-webapp Show documentation
The bookshelf is a webapp for collecting IIIF representations of books. It is based on the functionality of the IIIF Presentation API for modelling books. You can add books to your bookshelf loading the manifest.json of the book by its web-address.
package de.digitalcollections.iiif.bookshelf.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.info.InfoEndpoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
@Order(1)
public class SpringConfigSecurityMonitoring extends WebSecurityConfigurerAdapter {
@Value("${spring.security.user.name}")
private String actuatorUsername;
@Value("${spring.security.user.password}")
private String actuatorPassword;
@Value("${javamelody.init-parameters.monitoring-path:/monitoring}")
String javamelodyMonitoringPath;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(passwordEncoderDummy())
.withUser(User.withUsername(actuatorUsername).password(actuatorPassword).roles("ACTUATOR"));
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// Monitoring:
// see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints
http.antMatcher("/monitoring/**").authorizeRequests()
.requestMatchers(EndpointRequest.to(InfoEndpoint.class, HealthEndpoint.class)).permitAll()
.requestMatchers(EndpointRequest.to("jolokia", "prometheus", "version")).permitAll()
.requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR").and().httpBasic();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(javamelodyMonitoringPath);
}
private PasswordEncoder passwordEncoderDummy() {
return new PasswordEncoder() {
@Override
public String encode(CharSequence rawPassword) {
return rawPassword.toString();
}
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
return rawPassword.toString().equals(encodedPassword);
}
};
}
}