dev@glassfish.java.net

realm file names

From: Bill Shannon <bill.shannon_at_oracle.com>
Date: Mon, 19 Jul 2010 12:54:57 -0700

One of the things the startup synchronization code needs to do is
to synchronize all the files for file realms used by an instance.

I wrote the following method to discover these file names. Can someone
please review this and let me know if it looks correct? It seems to
work for my simple test cases.

Thanks.



    private static final String FILE_REALM_CLASS =
        "com.sun.enterprise.security.auth.realm.file.FileRealm";

    /**
     * Get the names of any realm files in the config directory
     * and add them to the set of file names. This will normally
     * find at least the "admin-keyfile" and "keyfile" files.
     */
    private void getRealmFileNames(Server server, Set<String> files) {
        File configDir = env.getConfigDirPath();
        URI configURI = configDir.toURI();
        Config config = domain.getConfigNamed(server.getConfigRef());
        // XXX - need to handle cluster instances specially?
        SecurityService securityService = config.getSecurityService();
        for (AuthRealm authRealm : securityService.getAuthRealm()) {
            String fileRealmClassName = authRealm.getClassname();
            // skip it if it's not a file realm
            if (fileRealmClassName == null ||
                    !fileRealmClassName.equals(FILE_REALM_CLASS))
                continue;
            String file = authRealm.getPropertyValue("file");
            if (file == null) // skip if no "file" property
                continue;
            File rfile = new File(file);
            if (!rfile.exists()) // skip if file doesn't exist
                continue;
            URI rURI = rfile.toURI();
            URI f = configURI.relativize(rfile.toURI());
            if (!f.isAbsolute()) // if file is in config dir, add it
                files.add(f.toString());
        }
    }