Last active
October 7, 2019 13:03
-
-
Save imrexhuang/4e67045d580f4478faf0314cd25b9284 to your computer and use it in GitHub Desktop.
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
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment