Blog Archives

Access private fields per Reflections within Glassfish

You can not access a private field per Reflections, if your application runs on Glassfish. You have to set a policy entry on the server to permit it:

1. open the security policy file: glassfishv3/glassfish/domains/domain1/config/server.policy
2. include the following entry:

        grant codeBase "file:${com.sun.aas.installRoot}/domains/domain1/applications/arena-dwr/-" {
            permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
        };

Don’t forget to replace the arena-dwr by the name of your application, and also to check project path if you are not using the default container instance domain1.

Then you can call:

   Entity.class.getDeclaredFields()

without a SecurityException.

HTPP -> HTTP redirect on Glassfish 3.1.2.2

Execute this on your Glassfish machine:

###
### HttpToHttpsRedirectOnDifferentPort
###
asadmin create-protocol --securityenabled=false http-redirect
asadmin create-http-redirect --redirect-port 443 --secure-redirect true http-redirect
asadmin create-protocol --securityenabled=false http-redirect-base
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-listener-2 --classname com.sun.grizzly.config.HttpProtocolFinder https-finder
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-redirect --classname com.sun.grizzly.config.HttpProtocolFinder http-redirect
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=http-redirect-base