Skip to content

Instantly share code, notes, and snippets.

@yock
Created July 18, 2011 19:32
Show Gist options
  • Save yock/1090422 to your computer and use it in GitHub Desktop.
Save yock/1090422 to your computer and use it in GitHub Desktop.
Vendor-supplied (before)
protected String getUserIdFromPrincipal( Principal prin ) {
try {
if ( prin == null ) {
return "";
}
String decodedPrin = URLDecoder.decode( prin.toString(), "UTF-8" );
// Not in CN=xyz format? Then just return full name up to first space, if any.
if ( !StringUtils.contains( decodedPrin, "=" ) ) {
return StringUtils.substringBefore( decodedPrin, " " );
}
String rhs = StringUtils.substringAfter( decodedPrin, "=" );
// Grab everything before the first comma, if any.
return StringUtils.substringBefore( rhs, "," );
}
catch( UnsupportedEncodingException e ) {
logger.error( e );
throw new RuntimeException( "UnsupportedEncodingException caught in trimUserIdFromPrincipal", e );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment