Skip to content

Commit

Permalink
[Fixes #389] Allow "Enable CORS" within GeoServer container through e…
Browse files Browse the repository at this point in the history
…nv (#390) (#392)

* [Fixes #389] Allow "Enable CORS" within GeoServer container through env

* - Renaming the GEOSERVER CORS variables and place them on the sample envs

* - Renaming the GEOSERVER CORS variables and place them on the sample envs

(cherry picked from commit bfb9b4b)
  • Loading branch information
afabiani authored Jan 9, 2023
1 parent d5332c9 commit c10b641
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
9 changes: 7 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ DEFAULT_FROM_EMAIL='{email}' # eg Company <[email protected]>

# Session/Access Control
LOCKDOWN_GEONODE=False
CORS_ALLOW_ALL_ORIGINS=True
X_FRAME_OPTIONS="SAMEORIGIN"
SESSION_EXPIRED_CONTROL_ENABLED=True
DEFAULT_ANONYMOUS_VIEW_PERMISSION=True
DEFAULT_ANONYMOUS_DOWNLOAD_PERMISSION=True

CORS_ALLOW_ALL_ORIGINS=True
GEOSERVER_CORS_ENABLED=True
GEOSERVER_CORS_ALLOWED_ORIGINS=*
GEOSERVER_CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,HEAD,OPTIONS
GEOSERVER_CORS_ALLOWED_HEADERS=*

# Users Registration
ACCOUNT_OPEN_SIGNUP=True
ACCOUNT_EMAIL_REQUIRED=True
Expand Down Expand Up @@ -229,7 +234,7 @@ LDAP_GROUP_PROFILE_MEMBER_ATTR=uniqueMember
# ##
# Note right autoscale value must coincide with worker concurrency value
# CELERY__AUTOSCALE_VALUES="15,10"
# CELERY__WORKER_CONCURRENCY="4"
# CELERY__WORKER_CONCURRENCY="10"
# ##
# CELERY__OPTS="--without-gossip --without-mingle -Ofair -B -E"
# CELERY__BEAT_SCHEDULE="/mnt/volumes/statics/celerybeat-schedule"
Expand Down
7 changes: 6 additions & 1 deletion .override_dev_env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ export DJANGO_EMAIL_USE_SSL=False
export DEFAULT_FROM_EMAIL="GeoNode <[email protected]>"

export LOCKDOWN_GEONODE=False
export CORS_ALLOW_ALL_ORIGINS=True
export X_FRAME_OPTIONS=SAMEORIGIN
export SESSION_EXPIRED_CONTROL_ENABLED=True
export DEFAULT_ANONYMOUS_VIEW_PERMISSION=True
export DEFAULT_ANONYMOUS_DOWNLOAD_PERMISSION=True

export CORS_ALLOW_ALL_ORIGINS=True
export GEOSERVER_CORS_ENABLED=True
export GEOSERVER_CORS_ALLOWED_ORIGINS=*
export GEOSERVER_CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,HEAD,OPTIONS
export GEOSERVER_CORS_ALLOWED_HEADERS=*

export ACCOUNT_OPEN_SIGNUP=True
export ACCOUNT_EMAIL_REQUIRED=True
export ACCOUNT_APPROVAL_REQUIRED=False
Expand Down
9 changes: 8 additions & 1 deletion docker/geoserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ ARG JAVA_HOME=/usr/local/openjdk-11
FROM tomcat:$IMAGE_VERSION
LABEL GeoNode Development Team

ARG GEOSERVER_CORS_ENABLED=False
ARG GEOSERVER_CORS_ALLOWED_ORIGINS=*
ARG GEOSERVER_CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,HEAD,OPTIONS
ARG GEOSERVER_CORS_ALLOWED_HEADERS=*
#
# Set GeoServer version and data directory
#
ENV GEOSERVER_VERSION=2.20.5
ENV GEOSERVER_DATA_DIR="/geoserver_data/data"

ENV GEOSERVER_CORS_ENABLED=$GEOSERVER_CORS_ENABLED
ENV GEOSERVER_CORS_ALLOWED_ORIGINS=$GEOSERVER_CORS_ALLOWED_ORIGINS
ENV GEOSERVER_CORS_ALLOWED_METHODS=$GEOSERVER_CORS_ALLOWED_METHODS
ENV GEOSERVER_CORS_ALLOWED_HEADERS=$GEOSERVER_CORS_ALLOWED_HEADERS
#
# Download and install GeoServer
#
Expand Down
32 changes: 31 additions & 1 deletion docker/geoserver/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,38 @@ for template in in ${geoserver_datadir_template_dirs[*]}; do
done

fi

done

# configure CORS (inspired by https://github.com/oscarfonts/docker-geoserver)
# if enabled, this will add the filter definitions
# to the end of the web.xml
# (this will only happen if our filter has not yet been added before)
if [ "${GEOSERVER_CORS_ENABLED}" = "true" ] || [ "${GEOSERVER_CORS_ENABLED}" = "True" ]; then
if ! grep -q DockerGeoServerCorsFilter "$CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml"; then
echo "Enable CORS for $CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml"
sed -i "\:</web-app>:i\\
<filter>\n\
<filter-name>DockerGeoServerCorsFilter</filter-name>\n\
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>\n\
<init-param>\n\
<param-name>cors.allowed.origins</param-name>\n\
<param-value>${GEOSERVER_CORS_ALLOWED_ORIGINS}</param-value>\n\
</init-param>\n\
<init-param>\n\
<param-name>cors.allowed.methods</param-name>\n\
<param-value>${GEOSERVER_CORS_ALLOWED_METHODS}</param-value>\n\
</init-param>\n\
<init-param>\n\
<param-name>cors.allowed.headers</param-name>\n\
<param-value>${GEOSERVER_CORS_ALLOWED_HEADERS}</param-value>\n\
</init-param>\n\
</filter>\n\
<filter-mapping>\n\
<filter-name>DockerGeoServerCorsFilter</filter-name>\n\
<url-pattern>/*</url-pattern>\n\
</filter-mapping>" "$CATALINA_HOME/webapps/geoserver/WEB-INF/web.xml";
fi
fi

# start tomcat
exec env JAVA_OPTS="${JAVA_OPTS}" catalina.sh run

0 comments on commit c10b641

Please sign in to comment.