on liberty服务器

juzqafwq  于 2021-06-03  发布在  Java
关注(0)|答案(3)|浏览(374)

我想使用java在WebSphereLiberty服务器上实现单点登录。我想使用ldap对用户进行身份验证。
我找了很多,但找不到确切的例子。我也检查了每个可用的堆栈溢出示例。但运气不好。
如果有人能提供相同的演示或示例代码,那就太好了。
提前谢谢。
更新:我在华夫饼的帮助下实现了同样的功能。。但是waffle不适用于linux/unix。。有人能帮我吗?

mf98qq94

mf98qq941#

专门用于windows。单点登录可以通过使用华夫饼来完成。
对于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,其server.xml需要修改。

9q78igpj

9q78igpj2#

华夫饼剂量支持*尼克斯。您可以使用jass(仅限于javase8)并支持krb5loginmodule,它将允许您缓存操作系统票证。

w1e3prcc

w1e3prcc3#

如果您使用的是ldap,则可以像basic一样传递身份验证。如果您知道用户名和密码,请在标题“authorization”后面附加值“basic base64\u token”。
base64令牌是一个字符串,它是用您的用户名和密码按以下格式进行base64编码的username:password. 理想情况下,这应该是可行的。如果不行就告诉我。在这种情况下,我们可以使用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
  }
}

相关问题