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 , 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 { 107 107 // context path for OAPI endpoint (e.g: localhost:8080/rasdaman/oapi) 108 108 public static final String OAPI = "oapi"; 109 109 110 // For community this endpoint always return fasle, it is used to check that if petascope is running from wsclient110 // Check if petascope has enabled authentication in petascope.properties 111 111 public static final String CHECK_PETASCOPE_ENABLE_AUTHENTICATION = "authisactive"; 112 112 public static final String CHECK_PETASCOPE_ENABLE_AUTHENTICATION_CONTEXT_PATH = ADMIN + "/authisactive"; 113 113 … … public class ConfigManager { 291 291 public static String INSPIRE_COMMON_URL = ""; 292 292 public static String INSPIRE_SPATIAL_DATASET_IDENTIFIER = "rasdaman"; 293 293 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 294 298 // rasj 295 299 private static final String KEY_RASJ_LOGGING_LEVEL = "rasj_logging_level"; 296 300 public static String RASJ_LOGGING_LEVEL = RasjLoggingLevel.WARN.name(); … … public class ConfigManager { 382 386 383 387 initRasj(); 384 388 389 initAuthenticationTypesSetting(); 390 385 391 printStartupMessage(); 386 392 387 393 GDAL_JAVA_VERSION = Byte.parseByte(gdal.VersionInfo().substring(0, 1)); … … public class ConfigManager { 433 439 434 440 return value; 435 441 } 442 443 private boolean containsProperty(String key) { 444 return props.get(key) != null; 445 } 436 446 437 447 private void initPetascopeSettings() throws PetascopeException { 438 448 // server.port … … public class ConfigManager { 740 750 741 751 log.info("------------------------------------"); 742 752 } 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 } 743 774 } 744 775 -
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 { 122 122 InputStream inputStream = urlConnection.getInputStream(); 123 123 return inputStream; 124 124 } 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 } 125 155 126 156 } -
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 */ 22 package com.rasdaman.accesscontrol.service; 23 24 import java.io.IOException; 25 import java.util.*; 26 import javax.servlet.Filter; 27 import javax.servlet.FilterChain; 28 import javax.servlet.FilterConfig; 29 import javax.servlet.ServletException; 30 import javax.servlet.ServletRequest; 31 import javax.servlet.ServletResponse; 32 import javax.servlet.http.HttpServletRequest; 33 import javax.servlet.http.HttpServletRequestWrapper; 34 import javax.servlet.http.HttpServletResponse; 35 36 import org.apache.commons.lang3.StringUtils; 37 import org.rasdaman.CorsFilter; 38 import org.rasdaman.config.ConfigManager; 39 import static org.rasdaman.config.ConfigManager.ADMIN; 40 import static org.rasdaman.config.ConfigManager.AUTHENTICATION_TYPE_BASIC_HEADER; 41 import static org.rasdaman.config.ConfigManager.OWS; 42 import static org.rasdaman.config.ConfigManager.RASQL; 43 import org.rasdaman.config.VersionManager; 44 import org.springframework.beans.factory.annotation.Autowired; 45 import org.springframework.stereotype.Component; 46 47 import static org.rasdaman.config.ConfigManager.*; 48 import static org.rasdaman.config.ConfigManager.PETASCOPE_ENDPOINT_URL; 49 import static petascope.core.KVPSymbols.WCS_SERVICE; 50 import petascope.core.Pair; 51 import petascope.exceptions.ExceptionCode; 52 import petascope.exceptions.PetascopeException; 53 import petascope.util.ExceptionUtil; 54 import petascope.util.ras.RasUtil; 55 import static org.rasdaman.config.ConfigManager.CHECK_PETASCOPE_ENABLE_AUTHENTICATION; 56 import static org.rasdaman.config.ConfigManager.SECORE; 57 import 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 66 public 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 21 21 */ 22 22 package com.rasdaman.admin.layer.service; 23 23 24 // -- rasdaman enterprise begin25 26 24 import com.rasdaman.admin.service.AbstractAdminService; 27 25 import petascope.core.response.Response; 28 26 import 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 22 22 package com.rasdaman.admin.layer.service; 23 23 24 24 25 // -- rasdaman enterprise begin26 27 25 import com.rasdaman.admin.service.AbstractAdminService; 28 26 29 27 // -- 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 begin2 3 1 /* 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>. 7 21 */ 8 9 22 package com.rasdaman.admin.model; 10 23 11 24 import com.fasterxml.jackson.annotation.JsonProperty; … … public class AuthIsActiveResult { 33 46 return rasdamanUser; 34 47 } 35 48 } 36 37 38 // -- rasdaman enterprise end39 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 { 329 329 330 330 // Test if rasdaman is running first with provided credentials from rasguest and rasadmin 331 331 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 338 332 if (ConfigManager.RASDAMAN_USER != null && !ConfigManager.RASDAMAN_USER.isEmpty() 339 333 && ConfigManager.RASDAMAN_PASS != null && !ConfigManager.RASDAMAN_PASS.isEmpty()) { 340 334 try { 341 335 RasUtil.checkValidUserCredentials(ConfigManager.RASDAMAN_USER, ConfigManager.RASDAMAN_PASS); 342 336 } catch (Exception ex) { 343 337 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."; 345 339 log.error(errorMessage); 346 340 AbstractController.startException = new PetascopeException(ExceptionCode.InternalComponentError, errorMessage); 347 341 return; … … public class ApplicationMain extends SpringBootServletInitializer { 353 347 RasUtil.checkValidUserCredentials(ConfigManager.RASDAMAN_ADMIN_USER, ConfigManager.RASDAMAN_ADMIN_PASS); 354 348 } catch(Exception ex) { 355 349 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."; 357 351 log.error(errorMessage); 358 352 AbstractController.startException = new PetascopeException(ExceptionCode.InternalComponentError, errorMessage); 359 353 return; … … public class ApplicationMain extends SpringBootServletInitializer { 362 356 CrsUtil.setInternalResolverCRSToQualifiedCRS(); 363 357 CrsUtil.currentWorkingResolverURL = ConfigManager.SECORE_URLS.get(0); 364 358 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 365 368 } 366 369 367 370 @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 */ 2 22 3 23 package org.rasdaman.datamigration; 4 24 import com.rasdaman.admin.layer.service.AdminCreateOrUpdateLayerService; … … public class DataMigration8Handler extends AbstractDataMigrationHandler { 51 71 52 72 } 53 73 54 // -- rasdaman enterprise end55 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 */ 2 22 3 23 package org.rasdaman.datamigration; 4 24 import org.rasdaman.domain.cis.Coverage; … … public class DataMigration9Handler extends AbstractDataMigrationHandler { 40 60 } 41 61 42 62 } 43 44 // -- rasdaman enterprise end45 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 22 22 package petascope.controller; 23 23 24 24 import com.rasdaman.accesscontrol.service.AuthenticationService; 25 26 import java.io.File; 25 27 import java.io.IOException; 26 28 import java.io.OutputStream; 27 29 import java.nio.file.Files; … … import org.apache.commons.io.IOUtils; 43 45 import org.apache.commons.lang3.StringEscapeUtils; 44 46 import org.apache.maven.wagon.util.FileUtils; 45 47 import org.rasdaman.config.ConfigManager; 48 49 import static com.rasdaman.accesscontrol.service.AuthenticationService.*; 46 50 import static org.rasdaman.config.ConfigManager.UPLOADED_FILE_DIR_TMP; 47 51 import static org.rasdaman.config.ConfigManager.UPLOAD_FILE_PREFIX; 48 52 import org.rasdaman.config.VersionManager; … … import petascope.controller.handler.service.AbstractHandler; 56 60 import petascope.controller.handler.service.XMLWCSServiceHandler; 57 61 import petascope.core.KVPSymbols; 58 62 import static petascope.core.KVPSymbols.KEY_ACCEPTVERSIONS; 59 60 61 63 import static petascope.core.KVPSymbols.KEY_REQUEST; 62 64 import static petascope.core.KVPSymbols.VALUE_INSERT_COVERAGE; 63 65 import static petascope.core.KVPSymbols.VALUE_UPDATE_COVERAGE; … … public abstract class AbstractController { 979 981 return sourceIP; 980 982 } 981 983 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 982 1026 /** 983 1027 * If basic authentication header is not enabled, then petascope checks if write request from IP address is valid or not 984 1028 * before processing. 985 1029 */ 986 p ublicvoid validateWriteRequestFromIP(HttpServletRequest httpServletRequest) throws PetascopeException {1030 private void validateWriteRequestFromIP(HttpServletRequest httpServletRequest) throws PetascopeException { 987 1031 if (!ConfigManager.ALLOW_WRITE_REQUESTS_FROM.contains(ConfigManager.PUBLIC_WRITE_REQUESTS_FROM)) { 988 1032 989 1033 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; 26 26 import java.io.BufferedReader; 27 27 import java.io.IOException; 28 28 import 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 30 import java.util.*; 37 31 import java.util.regex.Matcher; 38 32 import java.util.regex.Pattern; 39 33 import javax.servlet.http.HttpServletRequest; … … import org.rasdaman.config.ConfigManager; 41 35 import static org.rasdaman.config.ConfigManager.CHECK_PETASCOPE_ENABLE_AUTHENTICATION_CONTEXT_PATH; 42 36 43 37 import org.rasdaman.rasnet.util.DigestUtils; 44 import org.springframework.beans.factory.annotation.Autowired;45 38 import org.springframework.web.bind.annotation.RequestMapping; 46 39 import org.springframework.web.bind.annotation.RestController; 47 40 import petascope.core.Pair; … … public class AuthenticationController extends AbstractController { 65 58 66 59 public static final String READ_WRITE_RIGHTS = "RW"; 67 60 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 */ 68 67 @RequestMapping(value = CHECK_PETASCOPE_ENABLE_AUTHENTICATION_CONTEXT_PATH) 69 68 private void handleCheckEnableAuthentication() throws Exception { 70 69 if (startException != null) { 71 70 throw startException; 72 71 } 73 72 73 boolean basicAuthenticationHeaderEnabled = false; 74 74 String rasdamanUser = ""; 75 76 if (ConfigManager.enableAuthentication()) { 77 basicAuthenticationHeaderEnabled = true; 78 } 79 75 80 if (!ConfigManager.RASDAMAN_USER.trim().isEmpty() 76 81 && !ConfigManager.RASDAMAN_PASS.trim().isEmpty()) { 77 82 rasdamanUser = ConfigManager.RASDAMAN_USER; 78 83 } 79 84 80 AuthIsActiveResult result = new AuthIsActiveResult( false, rasdamanUser);85 AuthIsActiveResult result = new AuthIsActiveResult(basicAuthenticationHeaderEnabled, rasdamanUser); 81 86 Response response = new Response(Arrays.asList(JSONUtil.serializeObjectToJSONString(result).getBytes()), MIMEUtil.MIME_JSON); 82 87 this.writeResponseResult(response); 83 88 } … … public class AuthenticationController extends AbstractController { 95 100 96 101 String username = resultPair.fst; 97 102 String password = resultPair.snd; 98 103 99 104 String result = ""; 100 105 101 106 RasUtil.checkValidUserCredentials(username, password); … … public class AuthenticationController extends AbstractController { 119 124 * @TODO: this can be done faster and better with protobuf/grpc 120 125 */ 121 126 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 122 133 try { 123 134 // export RASLOGIN=rasadmin:d293a15562d3e70b6fdc5ee452eaed40 && rascontrol -q -e -x list user -rights 124 135 Runtime runtime = Runtime.getRuntime(); 125 136 126 Set<String>roleNames = new LinkedHashSet<>();137 roleNames = new LinkedHashSet<>(); 127 138 128 139 String loginEnv = ConfigManager.RASDAMAN_ADMIN_USER + ":" + DigestUtils.MD5(ConfigManager.RASDAMAN_ADMIN_PASS); 129 140 String[] envp = new String[] {"RASLOGIN=" + loginEnv}; … … public class AuthenticationController extends AbstractController { 160 171 } 161 172 } 162 173 } 174 175 System.out.println("#### Put roles of user: " + username + " to cache."); 176 userRolesCacheMap.put(username, roleNames); 163 177 164 178 return roleNames; 165 179 } 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 22 22 package petascope.controller; 23 23 24 24 25 import com.rasdaman.accesscontrol.service.AuthenticationService;26 25 import java.util.Map; 27 26 import javax.servlet.http.HttpServletRequest; 28 27 import org.rasdaman.config.ConfigManager; … … public class InspireController extends AbstractController { 71 70 @Override 72 71 protected void requestDispatcher(HttpServletRequest httpServletRequest, Map<String, String[]> kvpParameters) throws PetascopeException { 73 72 74 this.validateWriteRequest FromIP(httpServletRequest);73 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 75 74 76 75 String coverageId = this.getValueByKeyAllowNull(kvpParameters, KEY_INSPIRE_COVERAGE_ID); 77 76 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; 34 34 import org.springframework.web.bind.annotation.RequestMethod; 35 35 import org.springframework.web.bind.annotation.RestController; 36 36 import petascope.controller.AbstractController; 37 import petascope.controller.AuthenticationController; 37 38 import petascope.controller.RequestHandlerInterface; 38 39 import petascope.core.KVPSymbols; 39 40 import petascope.core.response.Response; … … public class AdminLayerManagementController extends AbstractController { 105 106 106 107 RequestHandlerInterface requestHandlerInterface = () -> { 107 108 try { 108 this.validateWriteRequest FromIP(httpServletRequest);109 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 109 110 this.activateLayerService.handle(httpServletRequest, kvpParameters); 110 111 } catch (Exception ex) { 111 112 ExceptionUtil.handle(VersionManager.getLatestVersion(KVPSymbols.WMS_SERVICE), ex, this.injectedHttpServletResponse); … … public class AdminLayerManagementController extends AbstractController { 132 133 133 134 RequestHandlerInterface requestHandlerInterface = () -> { 134 135 try { 135 this.validateWriteRequest FromIP(httpServletRequest);136 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 136 137 this.deactivateLayerService.handle(httpServletRequest, kvpParameters); 137 138 } catch (Exception ex) { 138 139 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; 36 36 import org.springframework.beans.factory.annotation.Autowired; 37 37 import org.springframework.web.bind.annotation.RequestMapping; 38 38 import org.springframework.web.bind.annotation.RequestMethod; 39 import petascope.controller.AuthenticationController; 39 40 import petascope.exceptions.PetascopeException; 40 41 import petascope.exceptions.SecoreException; 41 42 import petascope.exceptions.WCSException; … … public class AdminOwsServiceInfoController extends AbstractController { 107 108 108 109 RequestHandlerInterface requestHandlerInterface = () -> { 109 110 try { 110 this.validateWriteRequest FromIP(httpServletRequest);111 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 111 112 this.handle(kvpParameters); 112 113 } catch (Exception ex) { 113 114 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; 37 37 import org.springframework.web.bind.annotation.RequestMethod; 38 38 import org.springframework.web.bind.annotation.RestController; 39 39 import petascope.controller.AbstractController; 40 import petascope.controller.AuthenticationController; 40 41 import petascope.controller.RequestHandlerInterface; 41 42 import petascope.core.KVPSymbols; 42 43 import petascope.core.response.Response; … … public class AdminPyramidController extends AbstractController { 109 110 110 111 RequestHandlerInterface requestHandlerInterface = () -> { 111 112 try { 112 this.validateWriteRequest FromIP(httpServletRequest);113 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 113 114 114 115 this.addPyramidMemberService.handle(httpServletRequest, kvpParameters); 115 116 } catch (Exception ex) { … … public class AdminPyramidController extends AbstractController { 137 138 138 139 RequestHandlerInterface requestHandlerInterface = () -> { 139 140 try { 140 this.validateWriteRequest FromIP(httpServletRequest);141 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 141 142 142 143 this.removePyramidMemberService.handle(httpServletRequest, kvpParameters); 143 144 } catch (Exception ex) { … … public class AdminPyramidController extends AbstractController { 165 166 166 167 RequestHandlerInterface requestHandlerInterface = () -> { 167 168 try { 168 this.validateWriteRequest FromIP(httpServletRequest);169 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 169 170 170 171 this.createPyramidMemberService.handle(httpServletRequest, kvpParameters); 171 172 } 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; 34 34 import org.springframework.web.bind.annotation.RequestMethod; 35 35 import org.springframework.web.bind.annotation.RestController; 36 36 import petascope.controller.AbstractController; 37 import petascope.controller.AuthenticationController; 37 38 import petascope.controller.RequestHandlerInterface; 38 39 import petascope.core.KVPSymbols; 39 40 import petascope.exceptions.PetascopeException; … … public class AdminStyleManagementController extends AbstractController { 74 75 75 76 RequestHandlerInterface requestHandlerInterface = () -> { 76 77 try { 77 this.validateWriteRequest FromIP(httpServletRequest);78 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 78 79 79 80 this.createOrUpdateStyleService.handleAdd(httpServletRequest, kvpParameters); 80 81 } catch (Exception ex) { … … public class AdminStyleManagementController extends AbstractController { 102 103 103 104 RequestHandlerInterface requestHandlerInterface = () -> { 104 105 try { 105 this.validateWriteRequest FromIP(httpServletRequest);106 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 106 107 107 108 this.createOrUpdateStyleService.handleUpdate(httpServletRequest, kvpParameters); 108 109 } catch (Exception ex) { … … public class AdminStyleManagementController extends AbstractController { 130 131 131 132 RequestHandlerInterface requestHandlerInterface = () -> { 132 133 try { 133 this.validateWriteRequest FromIP(httpServletRequest);134 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 134 135 135 136 this.adminDeleteStyleService.handle(httpServletRequest, kvpParameters); 136 137 } 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; 38 38 import org.springframework.web.multipart.MultipartFile; 39 39 import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; 40 40 import petascope.controller.AbstractController; 41 import petascope.controller.AuthenticationController; 41 42 import petascope.controller.RequestHandlerInterface; 42 43 import petascope.core.KVPSymbols; 43 44 import static petascope.core.KVPSymbols.KEY_METADATA; … … public class AdminUpdateCoverageController extends AbstractController { 81 82 82 83 RequestHandlerInterface requestHandlerInterface = () -> { 83 84 try { 84 this.validateWriteRequest FromIP(httpServletRequest);85 this.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 85 86 86 87 this.adminUpdateCoverageService.handle(httpServletRequest, kvpParameters); 87 88 } 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 begin2 3 1 /* 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>. 7 21 */ 8 22 9 23 package petascope.util; … … public class IPAddressUtil { 105 119 } 106 120 107 121 } 108 109 110 // -- rasdaman enterprise end111 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 21 21 */ 22 22 package petascope.wcst.handlers; 23 23 24 import com.rasdaman.accesscontrol.service.AuthenticationService;25 24 import java.util.ArrayList; 26 25 import java.util.List; 27 26 import javax.servlet.http.HttpServletRequest; … … import org.rasdaman.repository.service.WMSRepostioryService; 38 37 import org.slf4j.LoggerFactory; 39 38 import org.springframework.beans.factory.annotation.Autowired; 40 39 import org.springframework.stereotype.Service; 40 import petascope.controller.AuthenticationController; 41 41 import petascope.controller.PetascopeController; 42 42 import petascope.exceptions.PetascopeException; 43 43 import petascope.exceptions.WMSException; … … import petascope.wcst.parsers.DeleteCoverageRequest; 55 55 import petascope.wms.handlers.service.WMSGetMapCachingService; 56 56 import org.rasdaman.repository.service.WMTSRepositoryService; 57 57 import petascope.util.CrsUtil; 58 import petascope.wmts.handlers.service.WMTSGetCapabilitiesService;59 58 60 59 /** 61 60 * Handles the deletion of a coverage. … … public class DeleteCoverageHandler { 86 85 private static final org.slf4j.Logger log = LoggerFactory.getLogger(DeleteCoverageHandler.class); 87 86 88 87 public Response handle(DeleteCoverageRequest request) throws Exception { 89 90 petascopeController.validateWriteRequestFromIP(httpServletRequest);88 89 this.petascopeController.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 91 90 92 91 String username = ConfigManager.RASDAMAN_ADMIN_USER; 93 92 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 21 21 */ 22 22 package petascope.wcst.handlers; 23 23 24 import com.rasdaman.accesscontrol.service.AuthenticationService;25 24 import java.io.File; 26 25 import java.io.IOException; 27 26 import java.util.ArrayList; … … import org.rasdaman.repository.service.CoverageRepositoryService; 42 41 import org.slf4j.LoggerFactory; 43 42 import org.springframework.beans.factory.annotation.Autowired; 44 43 import org.springframework.stereotype.Service; 44 import petascope.controller.AuthenticationController; 45 45 import petascope.controller.PetascopeController; 46 46 import petascope.exceptions.PetascopeException; 47 47 import petascope.exceptions.SecoreException; … … public class InsertCoverageHandler { 103 103 */ 104 104 public Response handle(InsertCoverageRequest request) throws Exception { 105 105 log.debug("Handling coverage insertion..."); 106 this.petascopeController.validateWriteRequest FromIP(httpServletRequest);106 this.petascopeController.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 107 107 108 108 if (request.getGMLCoverage() != null) { 109 109 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 27 27 */ 28 28 package petascope.wcst.handlers; 29 29 30 import com.rasdaman.accesscontrol.service.AuthenticationService;31 30 import com.rasdaman.admin.layer.service.AdminCreateOrUpdateLayerService; 32 31 32 import petascope.controller.AuthenticationController; 33 33 import petascope.core.Pair; 34 34 import petascope.core.XMLSymbols; 35 35 import petascope.core.gml.cis10.GMLCIS10ParserService; … … public class UpdateCoverageHandler { 143 143 public Response handle(UpdateCoverageRequest request) 144 144 throws WCSTCoverageParameterNotFound, WCSTInvalidXML, PetascopeException, SecoreException, Exception { 145 145 log.debug("Handling coverage update..."); 146 147 this.petascopeController.validateWriteRequest FromIP(httpServletRequest);146 147 this.petascopeController.validateWriteRequestByRoleOrAllowedIP(httpServletRequest, AuthenticationController.READ_WRITE_RIGHTS); 148 148 149 149 // persisted coverage 150 150 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 { 72 72 } 73 73 } 74 74 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 ends86 87 75 /** 88 76 * To improves ingestion performance if the data is on the same machine as the rasdaman server, as the network transport is bypassed 89 77 * 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 { 89 89 private WMSGetMapWCPSMetadataTranslatorService wmsGetMapWCPSMetadataTranslatorService; 90 90 @Autowired 91 91 private WcpsCoverageMetadataTranslator wcpsCoverageMetadataTranslator; 92 93 // -- rasdaman enteprise begin 94 92 95 93 public static final String WMS_VIRTUAL_LAYER_EXPECTED_BBOX = "BBOX"; 96 94 public static final String WMS_VIRTUAL_LAYER_EXPECTED_WIDTH = "WIDTH"; 97 95 public static final String WMS_VIRTUAL_LAYER_EXPECTED_HEIGHT = "HEIGHT"; 98 96 public static final String WMS_VIRTUAL_LAYER_EXPECTED_OUTPUT_CRS = "OUTPUT_CRS"; 99 100 // -- rasdaman enterprise end 101 97 102 98 public static final String FRAGMENT_ITERATOR_PREFIX = "$"; 103 99 private static final String COLLECTION_ITERATOR = "c"; 104 100 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= 80 80 rasdaman_url=http://localhost:7001 81 81 rasdaman_database=RASBASE 82 82 83 rasdaman_user= rasguest84 rasdaman_pass= rasguest83 rasdaman_user= 84 rasdaman_pass= 85 85 rasdaman_admin_user=rasadmin 86 86 rasdaman_admin_pass=rasadmin 87 87 … … rasdaman_bin_path=@GENERATED_rasdaman_bin_path@ 92 92 93 93 #---------------------------- Security configuration --------------------------- 94 94 95 authentication_type=basic_header 95 96 allow_write_requests_from=127.0.0.1 96 97 97 98 # 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 276 276 - Need to change: NO, unless changed in rasdaman (not recommended) 277 277 278 278 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``. 285 298 286 299 - Default: ``rasguest`` 287 300 … … Rasdaman 297 310 - Need to change: **YES** when changed in rasdaman 298 311 299 312 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. 306 320 307 Generally, this user should be granted full admin permissions.321 Generally, this user should be granted the ``RW`` rasdaman role. 308 322 309 323 - Default: ``rasadmin`` 310 324 … … Rasdaman 349 363 Security 350 364 ^^^^^^^^ 351 365 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 352 383 353 384 .. _conf-allow-write-requests-from: 354 385