How to configure “Cross-cell single sign-on” in WebSphere with Jython

To configure “Cross-cell single sign-on” in the WebSphere 6.1 admin console with a Jython script, you can use the script below. This assumes that you’ve exported the keys from the server you are going to connect to.

import java.lang.String as jstr
import java.util.Properties as jprops
import java.io as jio
import javax.management as jmgmt

keyfilepassword = "somepassword"

# Import LTPA Keys
AdminConfig.save(); # This needs to happen so you can write to the Security file.
keyFile = "C:/projects/custom-security/was61keys";
fin = jio.FileInputStream(keyFile);
wasdev61keys = jprops();
wasdev61keys.load(fin);
fin.close();
password = jstr(keyfilepassword).getBytes();
securityAdmin = AdminControl.queryNames('*:*,name=SecurityAdmin');
securityObjectName = jmgmt.ObjectName(securityAdmin);
params = [wasdev61keys, password];
signature = ['java.util.Properties', '[B'];
AdminControl.invoke_jmx(securityObjectName, 'importLTPAKeys', params, signature);

# Save Config at the end.
AdminConfig.save();

How to configure a Shared Library in WebSphere with Jython

Here’s a script that I used to configure a Shared Library in WebSphere 6.1 using Jython.

from string import whitespace

sharedLibName = "APPLICATION_SHARED_LIB"

# See if library already exists.
cellId = AdminConfig.list("Cell")
sharedLibraryId = AdminConfig.list("Library")
if (sharedLibraryId.find(sharedLibName) < 0): # Library does not exist.
	print "Creating Shared Library"
	params = [];
	params.append(["name", sharedLibName]);
	sharedLibraryId = AdminConfig.create("Library", cellId, params);

	# Find PARENT_LAST class loader
	print "Finding Class Loader"
	parentLastClassLoader = None;
	classLoaders = AdminConfig.list("Classloader")
	classLoaders = classLoaders.split();
	for classLoader in classLoaders:
		mode = AdminConfig.showAttribute(classLoader, "mode");
		if (mode == "PARENT_LAST"):
			parentLastClassLoader = classLoader;
			print "Found Parent Last Class Loader: " + classLoader;
	# Create a class loader
	if (parentLastClassLoader == None):
		print "Creating Class Loader";
		applicationServer = AdminConfig.list("ApplicationServer")
		params = [];
		params.append(["mode", "PARENT_LAST"]);
		parentLastClassLoader = AdminConfig.create("Classloader", applicationServer, params)
		print "Created Parent Last Class Loader: " + parentLastClassLoader;

	# Add the shared library to the class loader.
	params = [];
	params.append(["libraryName", sharedLibName]);
	params.append(["sharedClassloader", "true"]);
	AdminConfig.create("LibraryRef", parentLastClassLoader, params)

	print "Using Shared Library: " + sharedLibraryId;

	# Set a WAS variable to point to SharedLib
	print "Update the Variable Map"
	variableMap = AdminConfig.list("VariableMap").split();
	# Find the variable map for the server.
	for v in variableMap:
		if (v.find("/server") >= 0):
			variableMap = v
	print "Updating Variable Map: " + variableMap
	params = [];
	params.append(["symbolicName", "APP_SHARED_LIB_PATH"]);
	params.append(["value", "${APP_PROJECTS_ROOT}/SharedLib/MyApp"]);
	params.append(["description", "Root folder containing shared libs"]);
	AdminConfig.create("VariableSubstitutionEntry", variableMap, params);

	# Add all of our shared libs to Shared Library
	print "Adding Classpath";
	classpath = []
	classpath.append("${APP_SHARED_LIB_PATH}/activation.jar")
	classpath.append("${APP_SHARED_LIB_PATH}/commons-lang-2.1.jar")
	classpath.append("${APP_SHARED_LIB_PATH}/commons-logging.jar")
	classpath.append("${APP_SHARED_LIB_PATH}/dom4j-1.6.1.jar")
	classpath.append("${APP_SHARED_LIB_PATH}/smtp.jar")
	classpathStr = ""
	for c in classpath:
		if len(classpathStr) > 0:
			classpathStr += ";";
		classpathStr += c;
	params = [];
	params.append(["classPath", classpathStr]);
	AdminConfig.modify(sharedLibraryId, params);

# Save Config at the end.
AdminConfig.save();

How to configure WebSphere Global Security to use LDAP with Jython

Here’s a script that I used to configure the WebSphere 6.1 global security setting to use LDAP using Jython.

# Properties
username = "user"
password = "pass"
ldapServer = "somecompany.com"
ldapPort = "389"

# Configure the LDAP authentication
AdminConfig.save(); # This needs to happen so you can write to the Security file.
ltpa = AdminConfig.list("LTPA");
ldapUserRegistry = AdminConfig.list("LDAPUserRegistry");
params = [];
params.append(["primaryAdminId", username]);
params.append(["useRegistryServerId", "false"]);
params.append(["type", "ACTIVE_DIRECTORY"]);
params.append(["realm", ldapServer + ":" + ldapPort]);
params.append(["baseDN", "DC=somecompany,DC=com"]);
params.append(["bindDN", "CN=" + username + ",OU=Service Accounts,DC=somecompany,DC=com"]);
params.append(["bindPassword", password]);
AdminConfig.modify(ldapUserRegistry, params);
# Configure the LDAP Advanced Settings
ldapSearchFilter = AdminConfig.list("LDAPSearchFilter");
params = [];
params.append(["userFilter", "(&(sAMAccountName=%v)(objectcategory=user))"]);
params.append(["groupFilter", "(&(cn=%v)(objectcategory=group))"]);
params.append(["userIdMap", "user:sAMAccountName"]);
params.append(["groupIdMap", "*:cn"]);
params.append(["groupMemberIdMap", "memberof:member"]);
params.append(["certificateMapMode", "EXACT_DN"]);
params.append(["certificateFilter", ""]);
AdminConfig.modify(ldapSearchFilter, params);
# Configure the LDAP endpoint.
endpointStr = AdminConfig.showAttribute(ldapUserRegistry, "hosts");
endpointStr = endpointStr[1:len(endpointStr)-1];
endpoint = endpointStr.split(' ')[0];
print endpoint
params = [];
params.append(["host", ldapServer]);
params.append(["port", ldapPort]);
AdminConfig.modify(endpoint, params);

# Configure Global Security
security = AdminConfig.list("Security") # ex. (cells/CompNode10Cell|security.xml#Security_1)
params = [];
params.append(["enabled", "true"]);
params.append(["appEnabled", "true"]);
params.append(["enforceJava2Security", "false"]);
params.append(["activeUserRegistry", ldapUserRegistry]);
params.append(["activeAuthMechanism", ltpa]);
AdminConfig.modify(security, params);

# Save Config at the end.
AdminConfig.save();

Finding line count in DOS

In Unix, there’s this nifty binary called “lc” which gives you the line count of the file.

However, in DOS, you have to be a little more creative. Below is a DOS command I use to count the number of lines in a text file.

FIND /v /c "nonsense" filename.ext

The “nonsense” parameter is some text that is sure not to match any line in the file.

How to get JAX-WS Web Service Method Name

I’m not sure if this will always work, but here is some sample code that I put into a Handler to log the web service method name that is being called. I wanted to be able to track each method, and see which ones were getting use.

This web service was running on IBM WebSphere 6.1.


public boolean handleMessage(LogicalMessageContext context) {
	String webMethodOperationName = null;
	try {
		Field mepCtxField = context.getMessage().getClass().getDeclaredField("mepCtx");
		mepCtxField.setAccessible(true);
		Object mepCtx = mepCtxField.get(context.getMessage());
		
		Field requestMCField = mepCtx.getClass().getDeclaredField("requestMC");
		requestMCField.setAccessible(true);
		Object requestMC = requestMCField.get(mepCtx);
		
		Field operationDescField = requestMC.getClass().getDeclaredField("operationDesc");
		operationDescField.setAccessible(true);
		Object operationDesc = operationDescField.get(requestMC);
		
		Field webMethodOperationNameField = operationDesc.getClass().getDeclaredField("webMethodOperationName");
		webMethodOperationNameField.setAccessible(true);
		webMethodOperationName = (String) webMethodOperationNameField.get(operationDesc);
	}
	catch (Exception e) {
		log.warn("Cannot find method name of operation.");
	}
	
	System.out.println(webMethodOperationName);
	
	return true;
} 

Simple Lego Ship (with Blender mesh files)

This is a 3D model of a Lego ship that my brother, cousin and I made (over and over) when we were kids. For some reason, the simplicity of the space craft facinated us. We made many other spaceships throughout the summer, but this one stuck with me for some reason. Here’s how it fits together.

The image below shows the pieces required. They are (from left to right): thruster, jet booster, seat, and steering wheel.

Lego Ship Pieces

This next two images shows it going together.

Lego Ship Step 1

Lego Ship Step 2

Finally, here’s the ship fully assembled.

Lego Ship Fully Assembled

Here’s how the ship looks with a Lego Astronaut on it.

Lego Ship and Man

Finally, my brother also had an alternative version where the thruster is a gun. I don’t know if I like this one or not. It would definitely be more useful in a hostile environment, though.

Lego Ship and Man with Gun

I’ve also saved the Blender mesh files below. Feel free to download and use them.

Download the Blender mesh files

Lego Astronaut Blender Mesh Files

Lego Astronaut

Here is a Lego man that I did with Blender (v 2.4.9). I’ve decided I would post this, since when I did a search for one, I couldn’t find one. I will try to keep it up to date. The link to the mesh files are below.

Download the Blender Files (this contains LegoMan.blend, face.jpg, and suit_logo2.jpg)

My First Indigo Bunting Sighting

Since I started paying attention to birds just a few years ago or so, I’ve always been fascinated with the Indigo Bunting. Probably for two reason. One (in my opinion), it’s one of the more exotic looking birds that Minnesotans can see. And two, no matter how hard I tried, I could never see one in the woods. Just pictures in books. It always bugged me.

This morning that all changed though. While I was sitting at the breakfast table, I looked out at the feeder. At first I thought “that’s an indigo bunting out there!” But, since that’s never my luck, I figured it must be a bluebird. Once I saw that the chest was also blue, though, I ran and grabbed my video camera.

I couldn’t believe it. I was actually seeing an indigo bunting. And, not out in some quiet, wooded area, but right in my back yard. Right here in Saint Paul, MN. When I got back to the window with the camera, it was still there. And, it stayed there for quite some time. Here’s the video.

The funny thing is that lately I began thinking my back yard lacked bird traffic. It doesn’t have a lot of trees, so I’ve always figured I’d have problems getting birds to visit. Now, I wonder if these sightings are more common than I think. I haven’t really been bird watching for long, so it was definitely a blast to see. I hope it comes back again soon.

Best CSS trick I’ve ever needed to know

I often have to put CSS hacks in my HTML (thank you IE6), and when I do, I usually refer to this simple set of rules to help me determine what browsers I need the hack to work for.

Essentially, it boils down to this:

1) A dot in front of a style will cause the style to only be read by IE 6 and IE 7.
2) An underscore in front of the style will cause the style to only be read by IE 6.

See below:

margin-top: 1px; /* All Browsers */
.margin-top: 2px; /* Read by IE6 and IE7 only */
_margin-top: 3px; /* Read by IE6 only */

Here’s a link to the original post.

Enjoy.

Galvanized Iron Pipes

Corroded Galvanized Iron PipeWell, it feels good to finally have gotten rid of all of the galvanized pipes on our supply lines at home. I wish I could say I’m going to miss it, but I’m not.

This level of corrosion was pretty much on all of the fittings at the valve connection. This not only made the water pressure lower, but it also makes it nearly impossible to (assuming you are brave enough to try) turn the shut-off valves to the off position. I never turned these ones, for fear of breaking them off, or not getting them to open back up.