Skip to content

Commit 2c25117

Browse files
authored
Merge pull request #87 from linea-it/85-access-private-hips
85 access private hips
2 parents 26eaec8 + 7fc9c7f commit 2c25117

File tree

9 files changed

+148
-28
lines changed

9 files changed

+148
-28
lines changed

backend/config/settings/production.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
# default=True,
8080
# )
8181

82+
SESSION_COOKIE_DOMAIN = ".linea.org.br"
83+
CSRF_COOKIE_DOMAIN = ".linea.org.br"
84+
8285
# STATIC & MEDIA
8386
# ------------------------
8487
STORAGES = {

backend/config/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
CommonViews.environment_settings,
4949
name="environment_settings",
5050
),
51+
path("api/nginx_serve_protected_hips/", CommonViews.nginx_serve_protected_hips, name="protected_hips"),
52+
5153
path("api/teste/", CommonViews.teste, name="teste"),
5254
# DRF auth token
5355
path("api/auth-token/", obtain_auth_token),

backend/sky_viewer/common/api/views.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
from rest_framework.decorators import permission_classes
66
from rest_framework.permissions import AllowAny
77
from rest_framework.response import Response
8+
from django.contrib.auth.decorators import login_required
9+
from django.http import HttpResponse, HttpResponseForbidden
10+
from django.views.decorators.csrf import csrf_exempt
811

12+
import logging
913

1014
@api_view(["GET"])
1115
def teste(request):
@@ -41,3 +45,40 @@ def environment_settings(request):
4145
"build": "12345",
4246
}
4347
return Response(env_settings, status=status.HTTP_200_OK)
48+
49+
50+
@csrf_exempt
51+
def nginx_serve_protected_hips(request):
52+
logger = logging.getLogger("django")
53+
logger.info("-----------------------------------")
54+
logger.info("nginx_serve_protected_hips_debug()")
55+
56+
data = {
57+
'X-Original-URI': request.META.get('HTTP_X_ORIGINAL_URI'),
58+
'Cookie': request.META.get('HTTP_COOKIE'),
59+
'Path': request.path,
60+
'Method': request.method,
61+
'META': {k: v for k, v in request.META.items() if k.startswith('HTTP_')},
62+
}
63+
64+
logger.debug(data)
65+
66+
original_uri = request.META.get('HTTP_X_ORIGINAL_URI')
67+
if original_uri.endswith('/properties') or original_uri.endswith('/Moc.fits'):
68+
logger.info("Request for properties, temporary always return 200.")
69+
return HttpResponse({}, content_type="application/json", status=200)
70+
71+
if not request.user.is_authenticated:
72+
logger.warning("User is not authenticated, returning 403 Forbidden.")
73+
return HttpResponseForbidden({"message":"User is not authenticated."}, content_type="application/json", status=403)
74+
75+
logger.info(f"User is authenticated: {request.user.username}")
76+
77+
# Identifie release from the original URI
78+
if original_uri.find('/lsst/dp02/') > -1:
79+
# Check if the user has the required group membership for HIPS images
80+
if not request.user.groups.filter(name='dp02').exists():
81+
logger.warning(f"User {request.user.username} does not have access to DP02 HIPS images.")
82+
return HttpResponseForbidden({"message":"User does not have access to DP02 HIPS images."}, content_type="application/json", status=403)
83+
84+
return HttpResponse({}, content_type="application/json", status=200)

backend/sky_viewer/common/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.shortcuts import render
22
import logging
33

4+
45
def saml2_template_failure(request, exception=None, status=403, **kwargs):
56
""" Renders a simple template with an error message. """
67
logger = logging.getLogger("djangosaml2")

compose/production/frontend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ENV NODE_OPTIONS=--max_old_space_size=8192
99
WORKDIR /app
1010
COPY ./frontend/package.json /app
1111
COPY ./frontend/yarn.lock /app
12+
COPY ./frontend/aladin-lite-3.7.0-beta.tgz /app
1213
RUN yarn --non-interactive --ignore-optional --network-timeout 500000
1314

1415
FROM base AS builder

frontend/components/Aladin/index.js

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,49 @@ export default class Aladin extends React.Component {
110110
fov: 0.5,
111111
})
112112

113-
// PRIVATE RELEASES
114-
// ----------------------------------------------------------
115-
if (Array.isArray(this.props.userGroups) && this.props.userGroups.includes('dp02')) {
116-
// LSST DP0.2 IRG HIPS IMAGE
117-
this.aladin.setImageSurvey(this.aladin.createImageSurvey(
118-
"LSST_DP02_IRG_LIneA",
119-
"LSST DP0.2 IRG at LIneA",
120-
"https://datasets.linea.org.br/data/releases/lsst/dp02/images/hips/",
121-
"equatorial",
122-
), { imgFormat: 'hips' })
123-
}
124-
125-
126-
127113
// PUBLIC RELEASES
128114
// ----------------------------------------------------------
129115
// DES DR2 IRG HIPS IMAGE
130116
// https://aladin.cds.unistra.fr/AladinLite/doc/API/#image-layers
131117
// https://aladin.cds.unistra.fr/AladinLite/doc/API/
132-
this.aladin.setImageSurvey(this.aladin.createImageSurvey(
118+
// this.aladin.setImageSurvey(this.aladin.createImageSurvey(
119+
// "DES_DR2_IRG_LIneA",
120+
// "DES DR2 IRG at LIneA",
121+
// "https://datasets.linea.org.br/data/releases/des/dr2/images/hips/",
122+
// "equatorial",
123+
// ), { imgFormat: 'hips', requestCredentials: 'include', requestMode: 'cors' })
124+
125+
const des_dr2 = this.aladin.createImageSurvey(
133126
"DES_DR2_IRG_LIneA",
134127
"DES DR2 IRG at LIneA",
135128
"https://datasets.linea.org.br/data/releases/des/dr2/images/hips/",
136129
"equatorial",
137-
), { imgFormat: 'hips' })
130+
)
131+
this.aladin.setImageSurvey(des_dr2, { imgFormat: 'hips', requestCredentials: 'include', requestMode: 'cors' })
138132

133+
134+
// Adiciona a imagem mas não seleciona como imagem principal
135+
// this.aladin.addNewImageLayer(A.HiPS(
136+
// "https://datasets.linea.org.br/data/releases/des/dr2/images/hips/",
137+
// {
138+
// name: "DES DR2 IRG at LIneA",
139+
// imgFormat: 'jpg',
140+
// requestCredentials: 'include',
141+
// requestMode: 'cors'
142+
// // "DES DR2 IRG at LIneA",
143+
// // "equatorial",
144+
// }
145+
// ))
146+
147+
// this.aladin.setImageSurvey(this.aladin.createImageSurvey(
148+
// "DES_DR2_IRG_LIneA",
149+
// "DES DR2 Teste Credentials",
150+
// "https://skyviewer-dev.linea.org.br/data/releases/des/dr2/images/hips/",
151+
// "equatorial",
152+
// ), { imgFormat: 'hips', requestCredentials: 'include', requestMode: 'cors' })
153+
154+
// PUBLIC CATALOGS
155+
// ----------------------------------------------------------
139156
// DES DR2 Catalog HIPScat/HATS
140157
// https://aladin.cds.unistra.fr/AladinLite/doc/API/examples/catalog-hips-filter/
141158
// https://hipscat.cds.unistra.fr/HiPSCatService/I/345/gaia2/
@@ -147,7 +164,33 @@ export default class Aladin extends React.Component {
147164
color: '#33ff42',
148165
name: 'DES DR2',
149166
});
150-
this.aladin.addCatalog(hips);
167+
// this.aladin.addCatalog(hips);
168+
169+
170+
171+
// PRIVATE RELEASES
172+
// ----------------------------------------------------------
173+
174+
// LSST DP0.2 IRG HIPS IMAGE
175+
if (Array.isArray(this.props.userGroups) && this.props.userGroups.includes('dp02')) {
176+
// "https://datasets.linea.org.br/data/releases/lsst/dp02/images/hips/",
177+
// this.aladin.setImageSurvey(this.aladin.createImageSurvey(
178+
// "LSST_DP02_IRG_LIneA",
179+
// "LSST DP0.2 IRG at LIneA",
180+
// "https://skyviewer-dev.linea.org.br/data/releases/lsst/dp02/images/hips/",
181+
// "equatorial",
182+
// ), { imgFormat: 'hips', requestCredentials: 'include', requestMode: 'cors' })
183+
const lsst_dp02 = this.aladin.createImageSurvey(
184+
"LSST_DP02_IRG_LIneA",
185+
"LSST DP0.2 IRG at LIneA",
186+
"https://skyviewer-dev.linea.org.br/data/releases/lsst/dp02/images/hips/",
187+
"equatorial",
188+
)
189+
this.aladin.setImageSurvey(lsst_dp02, { imgFormat: 'hips', requestCredentials: 'include', requestMode: 'cors' })
190+
console.log("LSST DP0.2 IRG HIPS IMAGE added")
191+
}
192+
193+
151194
// console.log(this.aladin)
152195

153196
// var hips = A.catalogHiPS(
@@ -159,20 +202,11 @@ export default class Aladin extends React.Component {
159202
// });
160203
// this.aladin.addCatalog(hips);
161204

162-
{/* aladin.setImageSurvey(
163-
aladin.createImageSurvey(
164-
"DSS blue band",
165-
"Color DSS blue HiPS",
166-
"http://alasky.cds.unistra.fr/DSS/DSS2-blue-XJ-S/",
167-
"equatorial",
168-
9,
169-
{imgFormat: 'fits'})
170-
); // setting a custom HiPS */}
171-
172205
// // // Cria um catalogo com um unico source
173206
// // this.drawCatalog()
174207
// // // Centraliza a imagem na posição
175208
// // this.goToPosition(this.props.ra, this.props.dec)
209+
176210
})
177211
}
178212

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@mui/icons-material": "^6.0.2",
1818
"@mui/material": "^6.0.2",
1919
"@mui/material-nextjs": "^6.0.2",
20-
"aladin-lite": "^3.5.1-beta",
20+
"aladin-lite": "/app/aladin-lite-3.7.0-beta.tgz",
2121
"axios": "^1.9.0",
2222
"next": "14.2.7",
2323
"nookies": "^2.5.2",

frontend/yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ ajv@^6.12.4:
614614
json-schema-traverse "^0.4.1"
615615
uri-js "^4.2.2"
616616

617+
aladin-lite@/app/aladin-lite-3.7.0-beta.tgz:
618+
version "3.7.0-beta"
619+
resolved "/app/aladin-lite-3.7.0-beta.tgz#36cf9c942621a3b20b48cec20fca2ace4c71377b"
620+
617621
aladin-lite@^3.5.1-beta:
618622
version "3.5.1-beta"
619623
resolved "https://registry.yarnpkg.com/aladin-lite/-/aladin-lite-3.5.1-beta.tgz#4dfc4e56aad8c35966279316c08ec69b986f9a39"

nginx-proxy.conf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ upstream srvfrontend {
66
server frontend:3000;
77
}
88

9+
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=auth_cache:10m inactive=5m use_temp_path=off;
10+
911
server {
1012
listen 80;
1113

@@ -65,6 +67,38 @@ server {
6567
uwsgi_pass backend_srv;
6668
}
6769

70+
# Teste Private Hips Image
71+
location /data/releases/des/dr2/images/hips/ {
72+
auth_request /auth_hips;
73+
alias /var/www/data/releases/des/dr2/images/hips/;
74+
75+
try_files $uri $uri/ /index.html;
76+
autoindex off;
77+
}
78+
79+
location = /auth_hips {
80+
internal;
81+
82+
include uwsgi_params;
83+
uwsgi_param HTTP_X_ORIGINAL_URI $request_uri;
84+
uwsgi_param Cookie $http_cookie;
85+
86+
87+
uwsgi_param SCRIPT_NAME "";
88+
uwsgi_param PATH_INFO /api/nginx_serve_protected_hips_debug/;
89+
90+
uwsgi_pass backend_srv;
91+
92+
# Ativa cache do resultado da autenticação
93+
proxy_cache auth_cache;
94+
proxy_cache_valid 200 10s;
95+
proxy_cache_valid 403 10s;
96+
proxy_cache_valid 401 10s;
97+
98+
# Garante que erros inesperados não sejam cacheados
99+
proxy_cache_valid any 1s;
100+
}
101+
68102
# location /media {
69103
# proxy_pass $scheme://srvapi;
70104
# # uwsgi_pass $scheme://srvapi$request_uri;

0 commit comments

Comments
 (0)