[應用] Parse LDAP(AD) Status Code

看板java作者 (BlueCancer)時間5年前 (2019/10/06 18:30), 5年前編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
雖然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
文章代碼(AID): #1TcS8nC6 (java)
文章代碼(AID): #1TcS8nC6 (java)