test_class.file: security/file/src/test/java/cloud/piranha/security/file/FileSecurityInitializerTest.java
test_class.identifier: FileSecurityInitializerTest
test_case.body: @Test
      public void testOnStartup() throws Exception {
          DefaultWebApplication webApplication = new DefaultWebApplication();
          webApplication.addInitializer(new FileSecurityInitializer());
          webApplication.initialize();
          DefaultSecurityManager manager = (DefaultSecurityManager) webApplication.getSecurityManager();
          DefaultWebApplicationRequest request = new DefaultWebApplicationRequest();
          manager.login(request, "j2ee", "j2ee");
          assertTrue(manager.isUserInRole(request, "Administrator"));
      }
test_case.class_method_signature: FileSecurityInitializerTest.testOnStartup()
test_case.full_signature: @Test public void testOnStartup()
test_case.identifier: testOnStartup
test_case.invocations: addInitializer initialize getSecurityManager login assertTrue isUserInRole
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testOnStartup()
focal_class.file: security/file/src/main/java/cloud/piranha/security/file/FileSecurityInitializer.java
focal_class.identifier: FileSecurityInitializer
focal_class.interfaces: implements ServletContainerInitializer
focal_class.class_method_signature: FileSecurityInitializer.onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_class.full_signature: @Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_class.identifier: onStartup
focal_class.modifiers: @Override public
focal_class.parameters: (Set<Class<?>> classes, ServletContext servletContext)
focal_class.return: void
focal_class.signature: void onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_method.body: @Override
      public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
              throws ServletException {
  
          WebApplication webApplication = (WebApplication) servletContext;
          DefaultSecurityManager securityManager = new DefaultSecurityManager();
          webApplication.setSecurityManager(securityManager);
  
          File userFile = new File("user.properties");
          if (!userFile.exists()) {
              userFile = new File("etc/user.properties");
          }
          if (userFile.exists()) {
              Properties userProperties = new Properties();
              try (FileInputStream fileInput = new FileInputStream(userFile)) {
                  userProperties.load(fileInput);
              } catch (IOException ioe) {
              }
              userProperties.entrySet().forEach(entry -> {
                  String username = (String) entry.getKey();
                  String password = (String) entry.getValue();
                  securityManager.addUser(username, password);
              });
          }
          
          File userRoleFile = new File("userrole.properties");
          if (!userRoleFile.exists()) {
              userRoleFile = new File("etc/userrole.properties");
          }
          if (userRoleFile.exists()) {
              Properties userRoleProperties = new Properties();
              try (FileInputStream fileInput = new FileInputStream(userRoleFile)) {
                  userRoleProperties.load(fileInput);
              } catch (IOException ioe) {
              }
              userRoleProperties.entrySet().forEach(entry -> {
                  String username = (String) entry.getKey();
                  String roles = (String) entry.getValue();
                  securityManager.addUserRole(username, roles.split(","));
              });
              
          }
      }
focal_method.class_method_signature: FileSecurityInitializer.onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_method.full_signature: @Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext)
focal_method.identifier: onStartup
focal_method.invocations: setSecurityManager exists exists load forEach entrySet getKey getValue addUser exists exists load forEach entrySet getKey getValue addUserRole split
focal_method.modifiers: @Override public
focal_method.parameters: (Set<Class<?>> classes, ServletContext servletContext)
focal_method.return: void
focal_method.signature: void onStartup(Set<Class<?>> classes, ServletContext servletContext)