使用Apache Shiro进行身份认证-Active Directory认证
来源:互联网 发布:安卓手机网络打印机 编辑:程序博客网 时间:2024/05/12 20:57
Apache Shiro 支持基于活动目录的用户认证。
其配置文件shiro.ini配置如下:
activeDirectoryRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealmactiveDirectoryRealm.url = ldap://192.168.131.111:389activeDirectoryRealm.principalSuffix = @example.com
使用的认证类为ActiveDirectoryRealm。具体调研的方法是queryForAuthenticationInfo(AuthenticationToken token, LdapContextFactory ldapContextFactory)
这里需要一个ldapContextFactory类。系统在初始化时会默认创建一个缺省DefaultLdapContextFactory类。
具体调用是在AbstractLdapRealm中:
protected void onInit() { super.onInit(); ensureContextFactory(); } private LdapContextFactory ensureContextFactory() { if (this.ldapContextFactory == null) { if (log.isDebugEnabled()) { log.debug("No LdapContextFactory specified - creating a default instance."); } DefaultLdapContextFactory defaultFactory = new DefaultLdapContextFactory(); defaultFactory.setPrincipalSuffix(this.principalSuffix); defaultFactory.setSearchBase(this.searchBase); defaultFactory.setUrl(this.url); defaultFactory.setSystemUsername(this.systemUsername); defaultFactory.setSystemPassword(this.systemPassword); this.ldapContextFactory = defaultFactory; } return this.ldapContextFactory; }
用户的认证实现是在DefaultLdapContextFactory类中实现,这部分可以改进一下采用两次绑定会更好
public LdapContext getLdapContext(Object principal, Object credentials) throws NamingException { if (url == null) { throw new IllegalStateException("An LDAP URL must be specified of the form ldap://<hostname>:<port>"); } Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.SECURITY_AUTHENTICATION, authentication); if (principal != null) { env.put(Context.SECURITY_PRINCIPAL, principal); } if (credentials!= null) { env.put(Context.SECURITY_CREDENTIALS, credentials); } env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClassName); env.put(Context.PROVIDER_URL, url); env.put(Context.REFERRAL, referral); // Only pool connections for system contexts if (usePooling && principal != null && principal.equals(systemUsername)) { // Enable connection pooling env.put(SUN_CONNECTION_POOLING_PROPERTY, "true"); } if (additionalEnvironment != null) { env.putAll(additionalEnvironment); } if (log.isDebugEnabled()) { log.debug("Initializing LDAP context using URL [" + url + "] and username [" + systemUsername + "] " + "with pooling [" + (usePooling ? "enabled" : "disabled") + "]"); } return new InitialLdapContext(env, null); }
基本上活动目录的认证方式同LDAP认证方式是一样的。因为ad(活动目录)本身就是基于ldap协议的一个微软产品。
- 使用Apache Shiro进行身份认证-Active Directory认证
- 使用Apache Shiro进行身份认证
- 使用Apache Shiro进行身份认证-LDAP认证
- 使用Apache Shiro进行身份认证-LDAP两次绑定认证
- 使用Apache Shiro进行身份认证-多数据源认证
- 使用Apache Shiro进行身份认证-LDAP认证
- 使用Apache Shiro进行身份认证-密码加密
- 使用Apache Shiro进行身份认证-proxool配置
- C#.Net中WinForm采用Active Directory进行身份认证
- C#中WinForm采用Active Directory进行身份认证
- Apache Shiro 身份认证例子
- Apache Shiro 身份认证例子
- 使用Apache Shiro进行java认证说明
- Apache shiro 笔记整理之身份认证
- Apache Shiro身份认证(Authentication)
- 2 Apache Shiro 身份认证(登录)
- java连接Active Directory进行用户认证
- 身份认证(shiro)
- 使用Java操作Mongodb
- Dibonacci——不断培养的数学感情
- 各银行卡的优缺点,有用啊
- Linux文件夹和文件权限
- keytool命令详解
- 使用Apache Shiro进行身份认证-Active Directory认证
- 我的Dll(动态链接库)学习笔记
- Android 地区语言和简写对照表
- MyEclipse使用小技巧
- hadoop分布式系统优化分析
- LINUX VNC配置
- 百元钞票水印处多出00佰元 银行鉴定为真币
- Linux 中如何查询和卸载已安装的软件
- sap!!!