Ticket #2794: 0001-ticket-2792-Fix-add-authentication_type-basic_header.patch

File 0001-ticket-2792-Fix-add-authentication_type-basic_header.patch, 64.9 KB (added by Bang Pham Huu, 11 months ago)
  • applications/petascope/petascope_core/src/main/java/org/rasdaman/config/ConfigManager.java

    From 336629358238161cc317205eeafe7782d1484321 Mon Sep 17 00:00:00 2001
    From: Bang Pham Huu <b.phamhuu@jacobs-university.de>
    Date: Mon, 11 Dec 2023 12:53:47 +0100
    Subject: [PATCH] ticket:2792 - Fix - add authentication_type=basic_header in
     petascope.properties
    
    Summary:
    Added authentication_type= setting in petascope.properties and
    fixed the behavior of petascope community accordingly.
    
    Test Plan: tested manually
    
    Reviewers: dmisev
    
    Differential Revision: https://codereview.rasdaman.com/D531
    ---
     .../org/rasdaman/config/ConfigManager.java    |  33 +-
     .../service/AuthenticationService.java        |  30 ++
     .../accesscontrol/service/RequestsFilter.java | 285 ++++++++++++++++++
     .../service/AdminActivateLayerService.java    |   2 -
     .../service/AdminDeactivateLayerService.java  |   2 -
     .../admin/model/AuthIsActiveResult.java       |  28 +-
     .../java/org/rasdaman/ApplicationMain.java    |  21 +-
     .../datamigration/DataMigration8Handler.java  |  23 +-
     .../datamigration/DataMigration9Handler.java  |  24 +-
     .../controller/AbstractController.java        |  50 ++-
     .../controller/AuthenticationController.java  |  38 ++-
     .../controller/InspireController.java         |   3 +-
     .../admin/AdminLayerManagementController.java |   5 +-
     .../admin/AdminOwsServiceInfoController.java  |   3 +-
     .../admin/AdminPyramidController.java         |   7 +-
     .../admin/AdminStyleManagementController.java |   7 +-
     .../admin/AdminUpdateCoverageController.java  |   3 +-
     .../java/petascope/util/IPAddressUtil.java    |  27 +-
     .../wcst/handlers/DeleteCoverageHandler.java  |   7 +-
     .../wcst/handlers/InsertCoverageHandler.java  |   4 +-
     .../wcst/handlers/UpdateCoverageHandler.java  |   6 +-
     .../update/RasdamanUpdaterFactory.java        |  12 -
     .../service/WMSGetMapStyleService.java        |   8 +-
     .../main/resources/petascope.properties.in    |   5 +-
     ...services-guide-petascope-configuration.inc |  57 +++-
     25 files changed, 585 insertions(+), 105 deletions(-)
     create mode 100644 applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/RequestsFilter.java
    
    diff --git a/applications/petascope/petascope_core/src/main/java/org/rasdaman/config/ConfigManager.java b/applications/petascope/petascope_core/src/main/java/org/rasdaman/config/ConfigManager.java
    index 323547e0d..53408b95f 100644
    a b public class ConfigManager {  
    107107    // context path for OAPI endpoint (e.g: localhost:8080/rasdaman/oapi)
    108108    public static final String OAPI = "oapi";
    109109
    110     // For community this endpoint always return fasle, it is used to check that if petascope is running from wsclient
     110    // Check if petascope has enabled authentication in petascope.properties
    111111    public static final String CHECK_PETASCOPE_ENABLE_AUTHENTICATION = "authisactive";
    112112    public static final String CHECK_PETASCOPE_ENABLE_AUTHENTICATION_CONTEXT_PATH = ADMIN + "/authisactive";
    113113
    public class ConfigManager {  
    291291    public static String INSPIRE_COMMON_URL = "";
    292292    public static String INSPIRE_SPATIAL_DATASET_IDENTIFIER = "rasdaman";
    293293
     294    private static final String KEY_AUTHENTICATION_TYPE = "authentication_type";
     295    public static final String AUTHENTICATION_TYPE_BASIC_HEADER = "basic_header";
     296    public static String AUTHENTICATION_TYPE = AUTHENTICATION_TYPE_BASIC_HEADER;
     297
    294298    // rasj
    295299    private static final String KEY_RASJ_LOGGING_LEVEL = "rasj_logging_level";
    296300    public static String RASJ_LOGGING_LEVEL = RasjLoggingLevel.WARN.name();
    public class ConfigManager {  
    382386       
    383387        initRasj();
    384388
     389        initAuthenticationTypesSetting();
     390
    385391        printStartupMessage();
    386392       
    387393        GDAL_JAVA_VERSION = Byte.parseByte(gdal.VersionInfo().substring(0, 1));
    public class ConfigManager {  
    433439       
    434440        return value;
    435441    }
     442
     443    private boolean containsProperty(String key) {
     444        return props.get(key) != null;
     445    }
    436446   
    437447    private void initPetascopeSettings() throws PetascopeException {
    438448        // server.port
    public class ConfigManager {  
    740750
    741751        log.info("------------------------------------");
    742752    }
     753
     754    public static boolean enableAuthentication() {
     755        return !AUTHENTICATION_TYPE.isEmpty();
     756    }
     757
     758    /**
     759     * Initialize authentication types in Petascope (e.g: shibboleth and basic authentication header).
     760     */
     761    private void initAuthenticationTypesSetting() throws PetascopeException {
     762        if (containsProperty(KEY_AUTHENTICATION_TYPE)) {
     763            String value = get(KEY_AUTHENTICATION_TYPE).trim();
     764            if (!value.isEmpty()) {
     765                if (!value.equals(AUTHENTICATION_TYPE_BASIC_HEADER)) {
     766                    throw new PetascopeException(ExceptionCode.InvalidPropertyValue,
     767                            "Value for authentication setting '" + KEY_AUTHENTICATION_TYPE + "' is not supported. Given: '" + value + "'");
     768                }
     769            }
     770
     771            AUTHENTICATION_TYPE = value;
     772        }
     773    }
    743774}
    744775
  • applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/AuthenticationService.java

    diff --git a/applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/AuthenticationService.java b/applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/AuthenticationService.java
    index 5853e7328..508a5abdb 100644
    a b public class AuthenticationService {  
    122122        InputStream inputStream = urlConnection.getInputStream();
    123123        return inputStream;
    124124    }
     125
     126    /**
     127     * Return rasdaman user credentials from a request.
     128     * NOTE: used only in deeper classes which are behind this requests filter.
     129     */
     130    public static Pair<String, String> getRasUserCredentials(HttpServletRequest httpServletRequest) throws PetascopeException {
     131        String username = ConfigManager.RASDAMAN_USER;
     132        String password = ConfigManager.RASDAMAN_PASS;
     133       
     134        Pair<String, String> basicAuthCredentialsPair = getBasicAuthUsernamePassword(httpServletRequest);
     135        if (basicAuthCredentialsPair != null) {
     136            username = basicAuthCredentialsPair.fst;
     137            password = basicAuthCredentialsPair.snd;
     138        }
     139       
     140        if (ConfigManager.enableAuthentication()) {
     141
     142            // If request with basic authentication header then just use credentials from it
     143           
     144            if (basicAuthCredentialsPair != null) {
     145                // Basic authentication, credentials always from header
     146                username = basicAuthCredentialsPair.fst;
     147                password = basicAuthCredentialsPair.snd;
     148            }           
     149        }
     150       
     151        Pair<String, String> credentailsPair = new Pair<>(username, password);
     152       
     153        return credentailsPair;
     154    }
    125155   
    126156}
  • new file applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/RequestsFilter.java

    diff --git a/applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/RequestsFilter.java b/applications/petascope/petascope_main/src/main/java/com/rasdaman/accesscontrol/service/RequestsFilter.java
    new file mode 100644
    index 000000000..74fe160d8
    - +  
     1/*
     2 * This file is part of rasdaman community.
     3 *
     4 * Rasdaman community is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 3 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * Rasdaman community is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12 * See the GNU  General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU  General Public License
     15 * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
     16 *
     17 * Copyright 2003 - 2023 Peter Baumann / rasdaman GmbH.
     18 *
     19 * For more information please see <http://www.rasdaman.org>
     20 * or contact Peter Baumann via <baumann@rasdaman.com>.
     21 */
     22package com.rasdaman.accesscontrol.service;
     23
     24import java.io.IOException;
     25import java.util.*;
     26import javax.servlet.Filter;
     27import javax.servlet.FilterChain;
     28import javax.servlet.FilterConfig;
     29import javax.servlet.ServletException;
     30import javax.servlet.ServletRequest;
     31import javax.servlet.ServletResponse;
     32import javax.servlet.http.HttpServletRequest;
     33import javax.servlet.http.HttpServletRequestWrapper;
     34import javax.servlet.http.HttpServletResponse;
     35
     36import org.apache.commons.lang3.StringUtils;
     37import org.rasdaman.CorsFilter;
     38import org.rasdaman.config.ConfigManager;
     39import static org.rasdaman.config.ConfigManager.ADMIN;
     40import static org.rasdaman.config.ConfigManager.AUTHENTICATION_TYPE_BASIC_HEADER;
     41import static org.rasdaman.config.ConfigManager.OWS;
     42import static org.rasdaman.config.ConfigManager.RASQL;
     43import org.rasdaman.config.VersionManager;
     44import org.springframework.beans.factory.annotation.Autowired;
     45import org.springframework.stereotype.Component;
     46
     47import static org.rasdaman.config.ConfigManager.*;
     48import static org.rasdaman.config.ConfigManager.PETASCOPE_ENDPOINT_URL;
     49import static petascope.core.KVPSymbols.WCS_SERVICE;
     50import petascope.core.Pair;
     51import petascope.exceptions.ExceptionCode;
     52import petascope.exceptions.PetascopeException;
     53import petascope.util.ExceptionUtil;
     54import petascope.util.ras.RasUtil;
     55import static org.rasdaman.config.ConfigManager.CHECK_PETASCOPE_ENABLE_AUTHENTICATION;
     56import static org.rasdaman.config.ConfigManager.SECORE;
     57import petascope.controller.PetascopeController;
     58
     59/**
     60 * If Shibboleth authentication is configured, any unauthenticated requests will
     61 * need to redirect to Shibboleth auth endpoint to login from IdP's credentials.
     62 *
     63 * @author Bang Pham Huu <b.phamhuu@jacobs-university.de>
     64 */
     65@Component
     66public class RequestsFilter implements Filter {
     67   
     68    // Endpoint to check authentication and return the roles of an user to clients
     69    public static final String LOGIN = "login";
     70
     71    @Autowired
     72    private HttpServletRequest httpServletRequest;
     73    @Autowired
     74    private PetascopeController petascopeController;
     75    @Autowired
     76    private AuthenticationService authenticationService;
     77
     78    // NOTE: These requests should bypass authentication in Petascope (i.e: no need to authenticate in any case)
     79    // Because they are sent internally by petascope / rasfed not by users
     80    private static final List<String> NO_NEED_TO_AUTHENTICATE_REQUESTS = new ArrayList<>(Arrays.asList(
     81        // Rasql Servlet as it always needs query and password parameters
     82        RASQL,
     83           
     84        SECORE,   
     85
     86        // non-standard for checking authentication for petascope
     87        CHECK_PETASCOPE_ENABLE_AUTHENTICATION, LOGIN
     88    ));
     89
     90    /**
     91     * Check if a request should need authentication or not
     92     */
     93    private boolean requireAthenticationRequest(String requestMethod, String requestURI, String queryString) {
     94       
     95        // Static assets (.html, .js, .css) are not checked
     96        if (requestURI.matches(".*/.*\\..*")) {
     97            return false;
     98        }
     99
     100        if (requestURI.contains("admin/version")) {
     101            return false;
     102        }
     103       
     104        // Request to return WSClient
     105        if (requestMethod.equals("GET")) {
     106            if (requestURI.endsWith("/" + OWS) && queryString == null) {
     107                return false;
     108            } else if (requestURI.endsWith("rasdaman/") && queryString == null) {
     109                // Return the HTML pages configured in petascope.properties (e.g: BigDataCube demo)
     110                return false;
     111            }
     112        }
     113       
     114        // endpoint to show admin page embedded in petascope (the page contains web rascontrol, access controll management and statistic)
     115        if (this.httpServletRequest.getMethod().equals("GET") && requestURI.endsWith("/" + ADMIN)) {
     116            return false;
     117        }
     118
     119        for (String request : NO_NEED_TO_AUTHENTICATE_REQUESTS) {
     120            // special requests are not checked
     121            if (requestURI.contains("/" + request)) {
     122                return false;
     123            }
     124        }               
     125
     126        return true;
     127    }
     128
     129    /**
     130     * Check if credentials are valid
     131     * NOTE: it allows null credentialsPair for further processing
     132     */
     133    private void checkValidCredentialsAllowNull(Pair<String, String> credentialsPair) throws PetascopeException {
     134        if (credentialsPair != null) {
     135            RasUtil.checkValidUserCredentials(credentialsPair.fst, credentialsPair.snd);
     136        }
     137    }
     138   
     139    @Override
     140    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
     141        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
     142        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
     143
     144        // NOTE: no url for petascope is defined in petascope.properties, only now can have the HTTP request object to set this value
     145         if (StringUtils.isEmpty(PETASCOPE_ENDPOINT_URL)) {
     146            // use the requesting URL to Petascope (not always: http://localhost:8080/rasdaman/ows)
     147
     148            // e.g. /openeo/.well-known/openeo
     149            String servletPath = httpServletRequest.getServletPath();
     150            String requestURL = httpServletRequest.getRequestURL().toString();
     151
     152            // e.g. http://localhost:8080/rasdaman/ows
     153            String contextPathURL = requestURL.split(servletPath)[0] + "/" + OWS;
     154
     155            ConfigManager.setPetascopeEndpointUrl(contextPathURL);
     156            String protocol = httpServletRequest.getHeader("X-Forwarded-Proto");
     157
     158            if (protocol != null) {
     159                // e.g. in case using https in apache2 proxy for http on local tomcat
     160                String[] tmps = PETASCOPE_ENDPOINT_URL.split("://");
     161                ConfigManager.setPetascopeEndpointUrl(protocol + "://" + tmps[1]);
     162            }
     163        }
     164
     165        if (INSPIRE_COMMON_URL.isEmpty()) {
     166            INSPIRE_COMMON_URL = PETASCOPE_ENDPOINT_URL;
     167        }
     168       
     169        // NOTE: must enable 'Access-Control-Allow-Origin': * in HTTP response
     170        // In case basic header is enabled to avoid CORS problem in web browser
     171        CorsFilter.setResponseHeader(httpServletRequest, httpServletResponse);
     172       
     173        // NOTE: to avoid CORS error from web browser for preflight request (OPTIONS request), these requests don't contain basic header
     174        // (in case petascope's basic header is enabled)
     175        if ("OPTIONS".equals(httpServletRequest.getMethod())) {
     176            httpServletResponse.setStatus(HttpServletResponse.SC_OK);
     177            return;
     178        }
     179       
     180        String authenticationErrorMessage = "";
     181       
     182        if (ConfigManager.enableAuthentication()) {
     183           
     184            // Based on the first authentication type to redirect to Shibboleth IdP
     185            // or throw exception with basic authentcation header (requests without username and password)
     186            String authenticationType = ConfigManager.AUTHENTICATION_TYPE;
     187
     188            // Special requests will not need to check
     189            if (requireAthenticationRequest(httpServletRequest.getMethod(), httpServletRequest.getRequestURI(), httpServletRequest.getQueryString())) {
     190                Pair<String, String> basicAuthCredentialsPair = null;
     191                try {
     192                    basicAuthCredentialsPair = AuthenticationService.getBasicAuthUsernamePassword(httpServletRequest);
     193                    this.checkValidCredentialsAllowNull(basicAuthCredentialsPair);
     194                } catch (PetascopeException ex) {
     195                    ExceptionUtil.handle(VersionManager.getLatestVersion(WCS_SERVICE), ex, httpServletResponse);
     196                    return;
     197                }
     198
     199                if (authenticationType.equals(AUTHENTICATION_TYPE_BASIC_HEADER)) {
     200                    if (basicAuthCredentialsPair == null) {
     201                        if (ConfigManager.RASDAMAN_USER.isEmpty()) {
     202                            // If rasguest is not set as rasdaman_user and basic header is enabled, then petascope throws error for unauthenticated requests
     203                            try {
     204                                String requestRepresentation = this.petascopeController.getRequestPresentationWithEncodedAmpersands(httpServletRequest);
     205                                authenticationErrorMessage = "Missing basic authentication header with username:password encoded in Base64 string from request '" + requestRepresentation + "'";
     206                            } catch (Exception ex) {
     207                                ExceptionUtil.handle(VersionManager.getLatestVersion(WCS_SERVICE), ex, httpServletResponse);
     208                            }                           
     209                        } else {
     210                            // If rasguest is set as rasdaman_user and basic header is enabled, then petascope uses rasguest's credentials for unauthenticated requests
     211                            MutableHttpServletRequest mutableRequest = new MutableHttpServletRequest(httpServletRequest);
     212                            String credentialsInBase64 = AuthenticationService.createBasicHeaderCredentialsInBase64String(ConfigManager.RASDAMAN_USER, ConfigManager.RASDAMAN_PASS);
     213                            mutableRequest.putHeader(AuthenticationService.BASIC_AUTHENTICATION_HEADER, credentialsInBase64);
     214                        }
     215                    }
     216                }
     217            }
     218        } else {
     219            // Requests to SECORE should still be ok without these missing rasguest configurations
     220            if (!httpServletRequest.getRequestURI().contains(ConfigManager.SECORE)) {
     221                Pair<String, String> basicAuthCredentialsPair = null;
     222                try {
     223                    basicAuthCredentialsPair = AuthenticationService.getBasicAuthUsernamePassword(httpServletRequest);
     224                    this.checkValidCredentialsAllowNull(basicAuthCredentialsPair);
     225                } catch (PetascopeException ex) {
     226                    ExceptionUtil.handle(VersionManager.getLatestVersion(WCS_SERVICE), ex, httpServletResponse);
     227                }
     228            }
     229        }
     230
     231        if (authenticationErrorMessage.isEmpty()) {
     232            // requests has no problem with authentication
     233            filterChain.doFilter(request, response);
     234        } else {
     235            // request is not authenticated
     236            PetascopeException petascopeException = new PetascopeException(ExceptionCode.Unauthorized, authenticationErrorMessage);
     237            ExceptionUtil.handle(VersionManager.getLatestVersion(WCS_SERVICE), petascopeException, httpServletResponse);
     238        }
     239    }
     240
     241    @Override
     242    public void init(FilterConfig fc) throws ServletException {
     243    }
     244
     245    @Override
     246    public void destroy() {
     247    }
     248   
     249    // This is needed for adding custom header (e.g Authorization for basic header) to HttpServletRequest object
     250    final public class MutableHttpServletRequest extends HttpServletRequestWrapper {
     251
     252        private final Map<String, String> customHeaders;
     253
     254        public MutableHttpServletRequest(HttpServletRequest request){
     255            super(request);
     256            this.customHeaders = new HashMap<>();
     257        }
     258
     259        public void putHeader(String name, String value){
     260            this.customHeaders.put(name, value);
     261        }
     262
     263        public String getHeader(String name) {
     264            String headerValue = customHeaders.get(name);
     265
     266            if (headerValue != null){
     267                return headerValue;
     268            }
     269            return ((HttpServletRequest) getRequest()).getHeader(name);
     270        }
     271
     272        public Enumeration<String> getHeaderNames() {
     273            Set<String> set = new HashSet<String>(customHeaders.keySet());
     274
     275            @SuppressWarnings("unchecked")
     276            Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
     277            while (e.hasMoreElements()) {
     278                String n = e.nextElement();
     279                set.add(n);
     280            }
     281            return Collections.enumeration(set);
     282        }
     283    }
     284}
     285
  • applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/layer/service/AdminActivateLayerService.java

    diff --git a/applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/layer/service/AdminActivateLayerService.java b/applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/layer/service/AdminActivateLayerService.java
    index d1aaae521..9c9c96ab6 100644
    a b  
    2121 */
    2222package com.rasdaman.admin.layer.service;
    2323
    24 // -- rasdaman enterprise begin
    25 
    2624import com.rasdaman.admin.service.AbstractAdminService;
    2725import petascope.core.response.Response;
    2826import java.util.Map;
  • applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/layer/service/AdminDeactivateLayerService.java

    diff --git a/applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/layer/service/AdminDeactivateLayerService.java b/applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/layer/service/AdminDeactivateLayerService.java
    index c189644ec..7d71f71dc 100644
    a b  
    2222package com.rasdaman.admin.layer.service;
    2323
    2424
    25 // -- rasdaman enterprise begin
    26 
    2725import com.rasdaman.admin.service.AbstractAdminService;
    2826
    2927// -- rasdaman enterprise end
  • applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/model/AuthIsActiveResult.java

    diff --git a/applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/model/AuthIsActiveResult.java b/applications/petascope/petascope_main/src/main/java/com/rasdaman/admin/model/AuthIsActiveResult.java
    index 3c8cada7a..97dfa946f 100644
    a b  
    1 // -- rasdaman enterprise begin
    2 
    31/*
    4  *  Copyright 2003 - 2023 Peter Baumann / rasdaman GmbH.
    5  *  For more information please see <http://www.rasdaman.org>
    6  *  or contact Peter Baumann via <baumann@rasdaman.com>.
     2 * This file is part of rasdaman community.
     3 *
     4 * Rasdaman community is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 3 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * Rasdaman community is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12 * See the GNU  General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU  General Public License
     15 * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
     16 *
     17 * Copyright 2003 - 2023 Peter Baumann / rasdaman GmbH.
     18 *
     19 * For more information please see <http://www.rasdaman.org>
     20 * or contact Peter Baumann via <baumann@rasdaman.com>.
    721 */
    8 
    922package com.rasdaman.admin.model;
    1023
    1124import com.fasterxml.jackson.annotation.JsonProperty;
    public class AuthIsActiveResult {  
    3346        return rasdamanUser;
    3447    }
    3548}
    36 
    37 
    38 // -- rasdaman enterprise end
    39  No newline at end of file
  • applications/petascope/petascope_main/src/main/java/org/rasdaman/ApplicationMain.java

    diff --git a/applications/petascope/petascope_main/src/main/java/org/rasdaman/ApplicationMain.java b/applications/petascope/petascope_main/src/main/java/org/rasdaman/ApplicationMain.java
    index 84794cb63..628e2b3f5 100644
    a b public class ApplicationMain extends SpringBootServletInitializer {  
    329329
    330330        // Test if rasdaman is running first with provided credentials from rasguest and rasadmin
    331331
    332         if (ConfigManager.RASDAMAN_USER.trim().isEmpty() && ConfigManager.RASDAMAN_PASS.trim().isEmpty()) {
    333             AbstractController.startException = new PetascopeException(ExceptionCode.InternalComponentError,
    334                 "petascope does not know which user to query to rasdaman. " +
    335                 "Hint: in petascope.properties set rasdaman_user and rasdaman_pass with valid credentials of a rasdaman user, then restart tomcat service afterwards.");
    336         }
    337 
    338332        if (ConfigManager.RASDAMAN_USER != null && !ConfigManager.RASDAMAN_USER.isEmpty()
    339             && ConfigManager.RASDAMAN_PASS != null && !ConfigManager.RASDAMAN_PASS.isEmpty()) {
     333          && ConfigManager.RASDAMAN_PASS != null && !ConfigManager.RASDAMAN_PASS.isEmpty()) {
    340334            try {
    341335                RasUtil.checkValidUserCredentials(ConfigManager.RASDAMAN_USER, ConfigManager.RASDAMAN_PASS);
    342336            } catch (Exception ex) {
    343337                String errorMessage = "Cannot check if rasdaman is running. Reason: " + ex.getMessage().trim()
    344                     + ". Hint: make sure rasdaman is running, user's credentials are correct and restart tomcat service afterwards.";
     338                        + ". Hint: make sure rasdaman is running, user's credentials are correct and restart tomcat service afterwards.";
    345339                log.error(errorMessage);
    346340                AbstractController.startException = new PetascopeException(ExceptionCode.InternalComponentError, errorMessage);
    347341                return;
    public class ApplicationMain extends SpringBootServletInitializer {  
    353347            RasUtil.checkValidUserCredentials(ConfigManager.RASDAMAN_ADMIN_USER, ConfigManager.RASDAMAN_ADMIN_PASS);
    354348        } catch(Exception ex) {
    355349            String errorMessage = "Cannot check if rasdaman is running. Reason: " + ex.getMessage().trim()
    356                 + ". Hint: make sure rasdaman is running, user's credentials are correct and restart tomcat service afterwards.";
     350                                + ". Hint: make sure rasdaman is running, user's credentials are correct and restart tomcat service afterwards.";
    357351            log.error(errorMessage);
    358352            AbstractController.startException = new PetascopeException(ExceptionCode.InternalComponentError, errorMessage);
    359353            return;
    public class ApplicationMain extends SpringBootServletInitializer {  
    362356        CrsUtil.setInternalResolverCRSToQualifiedCRS();
    363357        CrsUtil.currentWorkingResolverURL = ConfigManager.SECORE_URLS.get(0);
    364358
     359        if (ConfigManager.RASDAMAN_USER.trim().isEmpty() && ConfigManager.RASDAMAN_PASS.trim().isEmpty()
     360                && !ConfigManager.enableAuthentication()
     361        ) {
     362            AbstractController.startException = new PetascopeException(ExceptionCode.InternalComponentError,
     363                    "No authentication is enabled, hence, petascope does not know which user to query to rasdaman.\n" +
     364                            "Hint: in petascope.properties either change to authentication_type=basic_header " +
     365                            "or set rasdaman_user and rasdaman_pass with valid credentials of a rasdaman user, then restart petascope.");
     366        }
     367
    365368    }
    366369
    367370    @EventListener(ApplicationReadyEvent.class)
  • applications/petascope/petascope_main/src/main/java/org/rasdaman/datamigration/DataMigration8Handler.java

    diff --git a/applications/petascope/petascope_main/src/main/java/org/rasdaman/datamigration/DataMigration8Handler.java b/applications/petascope/petascope_main/src/main/java/org/rasdaman/datamigration/DataMigration8Handler.java
    index 9d0a60823..b8b451177 100644
    a b  
    1 // -- rasdaman enterprise begin
     1/*
     2 * This file is part of rasdaman community.
     3 *
     4 * Rasdaman community is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 3 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * Rasdaman community is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12 * See the GNU  General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU  General Public License
     15 * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
     16 *
     17 * Copyright 2003 - 2023 Peter Baumann / rasdaman GmbH.
     18 *
     19 * For more information please see <http://www.rasdaman.org>
     20 * or contact Peter Baumann via <baumann@rasdaman.com>.
     21 */
    222
    323package org.rasdaman.datamigration;
    424import com.rasdaman.admin.layer.service.AdminCreateOrUpdateLayerService;
    public class DataMigration8Handler extends AbstractDataMigrationHandler {  
    5171   
    5272}
    5373
    54 // -- rasdaman enterprise end
    55  No newline at end of file
  • applications/petascope/petascope_main/src/main/java/org/rasdaman/datamigration/DataMigration9Handler.java

    diff --git a/applications/petascope/petascope_main/src/main/java/org/rasdaman/datamigration/DataMigration9Handler.java b/applications/petascope/petascope_main/src/main/java/org/rasdaman/datamigration/DataMigration9Handler.java
    index b43684142..b292496b7 100644
    a b  
    1 // -- rasdaman enterprise begin
     1/*
     2 * This file is part of rasdaman community.
     3 *
     4 * Rasdaman community is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 3 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * Rasdaman community is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12 * See the GNU  General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU  General Public License
     15 * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
     16 *
     17 * Copyright 2003 - 2023 Peter Baumann / rasdaman GmbH.
     18 *
     19 * For more information please see <http://www.rasdaman.org>
     20 * or contact Peter Baumann via <baumann@rasdaman.com>.
     21 */
    222
    323package org.rasdaman.datamigration;
    424import org.rasdaman.domain.cis.Coverage;
    public class DataMigration9Handler extends AbstractDataMigrationHandler {  
    4060    }
    4161   
    4262}
    43 
    44 // -- rasdaman enterprise end
    45  No newline at end of file
  • applications/petascope/petascope_main/src/main/java/petascope/controller/AbstractController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/AbstractController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/AbstractController.java
    index dd2d3b42a..c22acfea3 100644
    a b  
    2222package petascope.controller;
    2323
    2424import com.rasdaman.accesscontrol.service.AuthenticationService;
     25
     26import java.io.File;
    2527import java.io.IOException;
    2628import java.io.OutputStream;
    2729import java.nio.file.Files;
    import org.apache.commons.io.IOUtils;  
    4345import org.apache.commons.lang3.StringEscapeUtils;
    4446import org.apache.maven.wagon.util.FileUtils;
    4547import org.rasdaman.config.ConfigManager;
     48
     49import static com.rasdaman.accesscontrol.service.AuthenticationService.*;
    4650import static org.rasdaman.config.ConfigManager.UPLOADED_FILE_DIR_TMP;
    4751import static org.rasdaman.config.ConfigManager.UPLOAD_FILE_PREFIX;
    4852import org.rasdaman.config.VersionManager;
    import petascope.controller.handler.service.AbstractHandler;  
    5660import petascope.controller.handler.service.XMLWCSServiceHandler;
    5761import petascope.core.KVPSymbols;
    5862import static petascope.core.KVPSymbols.KEY_ACCEPTVERSIONS;
    59 
    60 
    6163import static petascope.core.KVPSymbols.KEY_REQUEST;
    6264import static petascope.core.KVPSymbols.VALUE_INSERT_COVERAGE;
    6365import static petascope.core.KVPSymbols.VALUE_UPDATE_COVERAGE;
    public abstract class AbstractController {  
    979981        return sourceIP;
    980982    }
    981983
     984    /**
     985     * Check if user has a specific role to process request
     986     */
     987    public void validateUserPermission(HttpServletRequest httpServletRequest, String... inputRoleNames) throws PetascopeException {
     988        Pair<String, String> credentialsPair = getBasicAuthCredentialsOrRasguest(httpServletRequest);
     989        String username = credentialsPair.fst;
     990
     991        Set<String> userRoles = AuthenticationController.parseRolesFromRascontrol(username);
     992
     993        for (String roleName : inputRoleNames) {
     994            if (!userRoles.contains(roleName)) {
     995                String requestRepresentation = this.getRequestPresentationWithEncodedAmpersands(httpServletRequest);
     996
     997                Pair<String, String> basicAuthCredentialsPair = getBasicAuthUsernamePassword(httpServletRequest);
     998
     999                ExceptionCode exceptionCode = ExceptionCode.AccessDenied;
     1000                if (basicAuthCredentialsPair == null) {
     1001                    // In this case rasguest user is set in petascope.properties, but the user doesn't have the permission to run
     1002                    exceptionCode = ExceptionCode.Unauthorized;
     1003                }
     1004
     1005                throw new PetascopeException(exceptionCode,
     1006                                                "User '" + username + "' does not have role '" + roleName + "' to process request '" + requestRepresentation + "'.");
     1007            }
     1008        }
     1009    }
     1010
     1011    /**
     1012     * The user requests must have the role if basic header is enabled, or his IP must be allowed
     1013     */
     1014    public void validateWriteRequestByRoleOrAllowedIP(HttpServletRequest httpServletRequest,
     1015                                                      String roleName) throws PetascopeException {
     1016
     1017        if (ConfigManager.enableAuthentication() || getBasicAuthUsernamePassword(httpServletRequest) != null) {
     1018            // + user must have the specific role, otherwise exception
     1019            this.validateUserPermission(httpServletRequest, roleName);
     1020        } else {
     1021            // + user's IP must be from allowed write request setting, otherwise exception
     1022            validateWriteRequestFromIP(httpServletRequest);
     1023        }
     1024    }
     1025
    9821026    /**
    9831027     * If basic authentication header is not enabled, then petascope checks if write request from IP address is valid or not
    9841028     * before processing.
    9851029     */
    986     public void validateWriteRequestFromIP(HttpServletRequest httpServletRequest) throws PetascopeException {
     1030    private void validateWriteRequestFromIP(HttpServletRequest httpServletRequest) throws PetascopeException {
    9871031        if (!ConfigManager.ALLOW_WRITE_REQUESTS_FROM.contains(ConfigManager.PUBLIC_WRITE_REQUESTS_FROM)) {
    9881032           
    9891033            String sourceIP = this.getRequestIPAddress(httpServletRequest);
  • applications/petascope/petascope_main/src/main/java/petascope/controller/AuthenticationController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/AuthenticationController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/AuthenticationController.java
    index 6218ae454..28b40eff1 100644
    a b import com.rasdaman.accesscontrol.service.AuthenticationService;  
    2626import java.io.BufferedReader;
    2727import java.io.IOException;
    2828import java.io.InputStreamReader;
    29 import static java.lang.System.in;
    30 import java.util.ArrayList;
    31 import java.util.Arrays;
    32 import java.util.LinkedHashSet;
    33 import java.util.Map;
    34 import java.util.Set;
    35 import java.util.logging.Level;
    36 import java.util.logging.Logger;
     29
     30import java.util.*;
    3731import java.util.regex.Matcher;
    3832import java.util.regex.Pattern;
    3933import javax.servlet.http.HttpServletRequest;
    import org.rasdaman.config.ConfigManager;  
    4135import static org.rasdaman.config.ConfigManager.CHECK_PETASCOPE_ENABLE_AUTHENTICATION_CONTEXT_PATH;
    4236
    4337import org.rasdaman.rasnet.util.DigestUtils;
    44 import org.springframework.beans.factory.annotation.Autowired;
    4538import org.springframework.web.bind.annotation.RequestMapping;
    4639import org.springframework.web.bind.annotation.RestController;
    4740import petascope.core.Pair;
    public class AuthenticationController extends AbstractController {  
    6558   
    6659    public static final String READ_WRITE_RIGHTS = "RW";
    6760
     61    private static final Map<String, Set<String>> userRolesCacheMap = new LinkedHashMap<>();
     62
     63    /**
     64     * Check if petascope has being enabled authentication in petascope.properties,
     65     * then WSClient shows a login form.
     66     */
    6867    @RequestMapping(value = CHECK_PETASCOPE_ENABLE_AUTHENTICATION_CONTEXT_PATH)
    6968    private void handleCheckEnableAuthentication() throws Exception {
    7069        if (startException != null) {
    7170            throw startException;
    7271        }
    7372
     73        boolean basicAuthenticationHeaderEnabled = false;
    7474        String rasdamanUser = "";
     75
     76        if (ConfigManager.enableAuthentication()) {
     77            basicAuthenticationHeaderEnabled = true;
     78        }
     79
    7580        if (!ConfigManager.RASDAMAN_USER.trim().isEmpty()
    7681                && !ConfigManager.RASDAMAN_PASS.trim().isEmpty()) {
    7782            rasdamanUser = ConfigManager.RASDAMAN_USER;
    7883        }
    7984
    80         AuthIsActiveResult result = new AuthIsActiveResult(false, rasdamanUser);
     85        AuthIsActiveResult result = new AuthIsActiveResult(basicAuthenticationHeaderEnabled, rasdamanUser);
    8186        Response response = new Response(Arrays.asList(JSONUtil.serializeObjectToJSONString(result).getBytes()), MIMEUtil.MIME_JSON);
    8287        this.writeResponseResult(response);
    8388    }
    public class AuthenticationController extends AbstractController {  
    95100       
    96101        String username = resultPair.fst;
    97102        String password = resultPair.snd;
    98        
     103
    99104        String result = "";
    100105       
    101106        RasUtil.checkValidUserCredentials(username, password);
    public class AuthenticationController extends AbstractController {  
    119124     * @TODO: this can be done faster and better with protobuf/grpc
    120125     */
    121126    public static Set<String> parseRolesFromRascontrol(String username) throws PetascopeException {
     127        Set<String> roleNames = userRolesCacheMap.get(username);
     128        if (roleNames != null) {
     129            System.out.println("############# user roles from cache: " + username);
     130            return roleNames;
     131        }
     132
    122133        try {
    123134            // export RASLOGIN=rasadmin:d293a15562d3e70b6fdc5ee452eaed40 && rascontrol -q -e -x list user -rights
    124135            Runtime runtime = Runtime.getRuntime();
    125136           
    126             Set<String> roleNames = new LinkedHashSet<>();
     137            roleNames = new LinkedHashSet<>();
    127138           
    128139            String loginEnv = ConfigManager.RASDAMAN_ADMIN_USER + ":" + DigestUtils.MD5(ConfigManager.RASDAMAN_ADMIN_PASS);
    129140            String[] envp = new String[] {"RASLOGIN=" + loginEnv};
    public class AuthenticationController extends AbstractController {  
    160171                    }
    161172                }
    162173            }
     174
     175            System.out.println("#### Put roles of user: " + username + " to cache.");
     176            userRolesCacheMap.put(username, roleNames);
    163177           
    164178            return roleNames;
    165179        } catch (IOException ex) {
  • applications/petascope/petascope_main/src/main/java/petascope/controller/InspireController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/InspireController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/InspireController.java
    index c84d7d711..30e99bdea 100644
    a b  
    2222package petascope.controller;
    2323
    2424
    25 import com.rasdaman.accesscontrol.service.AuthenticationService;
    2625import java.util.Map;
    2726import javax.servlet.http.HttpServletRequest;
    2827import org.rasdaman.config.ConfigManager;
    public class InspireController extends AbstractController {  
    7170    @Override
    7271    protected void requestDispatcher(HttpServletRequest httpServletRequest, Map<String, String[]> kvpParameters) throws PetascopeException {
    7372       
    74         this.validateWriteRequestFromIP(httpServletRequest);
     73        this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    7574       
    7675        String coverageId = this.getValueByKeyAllowNull(kvpParameters, KEY_INSPIRE_COVERAGE_ID);
    7776        String metadataURL = this.getValueByKeyAllowNull(kvpParameters, KEY_INSPIRE_METADATA_URL);
  • applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminLayerManagementController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminLayerManagementController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminLayerManagementController.java
    index fbfccac08..98e72cb5e 100644
    a b import org.springframework.web.bind.annotation.RequestMapping;  
    3434import org.springframework.web.bind.annotation.RequestMethod;
    3535import org.springframework.web.bind.annotation.RestController;
    3636import petascope.controller.AbstractController;
     37import petascope.controller.AuthenticationController;
    3738import petascope.controller.RequestHandlerInterface;
    3839import petascope.core.KVPSymbols;
    3940import petascope.core.response.Response;
    public class AdminLayerManagementController extends AbstractController {  
    105106       
    106107        RequestHandlerInterface requestHandlerInterface = () -> {
    107108            try {
    108                 this.validateWriteRequestFromIP(httpServletRequest);
     109                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    109110                this.activateLayerService.handle(httpServletRequest, kvpParameters);
    110111            } catch (Exception ex) {
    111112                ExceptionUtil.handle(VersionManager.getLatestVersion(KVPSymbols.WMS_SERVICE), ex, this.injectedHttpServletResponse);
    public class AdminLayerManagementController extends AbstractController {  
    132133       
    133134        RequestHandlerInterface requestHandlerInterface = () -> {
    134135            try {
    135                 this.validateWriteRequestFromIP(httpServletRequest);
     136                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    136137                this.deactivateLayerService.handle(httpServletRequest, kvpParameters);
    137138            } catch (Exception ex) {
    138139                ExceptionUtil.handle(VersionManager.getLatestVersion(KVPSymbols.WMS_SERVICE), ex, this.injectedHttpServletResponse);
  • applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminOwsServiceInfoController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminOwsServiceInfoController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminOwsServiceInfoController.java
    index 4fabf58b4..89f9d281c 100644
    a b import org.slf4j.LoggerFactory;  
    3636import org.springframework.beans.factory.annotation.Autowired;
    3737import org.springframework.web.bind.annotation.RequestMapping;
    3838import org.springframework.web.bind.annotation.RequestMethod;
     39import petascope.controller.AuthenticationController;
    3940import petascope.exceptions.PetascopeException;
    4041import petascope.exceptions.SecoreException;
    4142import petascope.exceptions.WCSException;
    public class AdminOwsServiceInfoController extends AbstractController {  
    107108       
    108109        RequestHandlerInterface requestHandlerInterface = () -> {
    109110            try {
    110                 this.validateWriteRequestFromIP(httpServletRequest);
     111                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    111112                this.handle(kvpParameters);
    112113            } catch (Exception ex) {
    113114                ExceptionUtil.handle(VersionManager.getLatestVersion(KVPSymbols.WCS_SERVICE), ex, this.injectedHttpServletResponse);
  • applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminPyramidController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminPyramidController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminPyramidController.java
    index 3cfdb029d..cb7be9e47 100644
    a b import org.springframework.web.bind.annotation.RequestMapping;  
    3737import org.springframework.web.bind.annotation.RequestMethod;
    3838import org.springframework.web.bind.annotation.RestController;
    3939import petascope.controller.AbstractController;
     40import petascope.controller.AuthenticationController;
    4041import petascope.controller.RequestHandlerInterface;
    4142import petascope.core.KVPSymbols;
    4243import petascope.core.response.Response;
    public class AdminPyramidController extends AbstractController {  
    109110       
    110111        RequestHandlerInterface requestHandlerInterface = () -> {
    111112            try {
    112                 this.validateWriteRequestFromIP(httpServletRequest);
     113                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    113114
    114115                this.addPyramidMemberService.handle(httpServletRequest, kvpParameters);
    115116            } catch (Exception ex) {
    public class AdminPyramidController extends AbstractController {  
    137138       
    138139        RequestHandlerInterface requestHandlerInterface = () -> {
    139140            try {
    140                 this.validateWriteRequestFromIP(httpServletRequest);
     141                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    141142
    142143                this.removePyramidMemberService.handle(httpServletRequest, kvpParameters);
    143144            } catch (Exception ex) {
    public class AdminPyramidController extends AbstractController {  
    165166       
    166167        RequestHandlerInterface requestHandlerInterface = () -> {
    167168            try {
    168                 this.validateWriteRequestFromIP(httpServletRequest);
     169                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    169170
    170171                this.createPyramidMemberService.handle(httpServletRequest, kvpParameters);
    171172            } catch (Exception ex) {
  • applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminStyleManagementController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminStyleManagementController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminStyleManagementController.java
    index 3f9ba1f64..573c5b1ff 100644
    a b import org.springframework.web.bind.annotation.RequestMapping;  
    3434import org.springframework.web.bind.annotation.RequestMethod;
    3535import org.springframework.web.bind.annotation.RestController;
    3636import petascope.controller.AbstractController;
     37import petascope.controller.AuthenticationController;
    3738import petascope.controller.RequestHandlerInterface;
    3839import petascope.core.KVPSymbols;
    3940import petascope.exceptions.PetascopeException;
    public class AdminStyleManagementController extends AbstractController {  
    7475       
    7576        RequestHandlerInterface requestHandlerInterface = () -> {
    7677            try {
    77                 this.validateWriteRequestFromIP(httpServletRequest);
     78                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    7879
    7980                this.createOrUpdateStyleService.handleAdd(httpServletRequest, kvpParameters);
    8081            } catch (Exception ex) {
    public class AdminStyleManagementController extends AbstractController {  
    102103       
    103104        RequestHandlerInterface requestHandlerInterface = () -> {
    104105            try {
    105                 this.validateWriteRequestFromIP(httpServletRequest);
     106                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    106107
    107108                this.createOrUpdateStyleService.handleUpdate(httpServletRequest, kvpParameters);
    108109            } catch (Exception ex) {
    public class AdminStyleManagementController extends AbstractController {  
    130131       
    131132        RequestHandlerInterface requestHandlerInterface = () -> {
    132133            try {
    133                 this.validateWriteRequestFromIP(httpServletRequest);
     134                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    134135
    135136                this.adminDeleteStyleService.handle(httpServletRequest, kvpParameters);
    136137            } catch (Exception ex) {
  • applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminUpdateCoverageController.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminUpdateCoverageController.java b/applications/petascope/petascope_main/src/main/java/petascope/controller/admin/AdminUpdateCoverageController.java
    index 38f8cba26..0dd6b35ce 100644
    a b import org.springframework.web.bind.annotation.RestController;  
    3838import org.springframework.web.multipart.MultipartFile;
    3939import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
    4040import petascope.controller.AbstractController;
     41import petascope.controller.AuthenticationController;
    4142import petascope.controller.RequestHandlerInterface;
    4243import petascope.core.KVPSymbols;
    4344import static petascope.core.KVPSymbols.KEY_METADATA;
    public class AdminUpdateCoverageController extends AbstractController {  
    8182       
    8283        RequestHandlerInterface requestHandlerInterface = () -> {
    8384            try {
    84                 this.validateWriteRequestFromIP(httpServletRequest);
     85                this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    8586
    8687                this.adminUpdateCoverageService.handle(httpServletRequest, kvpParameters);
    8788            } catch (Exception ex) {
  • applications/petascope/petascope_main/src/main/java/petascope/util/IPAddressUtil.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/util/IPAddressUtil.java b/applications/petascope/petascope_main/src/main/java/petascope/util/IPAddressUtil.java
    index e444816bc..093e5817b 100644
    a b  
    1 // -- rasdaman enterprise begin
    2 
    31/*
    4  *  Copyright 2003 - 2019 Peter Baumann / rasdaman GmbH.
    5  *  For more information please see <http://www.rasdaman.org>
    6  *  or contact Peter Baumann via <baumann@rasdaman.com>.
     2 * This file is part of rasdaman community.
     3 *
     4 * Rasdaman community is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 3 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * Rasdaman community is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12 * See the GNU  General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU  General Public License
     15 * along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
     16 *
     17 * Copyright 2003 - 2023 Peter Baumann / rasdaman GmbH.
     18 *
     19 * For more information please see <http://www.rasdaman.org>
     20 * or contact Peter Baumann via <baumann@rasdaman.com>.
    721 */
    822
    923package petascope.util;
    public class IPAddressUtil {  
    105119    }
    106120   
    107121}
    108 
    109 
    110 // -- rasdaman enterprise end
    111  No newline at end of file
  • applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/DeleteCoverageHandler.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/DeleteCoverageHandler.java b/applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/DeleteCoverageHandler.java
    index c7f041562..a7d7c2f76 100644
    a b  
    2121 */
    2222package petascope.wcst.handlers;
    2323
    24 import com.rasdaman.accesscontrol.service.AuthenticationService;
    2524import java.util.ArrayList;
    2625import java.util.List;
    2726import javax.servlet.http.HttpServletRequest;
    import org.rasdaman.repository.service.WMSRepostioryService;  
    3837import org.slf4j.LoggerFactory;
    3938import org.springframework.beans.factory.annotation.Autowired;
    4039import org.springframework.stereotype.Service;
     40import petascope.controller.AuthenticationController;
    4141import petascope.controller.PetascopeController;
    4242import petascope.exceptions.PetascopeException;
    4343import petascope.exceptions.WMSException;
    import petascope.wcst.parsers.DeleteCoverageRequest;  
    5555import petascope.wms.handlers.service.WMSGetMapCachingService;
    5656import org.rasdaman.repository.service.WMTSRepositoryService;
    5757import petascope.util.CrsUtil;
    58 import petascope.wmts.handlers.service.WMTSGetCapabilitiesService;
    5958
    6059/**
    6160 * Handles the deletion of a coverage.
    public class DeleteCoverageHandler {  
    8685    private static final org.slf4j.Logger log = LoggerFactory.getLogger(DeleteCoverageHandler.class);
    8786
    8887    public Response handle(DeleteCoverageRequest request) throws Exception {
    89        
    90         petascopeController.validateWriteRequestFromIP(httpServletRequest);
     88
     89        this.petascopeController.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    9190       
    9291        String username = ConfigManager.RASDAMAN_ADMIN_USER;
    9392        String password = ConfigManager.RASDAMAN_ADMIN_PASS;
  • applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/InsertCoverageHandler.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/InsertCoverageHandler.java b/applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/InsertCoverageHandler.java
    index 04edb922b..f4bc4b59f 100644
    a b  
    2121 */
    2222package petascope.wcst.handlers;
    2323
    24 import com.rasdaman.accesscontrol.service.AuthenticationService;
    2524import java.io.File;
    2625import java.io.IOException;
    2726import java.util.ArrayList;
    import org.rasdaman.repository.service.CoverageRepositoryService;  
    4241import org.slf4j.LoggerFactory;
    4342import org.springframework.beans.factory.annotation.Autowired;
    4443import org.springframework.stereotype.Service;
     44import petascope.controller.AuthenticationController;
    4545import petascope.controller.PetascopeController;
    4646import petascope.exceptions.PetascopeException;
    4747import petascope.exceptions.SecoreException;
    public class InsertCoverageHandler {  
    103103     */
    104104    public Response handle(InsertCoverageRequest request) throws Exception {
    105105        log.debug("Handling coverage insertion...");
    106         this.petascopeController.validateWriteRequestFromIP(httpServletRequest);
     106        this.petascopeController.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    107107       
    108108        if (request.getGMLCoverage() != null) {
    109109            return handleGMLCoverageInsert(request);
  • applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/UpdateCoverageHandler.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/UpdateCoverageHandler.java b/applications/petascope/petascope_main/src/main/java/petascope/wcst/handlers/UpdateCoverageHandler.java
    index c87d7d05c..733c00b93 100644
    a b  
    2727 */
    2828package petascope.wcst.handlers;
    2929
    30 import com.rasdaman.accesscontrol.service.AuthenticationService;
    3130import com.rasdaman.admin.layer.service.AdminCreateOrUpdateLayerService;
    3231
     32import petascope.controller.AuthenticationController;
    3333import petascope.core.Pair;
    3434import petascope.core.XMLSymbols;
    3535import petascope.core.gml.cis10.GMLCIS10ParserService;
    public class UpdateCoverageHandler {  
    143143    public Response handle(UpdateCoverageRequest request)
    144144            throws WCSTCoverageParameterNotFound, WCSTInvalidXML, PetascopeException, SecoreException, Exception {
    145145        log.debug("Handling coverage update...");
    146        
    147         this.petascopeController.validateWriteRequestFromIP(httpServletRequest);
     146
     147        this.petascopeController.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS);
    148148       
    149149        // persisted coverage
    150150        Coverage currentCoverage = persistedCoverageService.readCoverageByIdFromDatabase(request.getCoverageId());
  • applications/petascope/petascope_main/src/main/java/petascope/wcst/helpers/update/RasdamanUpdaterFactory.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/wcst/helpers/update/RasdamanUpdaterFactory.java b/applications/petascope/petascope_main/src/main/java/petascope/wcst/helpers/update/RasdamanUpdaterFactory.java
    index 3513732c2..361dbe359 100644
    a b public class RasdamanUpdaterFactory {  
    7272        }
    7373    }
    7474
    75     private String getInsituMime(String mimeType) {
    76         if (mimeType.contains(IOUtil.GRIB_MIMETYPE)) {
    77             return IOUtil.GRIB_MIMETYPE;
    78         } else if (mimeType.contains(IOUtil.NETCDF_MIMETYPE)) {
    79             return IOUtil.NETCDF_MIMETYPE;
    80         } else {
    81             return IOUtil.GDAL_MIMETYPE;
    82         }
    83     }
    84 
    85     // -- rasdaman enterprise ends
    86 
    8775    /**
    8876     * To improves ingestion performance if the data is on the same machine as the rasdaman server, as the network transport is bypassed
    8977     * we add the filePaths parameter into RangeElement strings
  • applications/petascope/petascope_main/src/main/java/petascope/wms/handlers/service/WMSGetMapStyleService.java

    diff --git a/applications/petascope/petascope_main/src/main/java/petascope/wms/handlers/service/WMSGetMapStyleService.java b/applications/petascope/petascope_main/src/main/java/petascope/wms/handlers/service/WMSGetMapStyleService.java
    index 702ccd5ca..91714becd 100644
    a b public class WMSGetMapStyleService {  
    8989    private WMSGetMapWCPSMetadataTranslatorService wmsGetMapWCPSMetadataTranslatorService;
    9090    @Autowired
    9191    private WcpsCoverageMetadataTranslator wcpsCoverageMetadataTranslator;   
    92    
    93     // -- rasdaman enteprise begin
    94    
     92
    9593    public static final String WMS_VIRTUAL_LAYER_EXPECTED_BBOX = "BBOX";
    9694    public static final String WMS_VIRTUAL_LAYER_EXPECTED_WIDTH = "WIDTH";
    9795    public static final String WMS_VIRTUAL_LAYER_EXPECTED_HEIGHT = "HEIGHT";
    9896    public static final String WMS_VIRTUAL_LAYER_EXPECTED_OUTPUT_CRS = "OUTPUT_CRS";
    99    
    100     // -- rasdaman enterprise end
    101    
     97
    10298    public static final String FRAGMENT_ITERATOR_PREFIX = "$";
    10399    private static final String COLLECTION_ITERATOR = "c";
    104100    public static final String WCPS_FRAGMENT_ITERATOR = FRAGMENT_ITERATOR_PREFIX + COLLECTION_ITERATOR;
  • applications/petascope/petascope_main/src/main/resources/petascope.properties.in

    diff --git a/applications/petascope/petascope_main/src/main/resources/petascope.properties.in b/applications/petascope/petascope_main/src/main/resources/petascope.properties.in
    index 775f88315..de2c14e66 100644
    a b static_html_dir_path=  
    8080rasdaman_url=http://localhost:7001
    8181rasdaman_database=RASBASE
    8282
    83 rasdaman_user=rasguest
    84 rasdaman_pass=rasguest
     83rasdaman_user=
     84rasdaman_pass=
    8585rasdaman_admin_user=rasadmin
    8686rasdaman_admin_pass=rasadmin
    8787
    rasdaman_bin_path=@GENERATED_rasdaman_bin_path@  
    9292
    9393#---------------------------- Security configuration ---------------------------
    9494
     95authentication_type=basic_header
    9596allow_write_requests_from=127.0.0.1
    9697
    9798# Used only for embedded petascope deployment
  • doc/main/05_geo-services-guide-petascope-configuration.inc

    diff --git a/doc/main/05_geo-services-guide-petascope-configuration.inc b/doc/main/05_geo-services-guide-petascope-configuration.inc
    index e548858b5..40d50edce 100644
    a b Rasdaman  
    276276    - Need to change: NO, unless changed in rasdaman (not recommended)
    277277
    278278
    279 -   ``rasdaman_user`` set the user for **unauthenticated** read-only access to
    280     rasdaman. Any request which does not provide credentials for a rasdaman user in
    281     basic authentication format in the HTTP Authorization header, will entail
    282     executing read-only operations with this user in rasdaman.
    283     It is best to limit this user to read-only access in rasdaman by granting
    284     the ``R`` permission to it.
     279-   ``rasdaman_user`` set the user for **unauthenticated** access to rasdaman.
     280
     281    When authentication is disabled by setting ``authentication_type=`` in
     282    petascope.properties, this user is used to run ``SELECT`` rasql queries,
     283    so it is best to limit it to read-only access in rasdaman (e.g. by granting
     284    the ``R`` role to it).
     285
     286    When authentication is enabled by setting ``authentication_type=basic_header``,
     287    then this setting allows to control whether any unauthenticated access is
     288    enabled.
     289
     290    If it is not set to anything with ``rasdaman_user=``, then unauthenticated
     291    access is disabled and any request without credentials will be immediately
     292    denied.
     293
     294    If it is set to some valid rasdaman user (e.g. ``rasdaman_user=rasguest``),
     295    then unauthenticated requests which do not specify any credentials will
     296    be executed with this user and its corresponding password set with
     297    ``rasdaman_pass``.
    285298
    286299    - Default: ``rasguest``
    287300
    Rasdaman  
    297310    - Need to change: **YES** when changed in rasdaman   
    298311
    299312
    300 -   ``rasdaman_admin_user`` this user is used to map updating OGC requests
    301     (e.g. during data import, or deleting coverages) to updating rasql queries, for
    302     any request which does not provide credentials for a rasdaman user in
    303     basic authentication format in the HTTP Authorization header.
    304     Additionally, these credentials are used internally for various tasks which require
    305     admin access rights in rasdaman.
     313-   ``rasdaman_admin_user`` when authentication is disabled with
     314    ``authentication_type=``, this user will be used for executing update
     315    queries in rasdaman, if they come from an allowed IP address as configured
     316    in :ref:`allow_write_requests_from <conf-allow-write-requests-from>`. When
     317    authentication is enabled, these credentials are not used for executing
     318    user requests. However, in both cases they are also needed internally for
     319    various tasks.
    306320
    307     Generally, this user should be granted full admin permissions.
     321    Generally, this user should be granted the ``RW`` rasdaman role.
    308322
    309323    - Default: ``rasadmin``
    310324
    Rasdaman  
    349363Security
    350364^^^^^^^^
    351365
     366-   ``authentication_type`` specifies how to authenticate requests.
     367    Valid values are:
     368
     369    - ``basic_header`` requires requests to attach ``username:password`` encoded
     370      as a Base64 string to the HTTP header. If the ``rasdaman_user`` setting is
     371      not empty, however, requests without credentials will be automatically
     372      mapped to the user and password configured in ``rasdaman_user`` and
     373      ``rasdaman_pass``; thereby unauthenticated access can be allowed, but
     374      limited to some restricted rasdaman user.
     375
     376    - An empty string, i.e. ``authentication_type=``, disables authentication.
     377      All requests will be forwarded to rasdaman with the credentials configured
     378      with ``rasdaman_user`` / ``rasdaman_pass`` for read queries, and
     379      ``rasdaman_admin_user`` / ``rasdaman_admin_pass`` for update queries.
     380     
     381    - Default if the setting does not exist, it is set to ``basic_header``.
     382
    352383
    353384.. _conf-allow-write-requests-from:
    354385