[應用] Parse LDAP(AD) Status Code
雖然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;
}
}
--
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.10.123 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/java/M.1570357809.A.306.html
※ 編輯: rexhuang (36.228.10.123 臺灣), 10/07/2019 21:01:07
※ 編輯: rexhuang (36.228.10.123 臺灣), 10/07/2019 21:03:37
java 近期熱門文章
PTT數位生活區 即時熱門文章