15
15
16
16
package au.org.ala.spatial
17
17
18
+ import au.ala.org.ws.security.RequireApiKey
19
+ import au.org.ala.web.AuthService
18
20
import grails.converters.JSON
19
21
import grails.converters.XML
20
22
import org.apache.commons.io.FileUtils
21
- import org.apache.commons.io.IOUtils
22
23
import org.hibernate.criterion.CriteriaSpecification
23
24
import org.json.simple.JSONObject
24
- import org.json.simple.parser.JSONParser
25
25
26
+ import javax.servlet.http.HttpServletResponse
26
27
import javax.transaction.Transactional
27
28
import java.text.SimpleDateFormat
28
29
@@ -37,6 +38,7 @@ class ManageLayersController {
37
38
38
39
FieldService fieldService
39
40
LayerService layerService
41
+ AuthService authService
40
42
41
43
/**
42
44
* admin only or api_key
@@ -614,8 +616,9 @@ class ManageLayersController {
614
616
def copy () {
615
617
String spatialServiceUrl = params. spatialServiceUrl
616
618
String fieldId = params. fieldId
619
+ String jwt = params. jwt
617
620
618
- manageLayersService. updateFromRemote(spatialServiceUrl, fieldId)
621
+ manageLayersService. updateFromRemote(spatialServiceUrl, fieldId, jwt )
619
622
redirect(controller : " Tasks" , action : " index" )
620
623
621
624
}
@@ -628,11 +631,11 @@ class ManageLayersController {
628
631
@RequireAdmin
629
632
def enable () {
630
633
if (params. id. isNumber()) {
631
- def layer = layerDao . getLayerById(params. id. toInteger(), false )
634
+ def layer = layerService . getLayerById(params. id. toInteger(), false )
632
635
layer. enabled = true
633
636
layerService. updateLayer(layer)
634
637
} else {
635
- def field = fieldDao . getFieldById(params. id, false )
638
+ def field = fieldService . getFieldById(params. id, false )
636
639
field. enabled = true
637
640
fieldService. updateField(field)
638
641
}
@@ -645,11 +648,22 @@ class ManageLayersController {
645
648
* a layer: 'cl..._res', 'el..._res', will provide the standardized files at the requested resolution
646
649
* (or next detailed) - shape files or diva grids
647
650
*
648
- * admin only or api_key, do not redirect to CAS
651
+ * Requires JWT with the configured layerCopyRole
652
+ *
649
653
* @return
650
654
*/
651
- @RequireAdmin
655
+ @RequireApiKey
652
656
def resource () {
657
+ // do permission check
658
+ if (! authService. userInRole(spatialConfig. layerCopyRole)) {
659
+ response. sendError(HttpServletResponse . SC_FORBIDDEN , " Forbidden, required role: " + spatialConfig. layerCopyRole)
660
+ return
661
+ }
662
+
663
+ if (! isLayerCopyFile(params. resource)) {
664
+ response. sendError(HttpServletResponse . SC_FORBIDDEN , " Forbidden, only allowed access to layer files" )
665
+ }
666
+
653
667
OutputStream outputStream = null
654
668
try {
655
669
outputStream = response. outputStream as OutputStream
@@ -674,13 +688,27 @@ class ManageLayersController {
674
688
/**
675
689
* for slaves to peek at a resource on the master
676
690
*
677
- * admin only or api_key, do not redirect to CAS
691
+ * Requires JWT with the configured layerCopyRole
678
692
*
679
693
* @return
680
694
*/
681
- @RequireAdmin
695
+ @RequireApiKey
682
696
def resourcePeek () {
697
+ // do permission check
698
+ if (! authService. userInRole(spatialConfig. layerCopyRole)) {
699
+ response. sendError(HttpServletResponse . SC_FORBIDDEN , " Forbidden, required role: " + spatialConfig. layerCopyRole)
700
+ return
701
+ }
702
+
703
+ if (! isLayerCopyFile(params. resource)) {
704
+ response. sendError(HttpServletResponse . SC_FORBIDDEN , " Forbidden, only allowed access to layer files" )
705
+ }
706
+
683
707
// write resource
684
708
render fileService. info(params. resource. toString()) as JSON
685
709
}
710
+
711
+ private boolean isLayerCopyFile (String resource ) {
712
+ return resource. startsWith(" /layer/" ) || resource. startsWith(" /standard_layer/" ) || resource. startsWith(" /public/layerDistances.properties" )
713
+ }
686
714
}
0 commit comments