Thursday, July 24, 2008

It is 30's All Over Again

From Bloomberg
Federal Reserve Bank of New York President Timothy Geithner said the central bank should play a prominent part in regulating financial institutions and ensuring market stability after the biggest credit crisis in decades.


Let me translate, the crisis we had a big hand in creating needs an even bigger hand to be helped.

Give me a break!!!!!

Excuse me, but how are you going to fix this? More regulation, socializing loses? The fix is to unwind bad debt - not with taxpayer money. Stop using FRE and FNM for origination (at least only originate under ever stricter standards) , and wind them out of business when the last bond holders are paid back. Cuba is a great example of how well nationalization works - we are trying to emulate them.

Thursday, June 26, 2008

What Dodd Didn't Know

Senator Dodd didn't know he would be in such a pickle. Dodd is either incompetent or he is unethical - in my opinion. If he can't recognize an extremely favorable deal on a Countrywide mortgage he is incompetent and not fit to be the BANKING committee chair. Worse, if he was unethical and took such a deal knowingly, then he should resign from the Senate.

I could rail on the softball questions Mozilo received or question who wrote the bank bailout bill winding through Congress but those have been sufficiently covered. At a minimum, the senator should resign from the banking committee that he chairs.

My wish is for the good people of Connecticut to elect a new Senator to serve their state and the people of the United States.

Thursday, April 10, 2008

Jakarta Commons HttpClient Digest Authentication

Working with Apache Jakarta HttpClient to call a site to get protected content can be easily achieved. The example below includes both setting up your Apache Web server (2.0) to use .htaccess to a protected file. The example presumes an example Java client that will make a GET request to an Apache HTML file protected using .htaccess and Digest Authentication.

The protected resource:
http://localhost/fishsticks/hello.html

Apache Version:
Apache 2.0 on Fedora 8

Setting up Apache for .htaccess
Configure the httpd.conf file to allow .htaccess by editing the section that looks like:
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None



Change the AllowOverride directive to be
AllowOverride AuthConfig


And then restart the Apache httpd (the web server). The httpd.conf on Fedora is located in /etc/httpd/conf directory and on windows it is generally on C:\Program Files\Apache Group\Apache\conf (or something close to that).

Next go to the content directory of the web server and add the .htaccess file. In my example, Apache serves files from /var/www/html directory. Therefore, I create the fishsticks directory, create a simple hello.html file that says "fishsticks". Make sure you can view this page in the browser. Simple go to http://localhost/fishsticks/hello.html. You should see the word "fishsticks" in your browser.

Creating the .htaccess File
The .htaccess file goes in the fishsticks directory that Apache serves content from (/var/www/html/fishsticks).

The .htaccess file needs to contain:
AuthType Digest
AuthName "realm"
AuthUserFile /usr/local/apache/passwd/digest
Require user corbin

The password file also needs to be created. This is done using the htpasswd utility, for example:
htpasswd -c /usr/local/apache/passwd/digest realm corbin

You will be requested to type and re-type the new password.
Adding password for corbin in realm realm.
New password:
Re-type new password:

Now you will have the file /usr/local/apache/passwd/digest which contains the following line:
corbin:realm:a8f9dac51f13bb1a0eb9ffe3aea281d6


Restart the Apache httpd and try to hit the url http://localhost/fishsticks/hello.html and you should be presented with an authorization dialog from your browser. This a controlled by the browser so there is not much you may do to make it pretty.

If you authenticate using username "corbin" and password "dallas" you should see the fishsticks page. If you fail authentication you will get a http 401 status page.

The code for the test client is:
package com.mindlinc.rx.integration.agent;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;

public class TestAuthentication {

/**
* @param args
*/
public static void main(String[] args) {

HttpClient client = new HttpClient();
UsernamePasswordCredentials upc = new UsernamePasswordCredentials("corbin", "dallas");
AuthScope as = new AuthScope("localhost", 80, "realm");
client.getState().setCredentials(as, upc);

try {
GetMethod gm = new GetMethod("http://localhost/fishsticks/hello.html");
int status = client.executeMethod(gm);
System.out.println("Response Status: "+ status);
String result = gm.getResponseBodyAsString();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
}

}


If you change the username or password the returned status will be 401 instead of 200 when you successfully authenticate.

Thursday, August 23, 2007

SOLVED: Fedora or Redhat clock drift under VMWare server

I stumbled upon an easy solution to clock skew or drift when, at least in my case, Redhat EL or Fedora 7 are a vmware server guest OS under Windows Server 2003.

Edit the /etc/grub.conf file and add to the end of the line that begins with "kernel /boot/vmlinuz-2.6.22.1-41.fc7.img ..."

These are the boot options for the kernel.

At the end of the above line add clock=pmtmr to the end of that line. Your kernel line in grub.conf should look similar to the following:

kernel /boot/vmlinuz-2.6.22.1-41.fc7 ro root=LABEL=/ rhgb quiet clock=pmtmr

Reboot and you clock drift should cease. Make sure to make a copy of the original just in case you cannot boot Linux. You can use either an alternate boot option or a rescue disk to recover to the original file.

Tuesday, May 15, 2007

JBoss 4.2 with Seam 1.2 using MyFaces

JBoss stopped using MyFaces in JBoss 4.2 and started using a JSF 1.2 compliant deployment.
This creates problems when using Seam 1.2.1 and JBoss 4.2 together. The fix is quite simple and can be remedied in three easy steps.

Step One:
Remove the MyFaces entry in web.xml by commenting out the MyFaces listener as shown below by adding the blue text below:
<!--
<listener> <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
-->

Step Two:
Edit application.xml (usually in the project's resources directory) and remove by either deletion or comment the el-api.jar module.

You can comment it out as shown below:
<!--
<module>
<java>el-api.jar</java>
</module>
-->

Step Three:
The final step is to make sure the build.xml copies commons-digester and commons-beanutils to the WEB-INF/lib directory of the web application's war file.

Add the following two lines to build.xml that are highlighted below in blue in the build files "war" target:
<target name="war" depends="compile"
description="Build the distribution .war file">
<copy todir="${war.dir}">
<fileset dir="${basedir}/view" />
</copy>
<copy todir="${war.dir}/WEB-INF">
<fileset dir="${basedir}/resources/WEB-INF">
<include name="*.*"/>
<include name="classes/**/*.*"/>
<exclude name="classes/**/*.class"/>
</fileset>
<filterset>
<filter token="debug" value="${debug}" />
<filter token="jndiPattern" value="${project.name}/#{ejbName}/local" />
<filter token="embeddedEjb" value="false" />
</filterset>
</copy>
<copy todir="${war.dir}/WEB-INF">
<fileset dir="${basedir}/resources/WEB-INF">
<include name="lib/*.*"/>
<include name="classes/**/*.class"/>
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/lib">
<fileset dir="${lib.dir}">
<include name="ajax4jsf*.jar" />
<include name="richfaces*.jar" />
<include name="oscache*.jar" />
<include name="jsf-facelets.jar" />
<include name="jboss-seam-*.jar" />
<include name="commons-digester-*.jar"/>
<include name="commons-beanutils-*.jar"/>
<exclude name="jboss-seam-gen.jar" />
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/classes">
<fileset dir="${basedir}/resources">
<include name="messages*.properties"/>
</fileset>
</copy>
</target>

That should be sufficient to run the seam-gen generated applications to run on JBoss 4.2.0GA.

Sunday, May 6, 2007

JBoss and Global JNDI Entries

In Tomcat, global JNDI entries can be added to the server.xml file to allow for JNDI entries to be shared across all deployed applications needing them. Trying to find way to get global JNDI entries in JBoss 4 was difficult, but the solution was easy. Probably a Google search string issue, anyway on to the solution.

How do you add global JNDI entries to JBoss?
To add global JNDI entries you simply create (edit if it exists) an jboss-service.xml file and use the JNDIBindingServiceMgr MBean.

jboss-service.xml:
   <?xml    version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
<server>
<mbean code="org.jboss.naming.JNDIBindingServiceMgr"
name="jboss.tests:service=JNDIBindingServiceMgr">
<attribute name="BindingsConfig" serialDataType="jbxb">
<jndi:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd">
<jndi:binding name="urls/jboss-home">
<jndi:value type="java.net.URL">http://www.jboss.org</jndi:value>
</jndi:binding>

<jndi:binding name="urls/scotts-test">
<jndi:value type="java.lang.String">http://www.yahoo.com</jndi:value>
</jndi:binding>

<jndi:binding name="hosts/localhost">
<jndi:value editor="org.jboss.util.propertyeditor.InetAddressEditor">127.0.0.1</jndi:value>
</jndi:binding>
<jndi:binding name="maps/testProps">
<java:properties xmlns:java="urn:jboss:java-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
<java:property>
<java:key>key1</java:key>
<java:value>value1</java:value>
</java:property>
<java:property>
<java:key>key2</java:key>
<java:value>value2</java:value>
</java:property>
</java:properties>
</jndi:binding>
</jndi:bindings>
</attribute>
</mbean>

</server>


</server>


Simply add/edit a jndi:binding to suit your needs and you will be able to access from either your EJB or web application. The Java code to access the entries in /urls including "scotts-test" above, simply perform the following in your enterprise application.


Retrieving Global JNDI Entries:
Context ctx = new InitialContext();
NamingEnumeration items = ctx.listBindings("/urls");
while ( items.hasMoreElements() ) {
System.out.println( items.next().toString() );
}


Some are probably wondering where the jboss-service.xml file goes. The place that worked for me was into <JBOSS_HOME>/server/default/deploy and then restart JBoss.

Related Links:
JBoss Wiki on JNDIBindingServiceMgr


Contributors