`
chinaet
  • 浏览: 5853 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

让liferay 支持 LDAP SSHA加密方式

阅读更多
最近公司的邮件服务器改成了ZIMBRA,ZIMBRA的LDAP使用了SSHA 加密方式,但是LIFERAY不支持,看了一下LIFERAY的代码,我写了一个patch。

ssha.patch

--- LDAPAuth.java 2007-03-01 23:42:18.000000000 +0800
+++ /liferay/portal-ejb/src/com/liferay/portal/security/auth/LDAPAuth.java 2007-03-01 23:11:33.000000000 +0800
@@ -28,6 +28,7 @@
import com.liferay.portal.kernel.log.LogUtil;
import com.liferay.portal.kernel.util.StackTraceUtil;
import com.liferay.portal.kernel.util.StringPool;
+import com.liferay.portal.kernel.util.Base64;
import com.liferay.portal.model.User;
import com.liferay.portal.security.ldap.LDAPImportUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
@@ -54,6 +55,10 @@
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;

+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import sun.misc.BASE64Encoder;
+
/**
* View Source
*
@@ -261,23 +266,11 @@
if (userPassword != null) {
String ldapPassword = new String((byte[])userPassword.get());

- String encryptedPassword = password;
-
- String algorithm = PrefsPropsUtil.getString(
- companyId,
- PropsUtil.AUTH_IMPL_LDAP_PASSWORD_ENCRYPTION_ALGORITHM);
-
- if (Validator.isNotNull(algorithm)) {
- encryptedPassword =
- "{" + algorithm + "}" +
- Encryptor.digest(algorithm, password);
- }
-
- if (!ldapPassword.equals(encryptedPassword)) {
+ if (!verifyPassword(ldapPassword,password)) {
_log.error(
"LDAP password " + ldapPassword +
" does not match with given password " +
- encryptedPassword + " for user id " + userId);
+ password + " for user id " + userId);

return false;
}
@@ -381,6 +374,98 @@
locationId, sendEmail, true, true);
}

+ /**
+ * Splits a byte array into two.
+ *
+ * @param src byte array to split
+ * @param n location to split the array
+ * @return a two dimensional array of the split
+ */
+ private static byte[][] split(byte[] src, int n) {
+ byte[] l;
+ byte[] r;
+
+ if (src.length <= n) {
+ l = src;
+ r = new byte[0];
+
+ } else {
+ l = new byte[n];
+ r = new byte[src.length - n];
+ System.arraycopy(src, 0, l, 0, n);
+ System.arraycopy(src, n, r, 0, r.length);
+
+ }
+
+ byte[][] lr = { l, r };
+
+ return lr;
+
+ }
+
+
+ /**
+ * Validates if a plaintext password matches a
+ * hashed version.
+ *
+ * @param digest digested version
+ * @param password plaintext password
+ * @return if the two match
+ */
+ public static boolean verifyPassword(String digest, String password) {
+ String alg = null;
+ int size = 0;
+
+ if (digest.regionMatches(true, 0, "{SHA}", 0, 5)) {
+ digest = digest.substring(5);
+ alg = "SHA-1";
+ size = 20;
+
+ } else if (digest.regionMatches(true, 0, "{SSHA}", 0, 6)) {
+ digest = digest.substring(6);
+ alg = "SHA-1";
+ size = 20;
+
+ } else if (digest.regionMatches(true, 0, "{MD5}", 0, 5)) {
+ digest = digest.substring(5);
+ alg = "MD5";
+ size = 16;
+
+ } else if (digest.regionMatches(true, 0, "{SMD5}", 0, 6)) {
+ digest = digest.substring(6);
+ alg = "MD5";
+ size = 16;
+
+ }
+
+ try {
+ MessageDigest mDigest = MessageDigest.getInstance(alg);
+
+ if (mDigest == null) {
+ return false;
+
+ }
+
+ byte[][] hs = split(Base64.decode(digest), size);
+ byte[] hash = hs[0];
+ byte[] salt = hs[1];
+ mDigest.reset();
+ mDigest.update(password.getBytes());
+ mDigest.update(salt);
+
+ byte[] pwhash = mDigest.digest();
+
+ return MessageDigest.isEqual(hash, pwhash);
+
+ } catch (NoSuchAlgorithmException nsae) {
+ _log.error(StackTraceUtil.getStackTrace(nsae));
+ return false;
+ }
+
+ }
+
+
+
private static Log _log = LogFactoryUtil.getLog(LDAPAuth.class);

-}
\ No newline at end of file
+}
分享到:
评论
1 楼 pikachu 2007-03-22  
谢谢chinaet热心帮助

相关推荐

    Liferay与LDAP集成

    Liferay与LDAP集成是将Liferay门户与目录服务相结合,实现单点登录、用户身份验证和用户数据同步等功能,提升企业级应用的安全性和用户体验。 OpenLDAP是LDAP协议的开源实现,包括slapd(LDAP服务守护进程)、...

    liferay cas ldap 集成配置

    总的来说,Liferay、CAS和LDAP的集成提供了一种安全且高效的方式来管理用户身份和访问控制,同时减少了用户在多个应用中重复输入凭据的麻烦。虽然配置过程可能复杂,但一旦设置完成,它可以极大地提升系统的安全性与...

    liferay + cas + ldap 集成配置

    标题 "Liferay + CAS + LDAP 集成配置" 涉及到的是在企业级内容管理系统 Liferay 中集成 Central Authentication Service (CAS) 和 Lightweight Directory Access Protocol (LDAP) 的过程。这种集成允许用户通过CAS...

    Liferay_SSH_开发案例

    【Liferay SSH 开发案例详解】 在Web应用开发领域,Liferay是一款强大的开源企业级门户平台,它提供了丰富的功能和高度可扩展性。SSH(Spring、Struts、Hibernate)是Java Web开发中常用的一种技术栈,用于构建MVC...

    Liferay 6 入门教程

    Liferay 6还支持Spring框架,"plugins开发指南17-liferay中spring开发(1).pdf"和"plugins开发指南18-liferay中spring开发(2).pdf"两部分深入探讨了如何在Liferay环境中利用Spring进行服务和组件的管理。...

    liferay 资料

    - 它支持 LDAP 和 SSO(单点登录),便于与企业现有身份验证系统集成。 7. **移动支持**: - Liferay 提供了移动友好的界面,同时也支持开发针对移动设备的 portlets。 - 通过 Liferay 移动 SDK,开发者可以构建...

    LifeRay+CAS+LDAP+Tomcat 单点登录门户.pdf

    【LifeRay+CAS+LDAP+Tomcat 单点登录门户】是一种常见的企业级身份验证解决方案,它结合了多个组件来实现高效、安全的用户登录管理。在这个架构中,LifeRay 是一个开源的内容管理系统,用于构建企业门户;CAS...

    liferay教程

    此外,Liferay还支持SSO(Single Sign-On)和LDAP集成,以便于企业进行身份验证和权限管理。 在实际应用中,Liferay的自定义开发是必不可少的。开发者可以通过编写Java Portlets、JSR-286 Portlets或者Freemarker...

    liferay详细讲解 liferay项目完全讲解

    5. **国际化和多语言支持**:Liferay支持多种语言,对于跨国企业尤其重要。 6. **服务和API**:Liferay提供大量的服务接口,开发者可以利用这些API进行扩展和集成。 7. **Web内容管理系统**:Liferay内置的WCM系统...

    liferay 6.2开发指南+用户手册

    Liferay提供了多种安全机制,如SSL加密、访问控制和审计日志。开发者应遵循最佳实践确保数据安全。 14. **监控与调试** 通过Liferay的控制台和日志系统,开发者可以监控应用状态、追踪错误并进行性能分析。 15. ...

    Liferay Portal Liferay IDE

    Liferay Portal Liferay IDE

    Liferay合集.zip

    10. **集成与互操作性**:了解Liferay与其他系统的集成方式,如SAML单点登录、LDAP目录服务等。 总的来说,这个"Liferay合集.zip"是学习和精通Liferay的宝贵资源,无论你是初学者还是经验丰富的开发者,都能从中...

    Liferay平台开发使用详细PPT演示文稿

    - **安全机制**:Liferay具有内置的安全措施,包括数据加密、XSS防护和CSRF保护。 - **身份认证**:支持多种认证机制,如OpenID、OAuth2等,确保用户访问的安全性。 5. **高可用** - **集群部署**:Liferay支持...

    liferay6.2开发指南.pdf

    - **支持的技术框架**:Liferay 内置了对多种开发框架的支持,如 Spring、Struts 和 JSF,使得开发者可以根据需求选择合适的框架进行开发。 #### 1-3 节 扩展和自定义 Liferay Liferay 允许开发者通过以下方式...

    liferay扩展环境 liferay ext

    标题 "Liferay扩展环境 Liferay Ext" 涉及到的是Liferay门户平台的一个关键概念,Liferay Ext是用于扩展和定制Liferay功能的核心工具。Liferay是一个开源的企业级内容管理平台,它允许用户根据需求构建自定义的数字...

    Liferay的CAS SSO实现

    5. **自定义和扩展**:Liferay和CAS的集成还支持自定义和扩展,比如自定义CAS的登录页面、添加额外的认证方式或者对特定用户组进行特殊处理。 SSO的实现不仅可以提升用户体验,还有助于提高安全性,因为用户不需要...

    liferay开发手册

    5. **安全和身份管理**:理解Liferay的安全模型,包括用户认证、授权和角色分配,以及如何与其他身份验证系统(如LDAP)集成。 6. **社区和社交功能**:Liferay内置了社交网络特性,如好友、群组、论坛等,开发者...

Global site tag (gtag.js) - Google Analytics