【问题标题】:How to use WAFFLE for SSO using stand alone java client如何使用独立的 Java 客户端将 WAFFLE 用于 SSO
【发布时间】:2015-04-21 07:16:59
【问题描述】:

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

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

【问题讨论】:

    标签: java kerberos jaas waffle kerberos-delegation


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      以下是在不使用服务器的情况下使用 Waffle 为独立 Java 客户端执行单点登录的步骤。

      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();
          }
        }
      }
      

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • Webapp 中的System.getProperty(“user.name”) 将给出运行该webapp 的用户的用户名。
        猜你喜欢
        • 2017-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-09
        • 2011-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多