Enable BlazeDS 4 on Glassfish V3.1.1

I had been using BlazeDS 3 on Sun Glassfish Enterprise Application Server V2.1.1 for a long time. At that time, I  followed someone's guide and hacked TomcatValve.java. And then BlazeDS 3 will be fully supported on Glassfish V2.1.1, including authentication of course.

But for Glassfish V3, I cannot find any guide, and authentication failed for Glassfish V3.1.1. And then I downloaded the source code of Glassfish V3.1.1 and BlazeDS 4, after 1 day's debugging. I got the solution hacking TomcatValve again. If you don't want to know the detail, just download the jar file or java file. For java file you have to compile that by yourself in BlazeDS 4 open source project. And for jar file, put them into the following directory:

$glassfish_home/glassfish/lib/

If you want to know all the detail about this issue, you can read the article below.

What caused BlazeDS's TomcatValve failed to authenticate?

No method found for Realm.authenticate(String username, String password).

Why BlazeDS's TomcatValve doesn't work for Glassfish V3.1.1 Server?

Glassfish changed it's method signature to Realm.authenticate(String username, char[] password).

How to hack?

Simple replace the method invocation with the following code segment:
			char[] passwordCharArray = password.toCharArray();

			try {
				Method m = realm.getClass().getMethod("authenticate",
						String.class, char[].class);
				principal = (Principal) m.invoke(realm, username,
						passwordCharArray);
			} catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}



More details.

Glassfish(Tomcat) Server will configure Web Module via following class and method:

WebModule.configureCatalinaProperties

    /**
     * Configure the <code>WebModule</code< properties.
     * @param propName the property name
     * @param propValue the property value
     */
    protected void configureCatalinaProperties(String propName,
                                               String propValue){
        if (propName == null || propValue == null) {
            logger.log(Level.WARNING,
                        "webcontainer.nullWebModuleProperty",
                        getName());
            return;
        }

        if (propName.startsWith("valve_")) {
            addValve(propValue);
        } else if (propName.startsWith("listener_")) {
            addCatalinaListener(propValue);
        }
    }



We can see, why we have to configure "<property name="valve_1" value="flex.messaging.security.TomcatValve"/>" into glassfish-web.xml,

你可能感兴趣的:(javaee,Security,Authentication,blazeds,Glassfish)