Created
July 18, 2011 19:32
-
-
Save yock/1090422 to your computer and use it in GitHub Desktop.
Vendor-supplied (before)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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