Spring Framework
  1. Spring Framework
  2. SPR-9970

UnsupportedOperationException when accessing Environment with active SecurityManager

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1 GA
    • Fix Version/s: 3.2.1
    • Component/s: Core, Core:Environment
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      When deploying the webapp to tomcat, I got "java.lang.UnsupportedOperationException" (see the stack trace below). I managed to trace back to the commit 20f87ab98da8a813c0251979286286e5e3776435 and found out the cause of the property name are "spring.profiles.default" and "spring.profile.active". I don't have those properties defined anywhere.

      The workaround is to define those two properties in the web.xml files. The value can be anything.

      Stack trace:
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.ReadOnlySystemAttributesMap.keySet(ReadOnlySystemAttributesMap.java:88)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.MapPropertySource.getPropertyNames(MapPropertySource.java:41)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.EnumerablePropertySource.containsProperty(EnumerablePropertySource.java:70)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.SystemEnvironmentPropertySource.resolvePropertyName(SystemEnvironmentPropertySource.java:109)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.SystemEnvironmentPropertySource.getProperty(SystemEnvironmentPropertySource.java:90)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:73)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:59)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:419)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.AbstractEnvironment.doGetDefaultProfiles(AbstractEnvironment.java:277)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.AbstractEnvironment.getDefaultProfiles(AbstractEnvironment.java:260)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.core.env.AbstractEnvironment.merge(AbstractEnvironment.java:402)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.context.support.AbstractApplicationContext.setParent(AbstractApplicationContext.java:392)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:585)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at javax.servlet.GenericServlet.init(GenericServlet.java:212)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at java.lang.reflect.Method.invoke(Method.java:597)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:270)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at java.security.AccessController.doPrivileged(Native Method)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:302)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:163)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:117)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1200)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:124)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:146)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at java.security.AccessController.doPrivileged(Native Method)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:777)
      INFO | jvm 1 | 2012/11/07 12:38:09 | at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

        Issue Links

          Activity

          Hide
          Chris Beams added a comment -

          Please provide as much information as possible about your runtime environment, thanks.

          Show
          Chris Beams added a comment - Please provide as much information as possible about your runtime environment, thanks.
          Hide
          Pan Luo added a comment -

          I'm developing a plugin for a learning management system, which uses apache/tomcat 6.0.35 as the container. It is running under jdk 1.6.0_30 and RHEL 5. The plugin will be deployed as an independent webapp on the server.

          Let me know if you need anything else.

          Show
          Pan Luo added a comment - I'm developing a plugin for a learning management system, which uses apache/tomcat 6.0.35 as the container. It is running under jdk 1.6.0_30 and RHEL 5. The plugin will be deployed as an independent webapp on the server. Let me know if you need anything else.
          Hide
          Chris Beams added a comment -

          That sounds pretty straightforward to reproduce. Would you be willing to create a repro project per the instructions at https://github.com/SpringSource/spring-framework-issues#readme? This really helps us expedite things.

          Thanks!

          Show
          Chris Beams added a comment - That sounds pretty straightforward to reproduce. Would you be willing to create a repro project per the instructions at https://github.com/SpringSource/spring-framework-issues#readme? This really helps us expedite things. Thanks!
          Hide
          Daniel Bower added a comment - - edited

          I had this same issue, and was able to resolve it with Pan's suggestion. I'm guessing that he is using the same learning management system that I am, though I am running under jdk 1.7 on windows. Additionally, I am using Spring 3.1.3. This particular learning management system is closed source and a bit of a bear to get going, so I don't think you'll be seeing an example project provided by Pan or anyone else.

          As a side note, I received this error again when trying to upgrade my project to Spring 3.2.0. I already had Pan's suggestion in place, so enabled the debugger and found a new parameter trying to be set in this way: "spring.liveBeansView.mbeanDomain"

          I tried adding another block to my web.xml to skip it in the same way as Pan, but unfortunately this particular code puts me between a rock and a hard place (I either can't start the webapp, or it tries to start an mbean server that I don't want):

          Commit e5f3669804248a22f860a9580058d41d80a86932
          String mbeanDomain = applicationContext.getEnvironment().getProperty(MBEAN_DOMAIN_PROPERTY_NAME);
                          if (mbeanDomain != null) {
                                  synchronized (applicationContexts) {
                                          if (applicationContexts.isEmpty()) {
                                                  try {
                                                          MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                                                          server.registerMBean(new LiveBeansView(),
                                                                          new ObjectName(mbeanDomain, MBEAN_APPLICATION_KEY, applicationContext.getApplicationName()));
                                                  }
                                                  catch (Exception ex) {
                                                          throw new ApplicationContextException("Failed to register LiveBeansView MBean", ex);
                                                  }
                                          }
                                          applicationContexts.add(applicationContext);
          
                                  }
                          }

          I'll have to revert back to 3.1.3.

          Show
          Daniel Bower added a comment - - edited I had this same issue, and was able to resolve it with Pan's suggestion. I'm guessing that he is using the same learning management system that I am, though I am running under jdk 1.7 on windows. Additionally, I am using Spring 3.1.3. This particular learning management system is closed source and a bit of a bear to get going, so I don't think you'll be seeing an example project provided by Pan or anyone else. As a side note, I received this error again when trying to upgrade my project to Spring 3.2.0. I already had Pan's suggestion in place, so enabled the debugger and found a new parameter trying to be set in this way: "spring.liveBeansView.mbeanDomain" I tried adding another block to my web.xml to skip it in the same way as Pan, but unfortunately this particular code puts me between a rock and a hard place (I either can't start the webapp, or it tries to start an mbean server that I don't want): Commit e5f3669804248a22f860a9580058d41d80a86932 String mbeanDomain = applicationContext.getEnvironment().getProperty(MBEAN_DOMAIN_PROPERTY_NAME); if (mbeanDomain != null ) { synchronized (applicationContexts) { if (applicationContexts.isEmpty()) { try { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.registerMBean( new LiveBeansView(), new ObjectName(mbeanDomain, MBEAN_APPLICATION_KEY, applicationContext.getApplicationName())); } catch (Exception ex) { throw new ApplicationContextException( "Failed to register LiveBeansView MBean" , ex); } } applicationContexts.add(applicationContext); } } I'll have to revert back to 3.1.3.
          Hide
          Pan Luo added a comment -

          Sorry Chris, I didn't get your message back in Nov. Just got the update about this ticket from JIRA.

          Yes, as Daniel said, the learning management system is closed source and I don't think I can create the repo to replicate it.

          However, I think the bug maybe related to the properties don't have the default value under certain conditions.

          Thanks for the information about 3.2, Daniel. It looks like I can't upgrade to 3.2 either

          Show
          Pan Luo added a comment - Sorry Chris, I didn't get your message back in Nov. Just got the update about this ticket from JIRA. Yes, as Daniel said, the learning management system is closed source and I don't think I can create the repo to replicate it. However, I think the bug maybe related to the properties don't have the default value under certain conditions. Thanks for the information about 3.2, Daniel. It looks like I can't upgrade to 3.2 either
          Hide
          Chris Beams added a comment -
          commit 39c00c489e47c2737cea45df3157e719900699c1
          Author: Chris Beams <cbeams@vmware.com>
          Commit: Chris Beams <cbeams@vmware.com>
          
              Avoid UnsupportedOperationEx. with active SecurityManager
              
              Issue: SPR-9970
          
          Show
          Chris Beams added a comment - commit 39c00c489e47c2737cea45df3157e719900699c1 Author: Chris Beams <cbeams@vmware.com> Commit: Chris Beams <cbeams@vmware.com> Avoid UnsupportedOperationEx. with active SecurityManager Issue: SPR-9970

            People

            • Assignee:
              Chris Beams
              Reporter:
              Pan Luo
              Last updater:
              Chris Beams
            • Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 12 weeks, 2 days ago