Thursday, 16 September 2010

Retrieving password, using spring-ldap

Consider following code snippet:
public class PasswordContextMapper extends AbstractContextMapper {
public static final String UID = "uid";
public static final String PASSWORD = "userPassword";
public static final String[] LDAP_ATTRIBUTES = { UID, PASSWORD };

@Override
protected Password doMapFromContext(DirContextOperations ctx) {
final Password p = new Password();
p.setPassword(ctx.getStringAttribute(PASSWORD));
p.setUid(ctx.getStringAttribute(UID));
return p;
}
}

Looks ok? Think again. There's one pitfall with password retrieval from LDAP. Although different LDAP viewers show password as hashed text, it's really an array of bytes. This code throws something like
[B cannot be cast to java.lang.String
It actually says that "Cannot cast from array of bytes to String" ('[' shows that object is array of something). Solution is trivial. Change ctx.getStringAttribute(PASSWORD) to ctx.getObjectAttribute(PASSWORD).toString();

Thursday, 19 August 2010

IE7 stretches element around text input field

Situation description: one of the application forms has lots of input fields. They're all formatted using table. One main table has two columns, where each of them contains another table with two columns. In each row of the inner table the first cell contains field label and the second cell contains field itself. Whole table is in DIV element with width of 100%.

I received some problem reports from users that by entering large text in the input field (input type="text") of the first column, other column is moving to the left until it completely disappears. Width of the input element is set to 250px. It turns out that IE7 allows input elements to stretch according to the length of entered text. Although width is set to 250px and user sees it as 250px wide, cell is stretched as if input element wouldn't have defined width.

Solution i found is add overflow:hidden style attribute.

Wednesday, 6 January 2010

Spring 3.0

At the end of last year Spring 3.0 was released (http://blog.springsource.com/2009/12/16/spring-framework-3-0-goes-ga/). But if you're developing v1.0 portlets, then you won't be able to use it, because it REQUIRES portlet v2.0 API.