Skip to content
Snippets Groups Projects
Select Git revision
  • 5407174b7f93696fc955a5040a6d0880e3d0749a
  • master default protected
  • add-frequency-to-form
  • dev protected
  • ckan-2.11.0
  • add-package-custom-fields
  • fix-adding-datasets-for-users-and-editors
  • add-auth-subroute
  • 71-migrate-custom-fields-to-ckanext-scheming
  • add-author-maintainer-information
  • fix-inline-flex-btns
  • fix-known-spatial-uri-validation
  • py3
  • 47-aktuelle-resource-einer-collection-wird-nicht-mehr-gefunden
  • 10-eingabe-der-dct-accrualperiodicity-in-weboberflache
  • v1.3
  • 2.5.3
  • 2.5.2
  • 2.5.1
  • 2.5.0
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.3
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.1
  • 2.3.0
  • 2.2.0
  • 2.1.0
  • 2.0.0
  • 1.4.3
  • 1.4.2
  • 1.4.1
36 results

precondition.py

Blame
  • SecurityConfiguration.java 3.00 KiB
    /*
     * Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch das
     * Ministerium für Energiewende, Klimaschutz, Umwelt und Natur Zentrales
     * IT-Management
     *
     * Lizenziert unter der EUPL, Version 1.2 oder - sobald diese von der
     * Europäischen Kommission genehmigt wurden - Folgeversionen der EUPL
     * ("Lizenz"); Sie dürfen dieses Werk ausschließlich gemäß dieser Lizenz nutzen.
     * Eine Kopie der Lizenz finden Sie hier:
     *
     * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
     *
     * Sofern nicht durch anwendbare Rechtsvorschriften gefordert oder in
     * schriftlicher Form vereinbart, wird die unter der Lizenz verbreitete Software
     * "so wie sie ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
     * ausdrücklich oder stillschweigend - verbreitet. Die sprachspezifischen
     * Genehmigungen und Beschränkungen unter der Lizenz sind dem Lizenztext zu
     * entnehmen.
     */
    package de.ozgcloud.admin.security;
    
    import java.util.List;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.HttpMethod;
    import org.springframework.security.config.Customizer;
    import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
    import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
    import org.springframework.security.config.http.SessionCreationPolicy;
    import org.springframework.security.oauth2.core.oidc.StandardClaimNames;
    import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
    import org.springframework.security.web.SecurityFilterChain;
    
    import lombok.RequiredArgsConstructor;
    
    @Configuration
    @EnableMethodSecurity(securedEnabled = true)
    @EnableWebSecurity
    @RequiredArgsConstructor
    public class SecurityConfiguration {
    
    	private final AdminAuthenticationEntryPoint authenticationEntryPoint;
    
    	@Bean
    	SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    
    		http.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()));
    
    		http.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
    
    		http.exceptionHandling(eh -> eh.authenticationEntryPoint(authenticationEntryPoint));
    
    		http.authorizeHttpRequests(requests -> requests
    				.requestMatchers(HttpMethod.GET, "/api/environment").permitAll()
    				.requestMatchers("/api").authenticated()
    				.requestMatchers("/api/**").authenticated()
    				.requestMatchers("/actuator").permitAll()
    				.requestMatchers("/actuator/**").permitAll()
    				.requestMatchers("/configserver/**").permitAll()
    				.anyRequest().denyAll());
    
    		return http.build();
    	}
    
    	@Bean
    	JwtAuthenticationConverter jwtAuthenticationConverter() {
    		var jwtConverter = new JwtAuthenticationConverter();
    		jwtConverter.setJwtGrantedAuthoritiesConverter(jwt -> List.of(() -> "ROLE_USER"));
    		jwtConverter.setPrincipalClaimName(StandardClaimNames.PREFERRED_USERNAME);
    		return jwtConverter;
    	}
    
    }