# dariahsp: service provider implementation for DARIAH services
# dariahsp: service provider implementation for DARIAH services
This project contains the [dariahsp-core] library and the Spring Boot based [dariahsp-sample-boot] application. Implementations that are based on the core library need to include the dariahsp-core dependency and provide configuration for the primary security entry points.
This project contains the [dariahsp-core](dariahsp-core) library and the Spring Boot based [dariahsp-sample-boot](dariahsp-sample-boot) application. Implementations that are based on the core library need to include the dariahsp-core dependency and provide configuration for the primary security entry points.
The library is a wrapper around [Spring Security](https://spring.io/projects/spring-security), [PAC4J](https://www.pac4j.org/) and [OpenSAML 4](https://build.shibboleth.net/nexus/content/repositories/releases/org/opensaml/opensaml-core/) and implements two security methods that are commonly used in the context of DARIAH: the _local_ method is intended primarily for developer and test setups, the _saml_ method is targeted towards production environments. Both methods can easily be tested within the dariahsp-sample-boot web application. Opposed to earlier version, a choice between the methods is no longer determined by an environment flag, but by setting enabled properties within application properties. Methods can be enabled simultaneously and can work in parallel.
The library is a wrapper around [Spring Security](https://spring.io/projects/spring-security), [PAC4J](https://www.pac4j.org/) and [OpenSAML 4](https://build.shibboleth.net/nexus/content/repositories/releases/org/opensaml/opensaml-core/) and implements two security methods that are commonly used in the context of DARIAH: the _local_ method is intended primarily for developer and test setups, the _saml_ method is targeted towards production environments. Both methods can easily be tested within the dariahsp-sample-boot web application. Opposed to earlier version, a choice between the methods is no longer determined by an environment flag, but by setting enabled properties within application properties. Methods can be enabled simultaneously and can work in parallel.
While still being used, the former v1.4 is discontinued and - being based on OpenSAML 2 ([also discontinued](https://wiki.shibboleth.net/confluence/display/OpenSAML/Home)) - should be replaced with a recent version.
While still being used, the former v1.4 is discontinued and - being based on OpenSAML 2 ([also discontinued](https://wiki.shibboleth.net/confluence/display/OpenSAML/Home)) - should be replaced with a recent version.
## Dependencies
## 1. Quickstart
The library and sample application are deployed to a Maven repository:
A reference implementation and quick-start guide can be found in the [dariahsp-sample-boot](dariahsp-sample-boot) application.
## 2. Repository and dependency setup
The library and sample application are deployed to the Maven repository available at https://minfba.de.dariah.eu/nexus. Repository configuration can be included in Maven and Gradle settings and build configurations with the following snippets.
### 2.1 Maven setup
Please find information on the current version of dariahsp-core at the [respective package](https://minfba.de.dariah.eu/nexus/#browse/browse:minfba-central:eu%2Fdariah%2Fde%2Fdariahsp-core) in the deployment repository:
#### Repository configuration
The Proxy repository _minfba-central_ provides combined access to releases and snapshots.
As this library is based on Spring Security, concepts such as _Java-based configuration_, _filters_, _interceptors_ or _global method security_ can be referenced in the respective Spring documentation, e.g. the [Spring Core reference](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html), the [Spring Web reference](https://docs.spring.io/spring-framework/docs/current/reference/html/web.html) and the [Spring Security Architecture](https://spring.io/guides/topicals/spring-security-architecture).
Components that _only need import and activation_ in the target application:
*[`SecurityConfig`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/SecurityConfig.java): Main configuration contains all security-related beans and can be imported into the applications configuration
*[`AuthInfoHandlerInterceptor`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/web/AuthInfoHandlerInterceptor.java) provides access to authentication information in every view-model as `_auth` attribute
*[`DefaultFiltersConfigurerAdapter`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/web/DefaultFiltersConfigurerAdapter.java) provides filters for logout and intermediat-authentication callback (SAML)
*[`SAMLMetadataController`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/web/controller/SAMLMetadataController.java) provides easy web access to SAML SP metadata that can be used to register the implementing application at identity providers or federations
*[`GlobalMethodSecurityConfig`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/web/GlobalMethodSecurityConfig.java) enables and configures annotation-based method security and thus simplifies security for REST controllers
One component requires _adaption_ in implementing applications:
*[`SecurityConfigurerAdapter`](dariahsp-core/src/main/java/eu/dariah/de/dariahsp/config/web/SecurityConfigurerAdapter.java) is intended to be extended by a concrete adapter that defines protected paths of the application.
## 4. Configuration
### Minimal working configuration
A minimal working configuration enables the local authentication method and provides local user accounts.
## Local user accounts
## Local user accounts
The library supports a local authentication method that is purely based on application configuration properties. A working example including all configurable aspects:
The library supports a local authentication method that is purely based on application configuration properties. A working example including all configurable aspects:
```yaml
#Minimal working sample configuration with local authentication enabled and one configured user
A more sophisticated configuration of the local authentication method could involve roles and role mappings along with a configured hierarchy between the roles
```yaml
```yaml
auth:
auth:
#settings under roleHierarchy and roleDefinitions apply to all supported authentication methods
#settings under roleHierarchy and roleDefinitions apply to all supported authentication methods
...
@@ -50,18 +142,15 @@ auth:
...
@@ -50,18 +142,15 @@ auth:
-role:ADMINISTRATOR
-role:ADMINISTRATOR
level:100
level:100
mappings:
mappings:
local:["application_admin"]
local:["application_admin"]
saml:["application_admin"]
-role:CONTRIBUTOR
-role:CONTRIBUTOR
level:50
level:50
mappings:
mappings:
local:["application_contributor"]
local:["application_contributor"]
saml:["application_contributor"]
-role:USER
-role:USER
level:10
level:10
mappings:
mappings:
local:["application_user"]
local:["application_user"]
saml:["application_user"]
#Enabled local authentication method with three configured users
#Enabled local authentication method with three configured users
System.out.println("Please make sure to provide BCrypt initialization arguments exactly \n as they are configured in the security-context-common.xml");
System.out.println("If you have not changed the default initialization of the BCryptPasswordEncoder \n (and you dont have to), choose the default values for rounds:");