class FileSecurityInitializer implements ServletContainerInitializer {

    @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(","));
            });
            
        }
    }

}