我想用Java在Websphere-Liberty服务器上实现单点登录。我想使用LDAP对用户进行身份验证。
我搜索了很多,但找不到确切的例子。我也检查了堆栈溢出的每个可用示例。但没那么走运。
如果能提供同样的演示或示例代码,那就太好了。
提前谢谢。
更新:在waffle的帮助下,我实现了同样的功能。但是华夫乐不能在Linux/Unix上工作。。。有谁能帮帮我吗?
发布于 2017-11-03 22:04:30
waffle不支持*nix。您可以在支持Krb5LoginModule的情况下使用JASS (仅限JavaSE8),它允许您缓存操作系统票证。
发布于 2017-09-25 17:37:01
如果您使用的是LDAP,则可以像Basic一样通过身份验证。如果您知道用户名和密码,请在头部Authorization后面加上值Basic base64_token。
base64令牌是一个使用用户名和密码进行base64编码的字符串,格式为用户名:密码。理想情况下,这应该是可行的。如果它不起作用,请告诉我。在这种情况下,我们可以使用SPNEGO探索选项。
JAVA中LDAP的代码:
public class Main
{
public static void main(String[] args)
{
//Replace username and password with your username and password
token = Base64.getEncoder().encodeToString((username + ":" + password).getBytes())
conn = (HttpURLConnection) endpoint.openConnection();
// Set the necessary header fields, which in this case is Basic
conn.addRequestProperty("Authorization", "Basic " + token);
//Continue to do what you want to do after this. This should authenticate
// you to the server
}
}发布于 2017-10-26 12:57:04
特别适用于windows。单点登录可以通过使用waffle来完成。
对于Ldap身份验证,您可以使用spring mvc转到简单的java类,代码行如下:
String username = login.getUsername();// "ancb";
String password = login.getPassword();// "*****";
String base = "OU=******,DC=InfoDir,DC=DEV,DC=****";
String dn = "CN=" + username + "," + base;
String ldapURL = "ldaps://****.systems.**.****:3269";
// Setup environment for authenticating
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, ldapURL);
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, dn);
environment.put(Context.SECURITY_CREDENTIALS, password);
String dynamicLdapaccount = "(CN="+ username +")" ;
DirContext authContext = new InitialDirContext(environment);对于单点登录:
您需要在服务器级别设置Kerberos和Spnego配置。对于liberty服务器,它的server.xml需要修改。
https://stackoverflow.com/questions/46035255
复制相似问题