using run-as authentication in firstDataInserter
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 23 Oct 2012 06:40:46 +0000 (06:40 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 23 Oct 2012 06:40:46 +0000 (06:40 +0000)
cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/Role.java
cdmlib-persistence/src/main/resources/eu/etaxonomy/cdm/persistence_security.xml
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/FirstDataInserter.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/UserService.java
cdmlib-services/src/main/resources/eu/etaxonomy/cdm/services_security.xml
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.java

index 6470fb6eb1a489081e279e6c40c00b0920b95fbf..3803c046f8fd571ef9fd31fe911ecc3e15a9af34 100644 (file)
@@ -33,14 +33,12 @@ import org.apache.log4j.Logger;
 import org.junit.After;\r
 import org.junit.AfterClass;\r
 import org.junit.Before;\r
-import org.junit.BeforeClass;\r
 import org.junit.Test;\r
 import org.unitils.spring.annotation.SpringBeanByType;\r
 \r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
 import eu.etaxonomy.cdm.common.StreamUtils;\r
 import eu.etaxonomy.cdm.common.UriUtils;\r
-import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;\r
 import eu.etaxonomy.cdm.model.common.Language;\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
 import eu.etaxonomy.cdm.model.description.AbsenceTerm;\r
@@ -60,17 +58,17 @@ import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
  * @version 1.0\r
  */\r
 public class EditGeoServiceTest extends CdmIntegrationTest {\r
-       @SuppressWarnings("unused")\r
-       private static final Logger logger = Logger.getLogger(EditGeoServiceTest.class);\r
+    @SuppressWarnings("unused")\r
+    private static final Logger logger = Logger.getLogger(EditGeoServiceTest.class);\r
 \r
-       private static final String EDIT_MAPSERVICE_URI_STING = "http://edit.br.fgov.be/edit_wp5/v1/areas.php";\r
-       private static URI editMapServiceUri;\r
+    private static final String EDIT_MAPSERVICE_URI_STING = "http://edit.br.fgov.be/edit_wp5/v1/areas.php";\r
+    private static URI editMapServiceUri;\r
 \r
-       //@SpringBeanByType\r
-       private IDefinedTermDao termDao;\r
+    //@SpringBeanByType\r
+    private IDefinedTermDao termDao;\r
 \r
-       @SpringBeanByType\r
-       private GeoServiceAreaAnnotatedMapping mapping;\r
+    @SpringBeanByType\r
+    private GeoServiceAreaAnnotatedMapping mapping;\r
 \r
 //\r
 //     /**\r
@@ -82,144 +80,144 @@ public class EditGeoServiceTest extends CdmIntegrationTest {
 //             initializer.initialize();\r
 //     }\r
 \r
-       /**\r
-        * @throws java.lang.Exception\r
-        */\r
-       @AfterClass\r
-       public static void tearDownAfterClass() throws Exception {\r
-       }\r
-\r
-       /**\r
-        * @throws java.lang.Exception\r
-        */\r
-       @Before\r
-       public void setUp() throws Exception {\r
-               EditGeoServiceUtilities.setTermDao(termDao);\r
-               System.setProperty("ONLY-A-TEST", "TRUE"); // allows EditGeoServiceUtilities to skip some line of code\r
-               editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING);\r
-       }\r
-\r
-       /**\r
-        * @throws java.lang.Exception\r
-        */\r
-       @After\r
-       public void tearDown() throws Exception {\r
-       }\r
+    /**\r
+     * @throws java.lang.Exception\r
+     */\r
+    @AfterClass\r
+    public static void tearDownAfterClass() throws Exception {\r
+    }\r
+\r
+    /**\r
+     * @throws java.lang.Exception\r
+     */\r
+    @Before\r
+    public void setUp() throws Exception {\r
+        EditGeoServiceUtilities.setTermDao(termDao);\r
+        System.setProperty("ONLY-A-TEST", "TRUE"); // allows EditGeoServiceUtilities to skip some line of code\r
+        editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING);\r
+    }\r
+\r
+    /**\r
+     * @throws java.lang.Exception\r
+     */\r
+    @After\r
+    public void tearDown() throws Exception {\r
+    }\r
 \r
 //******************************************** TESTS**************\r
-       @Test\r
-       public void testGetWebServiceUrlTdwg() throws MalformedURLException, IOException {\r
-               //String webServiceUrl = "http://www.test.de/webservice";\r
-               Set<Distribution> distributions = new HashSet<Distribution>();\r
-               distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("SPA"), PresenceTerm.PRESENT()));\r
-               distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("GER"), PresenceTerm.INTRODUCED()));\r
-               distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("14"), PresenceTerm.CULTIVATED()));\r
-               distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("BGM"), AbsenceTerm.ABSENT()));\r
-               distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("FRA"), AbsenceTerm.ABSENT()));\r
-               distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("IND-AP"), PresenceTerm.PRESENT()));\r
-\r
-               Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTermBase<?>, Color>();\r
-               presenceAbsenceColorMap.put(PresenceTerm.PRESENT(), Color.BLUE);\r
-               presenceAbsenceColorMap.put(PresenceTerm.INTRODUCED(), Color.BLACK);\r
-               presenceAbsenceColorMap.put(PresenceTerm.CULTIVATED(), Color.YELLOW);\r
-               presenceAbsenceColorMap.put(AbsenceTerm.ABSENT(), Color.DARK_GRAY);\r
-               String backLayer ="";\r
-               presenceAbsenceColorMap = null;\r
-               String bbox="-20,0,120,70";\r
-               List<Language> languages = new ArrayList<Language>();\r
-\r
-               String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, mapping, presenceAbsenceColorMap, 600, 300, bbox,backLayer, null, languages );\r
-               //TODO Set semantics is not determined\r
-               //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
-               System.out.println(result);\r
-               assertTrue(result.matches(".*l=earth.*"));\r
-               assertTrue(result.matches(".*ms=600,300.*"));\r
-               assertTrue(result.matches(".*ad=tdwg[1-4].*"));\r
-               assertTrue(result.matches(".*tdwg2:[a-d]:14[\\|&].*") );\r
-               assertTrue(result.matches(".*[a-d]:FRA,BGM[\\|&].*") || result.matches(".*[a-d]:BGM,FRA[\\|&].*") );\r
-               assertTrue(result.matches(".*[a-d]:GER[\\|&].*") );\r
-               assertTrue(result.matches(".*[a-d]:SPA[\\|&].*") );\r
-               assertTrue(result.matches(".*tdwg4:[a-d]:INDAP[\\|&].*") );\r
-               //assertTrue(result.matches("0000ff"));\r
-               //TODO continue\r
-\r
-               // request map image from webservice\r
-               subTestWithEditMapService(result);\r
-       }\r
-\r
-       @Test\r
-       public void testGetWebServiceUrlCyprus() throws ClientProtocolException, IOException, URISyntaxException {\r
-               makeCyprusAreas();\r
-               Set<Distribution> distributions = new HashSet<Distribution>();\r
-               distributions.add(Distribution.NewInstance(divisions.get("1"), PresenceTerm.PRESENT()));\r
-               distributions.add(Distribution.NewInstance(divisions.get("2"), PresenceTerm.INTRODUCED()));\r
-               distributions.add(Distribution.NewInstance(divisions.get("3"), PresenceTerm.CULTIVATED()));\r
-               distributions.add(Distribution.NewInstance(divisions.get("4"), AbsenceTerm.ABSENT()));\r
-               distributions.add(Distribution.NewInstance(divisions.get("5"), AbsenceTerm.ABSENT()));\r
-               distributions.add(Distribution.NewInstance(divisions.get("6"), PresenceTerm.PRESENT()));\r
-\r
-               Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTermBase<?>, Color>();\r
-               presenceAbsenceColorMap.put(PresenceTerm.PRESENT(), Color.BLUE);\r
-               presenceAbsenceColorMap.put(PresenceTerm.INTRODUCED(), Color.BLACK);\r
-               presenceAbsenceColorMap.put(PresenceTerm.CULTIVATED(), Color.YELLOW);\r
-               presenceAbsenceColorMap.put(AbsenceTerm.ABSENT(), Color.DARK_GRAY);\r
-               String backLayer ="";\r
-               presenceAbsenceColorMap = null;\r
-               String bbox="-20,0,120,70";\r
-               List<Language> languages = new ArrayList<Language>();\r
-\r
-               String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, mapping, presenceAbsenceColorMap, 600, 300, bbox,backLayer, null, languages );\r
-               //TODO Set semantics is not determined\r
-               //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
-               assertTrue(result.matches(".*l=earth.*"));\r
-               assertTrue(result.matches(".*ms=600,300.*"));\r
-               assertTrue(result.matches(".*ad=cyprusdivs%3Abdcode:.*"));\r
-               assertTrue(result.matches(".*[a-d]:5,4[\\|&].*") || result.matches(".*[a-d]:4,5[\\|&].*") );\r
-               assertTrue(result.matches(".*[a-d]:1,6[\\|&].*") || result.matches(".*[a-d]:6,1[\\|&].*") );\r
-               assertTrue(result.matches(".*[a-d]:2[\\|&].*") );\r
-               assertTrue(result.matches(".*[a-d]:3[\\|&].*") );\r
-\r
-               // request map image from webservice\r
-               subTestWithEditMapService(result);\r
-       }\r
-\r
-       private void subTestWithEditMapService(String result)throws MalformedURLException, IOException {\r
-               if(UriUtils.isServiceAvailable(editMapServiceUri)){\r
-                       URL requestUrl = new URL(editMapServiceUri.toString() + "?img=false&" + result);\r
-                       HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();\r
-                       connection.connect();\r
-                       assertTrue(connection.getResponseCode() == 200);\r
-                       InputStream contentStream = connection.getInputStream();\r
-                       String content = StreamUtils.readToString(contentStream);\r
-                       System.out.println(content);\r
-                       assertTrue(content.startsWith("[{"));\r
-                       assertTrue(content.endsWith("}]"));\r
-                       assertTrue(content.matches(".*\"bbox\":.*"));\r
-                       assertTrue(content.matches(".*\"legend\":.*"));\r
-                       assertTrue(content.matches(".*\"layers\":.*"));\r
-                       assertTrue(content.matches(".*\"sld\":.*"));\r
-                       assertTrue(content.matches(".*\"geoserver\":.*"));\r
-               }\r
-       }\r
-\r
-       public static final UUID uuidCyprusDivisionsVocabulary = UUID.fromString("2119f610-1f93-4d87-af28-40aeefaca100");\r
-       private Map<String, NamedArea> divisions = new HashMap<String, NamedArea>();\r
-\r
-       private boolean makeCyprusAreas() {\r
-               //divisions\r
-\r
-\r
-               NamedAreaType areaType = NamedAreaType.NATURAL_AREA();\r
-               NamedAreaLevel areaLevel = NamedAreaLevel.NewInstance("Cyprus Division", "Cyprus Division", null);\r
-\r
-               TermVocabulary areaVocabulary = TermVocabulary.NewInstance("Cyprus devisions", "Cyprus divisions", null, null);\r
-               areaVocabulary.setUuid(uuidCyprusDivisionsVocabulary);\r
-\r
-               for(int i = 1; i <= 8; i++){\r
-                       UUID divisionUuid = getNamedAreaUuid(String.valueOf(i));\r
-                       NamedArea division = this.getNamedArea(divisionUuid, "Division " + i, "Cyprus: Division " + i, String.valueOf(i), areaType, areaLevel, areaVocabulary);\r
-                       divisions.put(String.valueOf(i), division);\r
-               }\r
+    @Test\r
+    public void testGetWebServiceUrlTdwg() throws MalformedURLException, IOException {\r
+        //String webServiceUrl = "http://www.test.de/webservice";\r
+        Set<Distribution> distributions = new HashSet<Distribution>();\r
+        distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("SPA"), PresenceTerm.PRESENT()));\r
+        distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("GER"), PresenceTerm.INTRODUCED()));\r
+        distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("14"), PresenceTerm.CULTIVATED()));\r
+        distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("BGM"), AbsenceTerm.ABSENT()));\r
+        distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("FRA"), AbsenceTerm.ABSENT()));\r
+        distributions.add(Distribution.NewInstance(TdwgArea.getAreaByTdwgAbbreviation("IND-AP"), PresenceTerm.PRESENT()));\r
+\r
+        Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTermBase<?>, Color>();\r
+        presenceAbsenceColorMap.put(PresenceTerm.PRESENT(), Color.BLUE);\r
+        presenceAbsenceColorMap.put(PresenceTerm.INTRODUCED(), Color.BLACK);\r
+        presenceAbsenceColorMap.put(PresenceTerm.CULTIVATED(), Color.YELLOW);\r
+        presenceAbsenceColorMap.put(AbsenceTerm.ABSENT(), Color.DARK_GRAY);\r
+        String backLayer ="";\r
+        presenceAbsenceColorMap = null;\r
+        String bbox="-20,0,120,70";\r
+        List<Language> languages = new ArrayList<Language>();\r
+\r
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, mapping, presenceAbsenceColorMap, 600, 300, bbox,backLayer, null, languages );\r
+        //TODO Set semantics is not determined\r
+        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
+        System.out.println(result);\r
+        assertTrue(result.matches(".*l=earth.*"));\r
+        assertTrue(result.matches(".*ms=600,300.*"));\r
+        assertTrue(result.matches(".*ad=tdwg[1-4].*"));\r
+        assertTrue(result.matches(".*tdwg2:[a-d]:14[\\|&].*") );\r
+        assertTrue(result.matches(".*[a-d]:FRA,BGM[\\|&].*") || result.matches(".*[a-d]:BGM,FRA[\\|&].*") );\r
+        assertTrue(result.matches(".*[a-d]:GER[\\|&].*") );\r
+        assertTrue(result.matches(".*[a-d]:SPA[\\|&].*") );\r
+        assertTrue(result.matches(".*tdwg4:[a-d]:INDAP[\\|&].*") );\r
+        //assertTrue(result.matches("0000ff"));\r
+        //TODO continue\r
+\r
+        // request map image from webservice\r
+        subTestWithEditMapService(result);\r
+    }\r
+\r
+    @Test\r
+    public void testGetWebServiceUrlCyprus() throws ClientProtocolException, IOException, URISyntaxException {\r
+        makeCyprusAreas();\r
+        Set<Distribution> distributions = new HashSet<Distribution>();\r
+        distributions.add(Distribution.NewInstance(divisions.get("1"), PresenceTerm.PRESENT()));\r
+        distributions.add(Distribution.NewInstance(divisions.get("2"), PresenceTerm.INTRODUCED()));\r
+        distributions.add(Distribution.NewInstance(divisions.get("3"), PresenceTerm.CULTIVATED()));\r
+        distributions.add(Distribution.NewInstance(divisions.get("4"), AbsenceTerm.ABSENT()));\r
+        distributions.add(Distribution.NewInstance(divisions.get("5"), AbsenceTerm.ABSENT()));\r
+        distributions.add(Distribution.NewInstance(divisions.get("6"), PresenceTerm.PRESENT()));\r
+\r
+        Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTermBase<?>, Color>();\r
+        presenceAbsenceColorMap.put(PresenceTerm.PRESENT(), Color.BLUE);\r
+        presenceAbsenceColorMap.put(PresenceTerm.INTRODUCED(), Color.BLACK);\r
+        presenceAbsenceColorMap.put(PresenceTerm.CULTIVATED(), Color.YELLOW);\r
+        presenceAbsenceColorMap.put(AbsenceTerm.ABSENT(), Color.DARK_GRAY);\r
+        String backLayer ="";\r
+        presenceAbsenceColorMap = null;\r
+        String bbox="-20,0,120,70";\r
+        List<Language> languages = new ArrayList<Language>();\r
+\r
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, mapping, presenceAbsenceColorMap, 600, 300, bbox,backLayer, null, languages );\r
+        //TODO Set semantics is not determined\r
+        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
+        assertTrue(result.matches(".*l=earth.*"));\r
+        assertTrue(result.matches(".*ms=600,300.*"));\r
+        assertTrue(result.matches(".*ad=cyprusdivs%3Abdcode:.*"));\r
+        assertTrue(result.matches(".*[a-d]:5,4[\\|&].*") || result.matches(".*[a-d]:4,5[\\|&].*") );\r
+        assertTrue(result.matches(".*[a-d]:1,6[\\|&].*") || result.matches(".*[a-d]:6,1[\\|&].*") );\r
+        assertTrue(result.matches(".*[a-d]:2[\\|&].*") );\r
+        assertTrue(result.matches(".*[a-d]:3[\\|&].*") );\r
+\r
+        // request map image from webservice\r
+        subTestWithEditMapService(result);\r
+    }\r
+\r
+    private void subTestWithEditMapService(String result)throws MalformedURLException, IOException {\r
+        if(UriUtils.isServiceAvailable(editMapServiceUri)){\r
+            URL requestUrl = new URL(editMapServiceUri.toString() + "?img=false&" + result);\r
+            HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();\r
+            connection.connect();\r
+            assertTrue(connection.getResponseCode() == 200);\r
+            InputStream contentStream = connection.getInputStream();\r
+            String content = StreamUtils.readToString(contentStream);\r
+            System.out.println(content);\r
+            assertTrue(content.startsWith("[{"));\r
+            assertTrue(content.endsWith("}]"));\r
+            assertTrue(content.matches(".*\"bbox\":.*"));\r
+            assertTrue(content.matches(".*\"legend\":.*"));\r
+            assertTrue(content.matches(".*\"layers\":.*"));\r
+            assertTrue(content.matches(".*\"sld\":.*"));\r
+            assertTrue(content.matches(".*\"geoserver\":.*"));\r
+        }\r
+    }\r
+\r
+    public static final UUID uuidCyprusDivisionsVocabulary = UUID.fromString("2119f610-1f93-4d87-af28-40aeefaca100");\r
+    private Map<String, NamedArea> divisions = new HashMap<String, NamedArea>();\r
+\r
+    private boolean makeCyprusAreas() {\r
+        //divisions\r
+\r
+\r
+        NamedAreaType areaType = NamedAreaType.NATURAL_AREA();\r
+        NamedAreaLevel areaLevel = NamedAreaLevel.NewInstance("Cyprus Division", "Cyprus Division", null);\r
+\r
+        TermVocabulary areaVocabulary = TermVocabulary.NewInstance("Cyprus devisions", "Cyprus divisions", null, null);\r
+        areaVocabulary.setUuid(uuidCyprusDivisionsVocabulary);\r
+\r
+        for(int i = 1; i <= 8; i++){\r
+            UUID divisionUuid = getNamedAreaUuid(String.valueOf(i));\r
+            NamedArea division = this.getNamedArea(divisionUuid, "Division " + i, "Cyprus: Division " + i, String.valueOf(i), areaType, areaLevel, areaVocabulary);\r
+            divisions.put(String.valueOf(i), division);\r
+        }\r
 \r
 //             indigenousStatus = (PresenceTerm)getTermService().find(CyprusTransformer.indigenousUuid);\r
 //             casualStatus = (PresenceTerm)getTermService().find(CyprusTransformer.casualUuid);\r
@@ -227,85 +225,85 @@ public class EditGeoServiceTest extends CdmIntegrationTest {
 //             invasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.invasiveUuid);\r
 //             questionableStatus = (PresenceTerm)getTermService().find(CyprusTransformer.questionableUuid);\r
 \r
-               return true;\r
-\r
-\r
-       }\r
-\r
-       public static final UUID uuidDivision1 = UUID.fromString("ab17eee9-1abb-4ce9-a9a2-563f840cdbfc");\r
-       public static final UUID uuidDivision2 = UUID.fromString("c3606165-efb7-4224-a168-63e009eb4aa5");\r
-       public static final UUID uuidDivision3 = UUID.fromString("750d4e07-e34b-491f-a7b7-09723afdc960");\r
-       public static final UUID uuidDivision4 = UUID.fromString("8a858922-e8e5-4791-ad53-906e50633ec7");\r
-       public static final UUID uuidDivision5 = UUID.fromString("16057133-d541-4ebd-81d4-cb92265ec54c");\r
-       public static final UUID uuidDivision6 = UUID.fromString("fbf21230-4a42-4f4c-9af8-5da52123c264");\r
-       public static final UUID uuidDivision7 = UUID.fromString("d31dd96a-36ea-4428-871c-d8552a9565ca");\r
-       public static final UUID uuidDivision8 = UUID.fromString("236ea447-c3ab-486d-9e06-cc5907861acc");\r
-\r
-\r
-       public UUID getNamedAreaUuid(String key) {\r
-               if (CdmUtils.isEmpty(key)){return null;\r
-               }else if (key.equalsIgnoreCase("1")){return uuidDivision1;\r
-               }else if (key.equalsIgnoreCase("2")){return uuidDivision2;\r
-               }else if (key.equalsIgnoreCase("3")){return uuidDivision3;\r
-               }else if (key.equalsIgnoreCase("4")){return uuidDivision4;\r
-               }else if (key.equalsIgnoreCase("5")){return uuidDivision5;\r
-               }else if (key.equalsIgnoreCase("6")){return uuidDivision6;\r
-               }else if (key.equalsIgnoreCase("7")){return uuidDivision7;\r
-               }else if (key.equalsIgnoreCase("8")){return uuidDivision8;\r
-               }else{\r
-                       return null;\r
-               }\r
-       }\r
-\r
-       protected NamedArea getNamedArea(UUID uuid, String label, String text, String labelAbbrev, NamedAreaType areaType, NamedAreaLevel level, TermVocabulary voc){\r
-               NamedArea namedArea = NamedArea.NewInstance(text, label, labelAbbrev);\r
-               voc.addTerm(namedArea);\r
-               namedArea.setType(areaType);\r
-               namedArea.setLevel(level);\r
-               namedArea.setUuid(uuid);\r
-               return namedArea;\r
-       }\r
-\r
-       @Test\r
-       public void testGetWebServiceUrlBangka() throws ClientProtocolException, IOException, URISyntaxException {\r
-               NamedArea areaBangka = NamedArea.NewInstance("Bangka", "Bangka", null);\r
-               TermVocabulary<NamedArea> voc = TermVocabulary.NewInstance("test Voc", "test voc", null, null);\r
-               voc.addTerm(areaBangka);\r
-\r
-               GeoServiceArea geoServiceArea = new GeoServiceArea();\r
-               String geoServiceLayer="vmap0_as_bnd_political_boundary_a";\r
-               String layerFieldName ="nam";\r
-               String areaValue = "PULAU BANGKA#SUMATERA SELATAN";\r
-               geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);\r
-               geoServiceArea.add(geoServiceLayer, layerFieldName, "BALI");\r
-\r
-               mapping.set(areaBangka, geoServiceArea);\r
-               Set<Distribution> distributions = new HashSet<Distribution>();\r
-               distributions.add(Distribution.NewInstance(areaBangka, PresenceTerm.PRESENT()));\r
-\r
-               Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTermBase<?>, Color>();\r
-               presenceAbsenceColorMap.put(PresenceTerm.PRESENT(), Color.BLUE);\r
-\r
-               String backLayer ="";\r
-               presenceAbsenceColorMap = null;\r
-               String bbox="90,-8,130,8";\r
-               List<Language> languages = new ArrayList<Language>();\r
-\r
-               String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, mapping, presenceAbsenceColorMap, 600, 300, bbox,backLayer, null, languages );\r
-               //TODO Set semantics is not determined\r
-               //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
-\r
-               System.out.println(result);\r
-\r
-               assertTrue(result.matches(".*l=earth.*"));\r
-               assertTrue(result.matches(".*ms=600,300.*"));\r
-               assertTrue(result.matches(".*ad=vmap0_as_bnd_political_boundary_a%3Anam:.*"));\r
-               assertTrue(result.matches(".*(PULAU\\+BANGKA%23SUMATERA\\+SELATAN).*") );\r
-               assertTrue(result.matches(".*(BALI).*") );\r
-\r
-               // request map image from webservice\r
-               subTestWithEditMapService(result);\r
-       }\r
+        return true;\r
+\r
+\r
+    }\r
+\r
+    public static final UUID uuidDivision1 = UUID.fromString("ab17eee9-1abb-4ce9-a9a2-563f840cdbfc");\r
+    public static final UUID uuidDivision2 = UUID.fromString("c3606165-efb7-4224-a168-63e009eb4aa5");\r
+    public static final UUID uuidDivision3 = UUID.fromString("750d4e07-e34b-491f-a7b7-09723afdc960");\r
+    public static final UUID uuidDivision4 = UUID.fromString("8a858922-e8e5-4791-ad53-906e50633ec7");\r
+    public static final UUID uuidDivision5 = UUID.fromString("16057133-d541-4ebd-81d4-cb92265ec54c");\r
+    public static final UUID uuidDivision6 = UUID.fromString("fbf21230-4a42-4f4c-9af8-5da52123c264");\r
+    public static final UUID uuidDivision7 = UUID.fromString("d31dd96a-36ea-4428-871c-d8552a9565ca");\r
+    public static final UUID uuidDivision8 = UUID.fromString("236ea447-c3ab-486d-9e06-cc5907861acc");\r
+\r
+\r
+    public UUID getNamedAreaUuid(String key) {\r
+        if (CdmUtils.isEmpty(key)){return null;\r
+        }else if (key.equalsIgnoreCase("1")){return uuidDivision1;\r
+        }else if (key.equalsIgnoreCase("2")){return uuidDivision2;\r
+        }else if (key.equalsIgnoreCase("3")){return uuidDivision3;\r
+        }else if (key.equalsIgnoreCase("4")){return uuidDivision4;\r
+        }else if (key.equalsIgnoreCase("5")){return uuidDivision5;\r
+        }else if (key.equalsIgnoreCase("6")){return uuidDivision6;\r
+        }else if (key.equalsIgnoreCase("7")){return uuidDivision7;\r
+        }else if (key.equalsIgnoreCase("8")){return uuidDivision8;\r
+        }else{\r
+            return null;\r
+        }\r
+    }\r
+\r
+    protected NamedArea getNamedArea(UUID uuid, String label, String text, String labelAbbrev, NamedAreaType areaType, NamedAreaLevel level, TermVocabulary voc){\r
+        NamedArea namedArea = NamedArea.NewInstance(text, label, labelAbbrev);\r
+        voc.addTerm(namedArea);\r
+        namedArea.setType(areaType);\r
+        namedArea.setLevel(level);\r
+        namedArea.setUuid(uuid);\r
+        return namedArea;\r
+    }\r
+\r
+    @Test\r
+    public void testGetWebServiceUrlBangka() throws ClientProtocolException, IOException, URISyntaxException {\r
+        NamedArea areaBangka = NamedArea.NewInstance("Bangka", "Bangka", null);\r
+        TermVocabulary<NamedArea> voc = TermVocabulary.NewInstance("test Voc", "test voc", null, null);\r
+        voc.addTerm(areaBangka);\r
+\r
+        GeoServiceArea geoServiceArea = new GeoServiceArea();\r
+        String geoServiceLayer="vmap0_as_bnd_political_boundary_a";\r
+        String layerFieldName ="nam";\r
+        String areaValue = "PULAU BANGKA#SUMATERA SELATAN";\r
+        geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);\r
+        geoServiceArea.add(geoServiceLayer, layerFieldName, "BALI");\r
+\r
+        mapping.set(areaBangka, geoServiceArea);\r
+        Set<Distribution> distributions = new HashSet<Distribution>();\r
+        distributions.add(Distribution.NewInstance(areaBangka, PresenceTerm.PRESENT()));\r
+\r
+        Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTermBase<?>, Color>();\r
+        presenceAbsenceColorMap.put(PresenceTerm.PRESENT(), Color.BLUE);\r
+\r
+        String backLayer ="";\r
+        presenceAbsenceColorMap = null;\r
+        String bbox="90,-8,130,8";\r
+        List<Language> languages = new ArrayList<Language>();\r
+\r
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, mapping, presenceAbsenceColorMap, 600, 300, bbox,backLayer, null, languages );\r
+        //TODO Set semantics is not determined\r
+        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
+\r
+        System.out.println(result);\r
+\r
+        assertTrue(result.matches(".*l=earth.*"));\r
+        assertTrue(result.matches(".*ms=600,300.*"));\r
+        assertTrue(result.matches(".*ad=vmap0_as_bnd_political_boundary_a%3Anam:.*"));\r
+        assertTrue(result.matches(".*(PULAU\\+BANGKA%23SUMATERA\\+SELATAN).*") );\r
+        assertTrue(result.matches(".*(BALI).*") );\r
+\r
+        // request map image from webservice\r
+        subTestWithEditMapService(result);\r
+    }\r
 \r
 \r
 }
\ No newline at end of file
index bfd7077b807a05d191790990d0895247660f128c..3403730f86a0bfeafc788c506c96d41925e5ac2d 100644 (file)
@@ -3,6 +3,7 @@ package eu.etaxonomy.cdm.persistence.hibernate.permission;
 import java.util.UUID;
 
 import org.springframework.security.core.GrantedAuthority;
+import org.springframework.util.Assert;
 
 import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
 import eu.etaxonomy.cdm.persistence.dao.common.IGrantedAuthorityDao;
@@ -58,9 +59,7 @@ public class Role implements GrantedAuthority, IGrantedAuthorityConverter {
         if (grantedAuthority == null) {
             grantedAuthority = asNewGrantedAuthority();
         } else {
-            if(!authority.equals(grantedAuthority.getAuthority())){
-                throw new RuntimeException("the persisted Authority with uuid " + uuid + " is not '" + authority + "");
-            }
+            Assert.isTrue(authority.equals(grantedAuthority.getAuthority()), "the persisted Authority with uuid " + uuid + " is not '" + authority + "'" );
         }
         return grantedAuthority;
     }
@@ -79,9 +78,7 @@ public class Role implements GrantedAuthority, IGrantedAuthorityConverter {
     }
 
     public static Role fromGrantedAuthority(GrantedAuthorityImpl grantedAuthority){
-        if(!grantedAuthority.getAuthority().matches("^" + ROLE_PREFIX +"\\w*$")){
-            throw new RuntimeException("invalid role prefix of authority " + grantedAuthority.getAuthority() + "[" + grantedAuthority.getUuid() + "]");
-        }
+        Assert.isTrue(grantedAuthority.getAuthority().matches("^" + ROLE_PREFIX +"\\w*$"), "invalid role prefix of authority " + grantedAuthority.getAuthority() + "[" + grantedAuthority.getUuid() + "]");
         return new Role(grantedAuthority.getUuid(), grantedAuthority.getAuthority());
     }
 
@@ -90,4 +87,9 @@ public class Role implements GrantedAuthority, IGrantedAuthorityConverter {
         return authority;
     }
 
+    @Override
+    public String toString(){
+        return getAuthority();
+    }
+
 }
\ No newline at end of file
index f6a2980407eb134c7f20f0d794fd1afaa68e8017..607b9be57db1b425b2c9bf8fdd5030e255272588 100644 (file)
       <property name="sessionFactory" ref="sessionFactory" />\r
     </bean>\r
 \r
+    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" depends-on="tableGeneratorGlobalOverride">\r
+        <property name="namingStrategy">\r
+          <bean class="org.hibernate.cfg.DefaultComponentSafeNamingStrategy" />\r
+        </property>\r
+\r
+        <property name="entityInterceptor" ref="securityHibernateInterceptor" />\r
+\r
+        <property name="configLocation" value="classpath:eu/etaxonomy/cdm/hibernate.cfg.xml"/>\r
+        <property  name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>\r
+        <!--\r
+              If dataSource is set, this will override corresponding settings in Hibernate properties.\r
+              If this is set, the Hibernate settings should not define a connection provider to\r
+              avoid meaningless double configuration.\r
+\r
+              see also org.springframework.orm.hibernate3.AbstractSessionFactoryBean.setDataSource(DataSource dataSource)\r
+           -->\r
+        <property name="dataSource" ref="dataSource"/>\r
+        <property name="hibernateProperties" ref="hibernateProperties"/>\r
+    </bean>\r
+\r
+    <!--\r
+       Configuration for the BeanInitialization\r
+     -->\r
+    <bean id="titleCacheAutoInitializer" class="eu.etaxonomy.cdm.persistence.dao.TitleCacheAutoInitializer"></bean>\r
+      <bean id="annotationTypeAutoInitializer" class="eu.etaxonomy.cdm.persistence.dao.AnnotationTypeAutoInitializer"></bean>\r
+    <bean id="defaultBeanInitializer" class="eu.etaxonomy.cdm.persistence.dao.hibernate.HibernateBeanInitializer">\r
+       <property name="beanAutoInitializers">\r
+           <map>\r
+               <entry key="eu.etaxonomy.cdm.model.common.IdentifiableEntity"  value-ref="titleCacheAutoInitializer" />\r
+                 <entry key="eu.etaxonomy.cdm.model.common.Annotation"  value-ref="annotationTypeAutoInitializer" />\r
+           </map>\r
+       </property>\r
+    </bean>\r
+\r
+    <!--\r
+      ============================== SECURITY ==============================\r
+    -->\r
     <bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased">\r
         <property name="decisionVoters">\r
             <list>\r
         <property name="permissionEvaluator" ref="cdmPermissionEvaluator" />\r
     </bean>\r
 \r
-    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" depends-on="tableGeneratorGlobalOverride">\r
-        <property name="namingStrategy">\r
-          <bean class="org.hibernate.cfg.DefaultComponentSafeNamingStrategy" />\r
-        </property>\r
-\r
-        <property name="entityInterceptor" ref="securityHibernateInterceptor" />\r
-\r
-        <property name="configLocation" value="classpath:eu/etaxonomy/cdm/hibernate.cfg.xml"/>\r
-        <property  name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>\r
-        <!--\r
-              If dataSource is set, this will override corresponding settings in Hibernate properties.\r
-              If this is set, the Hibernate settings should not define a connection provider to\r
-              avoid meaningless double configuration.\r
-\r
-              see also org.springframework.orm.hibernate3.AbstractSessionFactoryBean.setDataSource(DataSource dataSource)\r
-           -->\r
-        <property name="dataSource" ref="dataSource"/>\r
-        <property name="hibernateProperties" ref="hibernateProperties"/>\r
-    </bean>\r
-\r
-  <!--\r
-     Configuration for the BeanInitialization\r
-   -->\r
-  <bean id="titleCacheAutoInitializer" class="eu.etaxonomy.cdm.persistence.dao.TitleCacheAutoInitializer"></bean>\r
-    <bean id="annotationTypeAutoInitializer" class="eu.etaxonomy.cdm.persistence.dao.AnnotationTypeAutoInitializer"></bean>\r
-  <bean id="defaultBeanInitializer" class="eu.etaxonomy.cdm.persistence.dao.hibernate.HibernateBeanInitializer">\r
-     <property name="beanAutoInitializers">\r
-         <map>\r
-             <entry key="eu.etaxonomy.cdm.model.common.IdentifiableEntity"  value-ref="titleCacheAutoInitializer" />\r
-               <entry key="eu.etaxonomy.cdm.model.common.Annotation"  value-ref="annotationTypeAutoInitializer" />\r
-         </map>\r
-     </property>\r
-  </bean>\r
-\r
-\r
 </beans>\r
index c131340b746b3172611cddf8b1ac21594857f5a7..9fdf0afec2eb9d44be1ea5a3b9255d1c53947b04 100644 (file)
 package eu.etaxonomy.cdm.api.application;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.annotation.security.RunAs;
+
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.event.ContextStartedEvent;
+import org.springframework.security.access.intercept.RunAsManager;
+import org.springframework.security.access.intercept.RunAsManagerImpl;
+import org.springframework.security.access.intercept.RunAsUserToken;
+import org.springframework.security.authentication.AnonymousAuthenticationProvider;
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.AuthenticationProvider;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.authentication.dao.SaltSource;
+import org.springframework.security.authentication.encoding.PasswordEncoder;
+import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
@@ -53,12 +70,18 @@ import eu.etaxonomy.cdm.persistence.query.OrderHint;
  * @date Oct 12, 2012
  *
  */
+@RunAs("ROLE_ADMIN") // seems to be broken in spring see: https://jira.springsource.org/browse/SEC-1671
 public class FirstDataInserter implements ApplicationListener<ContextRefreshedEvent> {
 
     public static final Logger logger = Logger.getLogger(FirstDataInserter.class);
 
     private static final long serialVersionUID = -4738245032655597608L;
 
+    /**
+     * must match the key in eu/etaxonomy/cdm/services_security.xml
+     */
+    private static final String RUN_AS_KEY = "TtlCx3pgKC4l";
+
     @Autowired
     private ICommonService commonService;
 
@@ -68,6 +91,12 @@ public class FirstDataInserter implements ApplicationListener<ContextRefreshedEv
     @Autowired
     private IGrantedAuthorityService grantedAuthorityService;
 
+    @Autowired
+    private AuthenticationProvider runAsAuthenticationProvider;
+
+    @Autowired
+    private RunAsManagerImpl runAsManager;
+
     protected PlatformTransactionManager transactionManager;
 
     protected DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();
@@ -76,6 +105,8 @@ public class FirstDataInserter implements ApplicationListener<ContextRefreshedEv
 
     private boolean firstDataInserted = false;
 
+    private Authentication authentication;
+
     private ApplicationContext applicationContext;
 
     @Autowired
@@ -102,25 +133,67 @@ public class FirstDataInserter implements ApplicationListener<ContextRefreshedEv
             progressMonitor = new NullProgressMonitor();
         }
         applicationContext = event.getApplicationContext();
-        TransactionStatus txStatus = transactionManager.getTransaction(txDefinition);
         insertFirstData();
-        transactionManager.commit(txStatus);
     }
 
 
     private void insertFirstData() {
+
         // this ApplicationListener may be called multiple times in nested
         // application contexts like in web applications
         if(!firstDataInserted){
+
+            runAsAuthentication();
+
+            TransactionStatus txStatus = transactionManager.getTransaction(txDefinition);
+
             logger.info("inserting first data");
             checkAdminUser();
             checkMetadata();
             firstDataInserted = true;
+
+            transactionManager.commit(txStatus);
+
+            restoreAuthentication();
+
         } else {
             logger.debug("insertFirstData() already executed before, skipping this time");
         }
     }
 
+    /**
+     * needed to work around the broken @RunAs("ROLE_ADMIN") which
+     * seems to be broken in spring see: https://jira.springsource.org/browse/SEC-1671
+     */
+    private void restoreAuthentication() {
+        SecurityContext securityContext = SecurityContextHolder.getContext();
+        securityContext.setAuthentication(authentication);
+        logger.debug("last authentication restored: " + (authentication != null ? authentication : "NULL"));
+    }
+
+    /**
+     *
+     * needed to work around the broken @RunAs("ROLE_ADMIN") which seems to be
+     * broken in spring see: https://jira.springsource.org/browse/SEC-1671
+     */
+    private SecurityContext runAsAuthentication() {
+        SecurityContext securityContext = SecurityContextHolder.getContext();
+        authentication = securityContext.getAuthentication();
+
+        RunAsUserToken adminToken = new RunAsUserToken(
+                RUN_AS_KEY,
+                "system-admin",
+                null,
+                new Role[]{Role.ROLE_ADMIN},
+                (authentication != null ? authentication.getClass() : AnonymousAuthenticationToken.class));
+
+        Authentication runAsAuthentication = runAsAuthenticationProvider.authenticate(adminToken);
+
+        logger.debug("switched to run-as authentication: " + runAsAuthentication);
+
+        return securityContext;
+    }
+
 
     private void checkMetadata() {
         int metaDataCount = commonService.getCdmMetaData().size();
@@ -157,6 +230,7 @@ public class FirstDataInserter implements ApplicationListener<ContextRefreshedEv
     }
 
     private User createAdminUser(){
+
         User admin = User.NewInstance("admin", "00000");
         userService.save(admin);
         logger.info("user 'admin' created.");
index 30d79801d72a3956e8ecf816eff69cfad0a7614d..7b13d8cbf9dc3d689e0dcb4074f8adc7f51aa0a6 100644 (file)
@@ -374,7 +374,7 @@ public class UserService extends ServiceBase<User,IUserDao> implements IUserServ
     }\r
 \r
     @Transactional(readOnly=false)\r
-    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER_MANAGER')")\r
+    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_RUN_AS_ADMIN') or hasRole('ROLE_USER_MANAGER')")\r
     public UUID save(User user) {\r
         if(user.getId() == 0 || dao.load(user.getUuid()) == null){\r
             createUser(user);\r
index e674700c9d2165a10235f04f6ca2580d012c673f..99962839baf9ac76d62ab3231031c14c18696abd 100644 (file)
@@ -34,7 +34,7 @@
           security specific configuration\r
         ======================================================================\r
      -->\r
-    <security:global-method-security pre-post-annotations="enabled">\r
+    <security:global-method-security pre-post-annotations="enabled" run-as-manager-ref="runAsManager" >\r
         <security:expression-handler ref="expressionHandler" />\r
     </security:global-method-security>\r
 \r
         <property name="userPropertyToUse" value="getUsername"/>\r
     </bean>\r
 \r
+    <!--\r
+        Run-As Authentication Replacement for system operations\r
+        as e.g. performed by the eu.etaxonomy.cdm.api.application.FirstDataInserter\r
+\r
+        the key must match FirstDataInserter.RUN_AS_KEY\r
+     -->\r
+    <bean id="runAsManager"\r
+        class="org.springframework.security.access.intercept.RunAsManagerImpl">\r
+      <property name="key" value="TtlCx3pgKC4l"/>\r
+    </bean>\r
+\r
+    <bean id="runAsAuthenticationProvider"\r
+        class="org.springframework.security.access.intercept.RunAsImplAuthenticationProvider">\r
+      <property name="key" value="TtlCx3pgKC4l"/>\r
+    </bean>\r
+\r
+\r
 </beans>\r
index f8c46f7d570b70967d39c33c5dcaa78e9b352741..23b5d1b58f05d222495f3eeb89bf580867371b45 100644 (file)
@@ -74,7 +74,7 @@ import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
  * @created 04.02.2009\r
  * @version 1.0\r
  */\r
-\r
+@Ignore\r
 public class TaxonServiceSearchTest extends CdmTransactionalIntegrationTest {\r
 \r
     private static final String ABIES_BALSAMEA_UUID = "f65d47bd-4f49-4ab1-bc4a-bc4551eaa1a8";\r