< prev index next >

test/javax/xml/jaxp/unittest/common/Bug7143711Test.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package common;
  25 
  26 import java.security.AllPermission;
  27 import java.security.Permission;
  28 import java.security.Permissions;
  29 
  30 import javax.xml.XMLConstants;
  31 import javax.xml.transform.TransformerFactory;
  32 import javax.xml.validation.SchemaFactory;
  33 import javax.xml.xpath.XPathFactory;
  34 


  35 import org.testng.Assert;

  36 import org.testng.annotations.Test;
  37 
  38 /*
  39  * @bug 7143711
  40  * @summary Test set use-service-mechanism shall not override what's set by the constructor in secure mode.
  41  */

  42 public class Bug7143711Test {
  43     static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
  44     static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
  45 
  46     private static final String DOM_FACTORY_ID = "javax.xml.parsers.DocumentBuilderFactory";
  47     private static final String SAX_FACTORY_ID = "javax.xml.parsers.SAXParserFactory";
  48 
  49     // impl specific feature
  50     final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
  51 
  52     @Test
  53     public void testValidation_SAX_withSM() {
  54         System.out.println("Validation using SAX Source with security manager:");
  55         System.setProperty(SAX_FACTORY_ID, "MySAXFactoryImpl");
  56         Permissions granted = new java.security.Permissions();
  57         granted.add(new AllPermission());
  58         System.setSecurityManager(new MySM(granted));
  59 
  60         try {
  61             SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);


   1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package common;
  25 
  26 import java.security.AllPermission;
  27 import java.security.Permission;
  28 import java.security.Permissions;
  29 
  30 import javax.xml.XMLConstants;
  31 import javax.xml.transform.TransformerFactory;
  32 import javax.xml.validation.SchemaFactory;
  33 import javax.xml.xpath.XPathFactory;
  34 
  35 import jaxp.library.JAXPTestUtilities;
  36 
  37 import org.testng.Assert;
  38 import org.testng.annotations.Listeners;
  39 import org.testng.annotations.Test;
  40 
  41 /*
  42  * @bug 7143711
  43  * @summary Test set use-service-mechanism shall not override what's set by the constructor in secure mode.
  44  */
  45 @Listeners({jaxp.library.BasePolicy.class})
  46 public class Bug7143711Test {
  47     static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
  48     static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
  49 
  50     private static final String DOM_FACTORY_ID = "javax.xml.parsers.DocumentBuilderFactory";
  51     private static final String SAX_FACTORY_ID = "javax.xml.parsers.SAXParserFactory";
  52 
  53     // impl specific feature
  54     final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
  55 
  56     @Test
  57     public void testValidation_SAX_withSM() {
  58         System.out.println("Validation using SAX Source with security manager:");
  59         System.setProperty(SAX_FACTORY_ID, "MySAXFactoryImpl");
  60         Permissions granted = new java.security.Permissions();
  61         granted.add(new AllPermission());
  62         System.setSecurityManager(new MySM(granted));
  63 
  64         try {
  65             SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);


< prev index next >