作者rexhuang (BlueCancer)
看板java
标题[应用] Parse LDAP(AD) Status Code
时间Sun Oct 6 18:30:05 2019
虽然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://webptt.com/cn.aspx?n=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