[应用] Parse LDAP(AD) Status Code

楼主: rexhuang (BlueCancer)   2019-10-06 18:30:05
虽然LDAP很多种,但本范例以Active Directory为主
//Gist版:https://tinyurl.com/y4axafeg
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//取得Active Directory资讯可以参考
https://www.cnblogs.com/qlong8807/archive/2012/10/26/2741563.html
public class ADgetErrorCode {
public static void main(String[] args) {
String errmsg = "[LDAP: error code 49 - 80090308: \r\n" +
" LdapErr: DSID-0C090334, \r\n" +
" comment: AcceptSecurityContext error, data 773, vece]";
System.out.println( getLDAPStatusCode(errmsg) );
System.out.println( getAD49ErrorCode(errmsg) );
}
/*
*
https://stackoverflow.com/questions/30532673/directoryservicescomexception-extendederrormessage-list-of-data-codes
* 525 - user not found
* 52e - invalid credentials
* 530 - not permitted to logon at this time
* 531 - not permitted to logon at this workstation
* 532 - password expired
* 533 - account disabled
* 534 - The user has not been granted the requested logon type at this machine
* 701 - account expired
* 773 - user must reset password
* 775 - user account locked
* */
private static String getAD49ErrorCode(final String exceptionMsg)
{
String pattern=".*data ([A-Za-z0-9]+)";
Pattern p=Pattern.compile(pattern);
Matcher m=p.matcher(exceptionMsg);
if (m.find()) {
return m.group(1);
}
return "Parse 49Code Error";
}
//https://docs.oracle.com/javase/tutorial/jndi/ldap/exceptions.html
//49:Invalid credentials (AuthenticationException)
private static int getLDAPStatusCode(final String exceptionMsg)
{
//String pattern="-?\\d+";
String pattern=".*error code ([0-9]+)";
Pattern p=Pattern.compile(pattern);
Matcher m=p.matcher(exceptionMsg);
if (m.find()) {
//return Integer.valueOf(m.group(0));
return Integer.valueOf(m.group(1));
}
return -1;
}
}

Links booklink

Contact Us: admin [ a t ] ucptt.com