如何使用独立的Java客户端使用WAFFLE进行SSO

时间:2015-04-21 07:16:59

标签: java kerberos jaas waffle kerberos-delegation

我们正在尝试使用带有JAAS的独立Java客户端将WAFFLE用于SSO。我们在jaas.conf中提到了waffle.jaas.WindowsLoginModule,但它提示输入用户名,密码,我们认为这不是SSO的理想解决方案。任何人都可以建议如何避免这种情况吗?

仅供参考 - 我们没有使用任何网络/应用服务器。

3 个答案:

答案 0 :(得分:1)

我相信你需要SSO的服务器和客户端。您可以查看this example,它不使用登录模块,而是使用WAFFLE中包含的基础WindowsSecurityContext类来来回传递kerberos令牌以获取登录用户。

答案 1 :(得分:0)

下面是在不使用服务器的情况下使用Waffle for独立Java Client进行单点登录的步骤。

  1. 创建客户端凭据
  2. 使用WindowsSecurityContextImpl的initializeSecurityContext获取服务票证。
  3. 使用WindowsAuthProviderImpl的accessSecurityContext获取WindowsIdentity

原始链接https://exceptionshub.com/getting-kerberos-service-ticket-using-waffle-in-java.html

对于客户端-服务器sso,您应遵循https://code.dblock.org/2010/04/08/pure-java-waffle.html 下面的代码描述了使用kerberos的独立Java sso。

import com.sun.jna.platform.win32.Sspi;
import waffle.windows.auth.IWindowsCredentialsHandle;
import waffle.windows.auth.IWindowsIdentity;
import waffle.windows.auth.IWindowsSecurityContext;
import waffle.windows.auth.impl.WindowsAccountImpl;
import waffle.windows.auth.impl.WindowsAuthProviderImpl;
import waffle.windows.auth.impl.WindowsCredentialsHandleImpl;
import waffle.windows.auth.impl.WindowsSecurityContextImpl;

public class KerberosSingleSignOn {
  public static void main() {
    try {
      System.out.println(getWindowsIdentity().getFqn());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static IWindowsIdentity getWindowsIdentity() throws Exception {
    try {
      byte[] kerberosToken = getServiceTicketSSPI();
      WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
      IWindowsSecurityContext securityContext = provider
        .acceptSecurityToken("client-connection", kerberosToken, "Kerberos");
      return securityContext.getIdentity();
    }
    catch (Exception e) {
      throw new Exception("Failed to process kerberos token");
    }
  }

  public static byte[] getServiceTicketSSPI() throws Exception {
    final String securityPackage = "Kerberos";
    IWindowsCredentialsHandle clientCredentials = null;
    WindowsSecurityContextImpl clientContext = null;
    final String currentUser = WindowsAccountImpl.getCurrentUsername();
    try {
      clientCredentials = WindowsCredentialsHandleImpl.getCurrent(securityPackage);
      clientCredentials.initialize();
      // initial client security context
      clientContext = new WindowsSecurityContextImpl();
      clientContext.setCredentialsHandle(clientCredentials.getHandle());
      /*OR 
       clientContext.setCredentialsHandle(clientCredentials);
       */
      clientContext.setSecurityPackage(securityPackage);
      final Sspi.SecBufferDesc continueToken = null;
      do {
        System.out.println("Using current username: " + currentUser);
        clientContext.initialize(clientContext.getHandle(), continueToken, currentUser);
      }
      while (clientContext.isContinue());

      return clientContext.getToken();
    }
    catch (Exception e) {
      throw new Exception("Failed to process kerberos token");
    }
    finally {
      if (clientContext != null)
        clientContext.dispose();
      if (clientCredentials != null)
        clientCredentials.dispose();
    }
  }
}

答案 2 :(得分:-1)

而不是使用华夫饼干并使其变得复杂。您可以轻松使用System.getProperty(“user.name”)提供用户名。