有一個older thread似乎是我所能找到的唯一相關討論。使用Javamail實現Kerberos驗證
我試圖通過Javamail(通過IMAP)實現Kerberos,我已經弄清楚了究竟要用mail.imap.sasl.mechanisms完成什麼工作。假設我給出了「GSS-API」的值,但是失去了從哪裏去的地方。我注意到Javamail有一個IMAPSaslAuthernticator類。在我看來,這是需要的,但我可以在哪裏或如何使用它,找到寶貴的小文檔。
任何想法?
注:我想發佈更多的代碼爲我的問題,但根據網站的指示,完整的職位只是答案。所以,我編輯了我最初發布的代碼問題。
下面是真正的肉。現在,一旦我通過這一點,我從服務器獲得消息[],並將大小打印到控制檯。
SSL/TLS安全性是必需的,所以它在下面啓用。在這個例子中,證書由Java中的可信密鑰庫管理。
private Folder folder;
private Session session;
private Store store;
public boolean connectToKerberosMail() {
if (folder != null && folder.isOpen()) {
return true;
}
Properties properties = new Properties();
properties.setProperty("mail.debug", "true");
properties.put("mail.imaps.connectiontimeout",600000);
properties.put("mail.imaps.timeout",601000);
properties.put("mail.imaps.fetchsize", 65000);
properties.put("mail.imaps.starttls.enable", "true");
properties.put("mail.imaps.starttls.required", "false");
properties.put("mail.imaps.sasl.enable","true");
properties.put("mail.imaps.sasl.mechanisms","GSSAPI");
properties.put("mail.imaps.sasl.authorizationid",<user>);
properties.put("mail.imaps.sasl.realm",<realm>);
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("java.security.krb5.realm",<realm>);
System.setProperty("java.security.krb5.kdc", <ip-address>);
System.setProperty("java.security.auth.login.config", "jaas.conf");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
try {
session = Session.getInstance(properties);
} catch (Exception e) {
session = null;
return false;
}
session.setDebug(true);
URLName url = new URLName("imaps", <host>, <port>, "", <user>, <pass>);
store = new IMAPSSLStore(session, url);
try {
store.connect();
} catch (Exception e) {
e.printStackTrace();
store = null;
session = null;
return false;
}
return openFolder();
}
我Jaas.conf檔案如下(票據緩存從收購的kinit):
com.sun.security.jgss.initiate {
com.sun.security.auth.module.Krb5LoginModule required
principal="<principal>"
ticketCache="<cache-path>"
doNotPrompt="true"
useTicketCache="true"
debug="true";
};
com.sun.security.jgss.accept {
com.sun.security.auth.module.Krb5LoginModule required
principal="<principal>"
ticketCache="<cache-path>"
doNotPrompt="true"
useTicketCache="true"
debug="true";
};
我最近張貼在這裏的產量,但發現我的一些屬性,其中指定「IMAP」而不是「imaps」。因此,在posintg輸出將其更改之前,我正在進行更多測試。
在此期間,我有什麼正確的?從我的理解,我必須啓用imap的imap連接,啓動TLS的TLS/SSL,和sasl kerberos。但也許有什麼東西壓倒另一個?
文檔狀態通過選擇GSSAPI機制可以使用Kerberos,並且上述sasl屬性位於IMAP api中,這需要諸如Kerberos等領域所需的東西。 我成功地運行了一個使用明確的用戶名和密碼直接連接到郵件服務器(IMAP)的javamail客戶端。我還成功地重定向連接到Kerberos服務器,以請求[有用的博客]票(http://thejavamonkey.blogspot.com/2008/04/clientserver-hello-world-in-kerberos.html)。 所以所有的peices似乎都存在,但我不知道如何連接它們。 – amirsk 2012-02-22 06:51:00
同樣,協議跟蹤顯示了什麼? – 2012-02-22 20:34:04
找出Javamail和Kerberos的解決方案!我計劃在這裏爲每個搜索代碼示例的人發佈信息。但是在我的解決方案完成之前,我有最後一個問題。我必須通過SSL與Kerberos一起工作。所以我使用IMAPSSLStore。但是URLName需要用戶名和密碼。當我提供它時,Javamail從Kerberos獲取票據並使用它來聯繫IMAP服務器。 問題依然存在,我需要單點登錄,用戶永遠不必提供用戶/密碼。但IMAPSSLStore需要它們並引發異常。 如何用javamail實現單點登錄? – amirsk 2012-02-26 12:05:24