我的任务是为我公司的应用程序创建 SSO(单点登录)。我刚从大学毕业,所以对这里的大部分事情仍然很新鲜。我做了很多研究,我并不完全了解所有这些,但我正在尽我所能。所以我所处的场景是,我有一个 Windows Java 应用程序(Swing)(不是基于 WEB 的应用程序)和一个基于 LINUX 的服务器。两者都可以访问相同的 Active Directory (AD)。我需要验证客户所说的是谁。我试图同时使用 Kerberos 和 WAFFLE 都无济于事。Kerberos 有零有用的代码示例或在线信息,甚至可以开始尝试使用这种形式的身份验证。WAFFLE 我已经设置但不能使用,因为它需要一个 Windows 服务器,而我的是 LINUX。
我想要做的是将当前登录的 Windows 用户与令牌一起发送到服务器,服务器在活动目录中进行查找以查看用户名和令牌是否匹配。如果他们这样做了,那么您就可以登录了。这可能吗?在 AD 中是否存在这样的事情?Kerberos 令牌是否存储在 AD 中?如果是这样,我是否能够访问这样的令牌以发送到服务器进行身份验证?SSPI 令牌是否存储在那里,因为这就是我工作的这个 WAFFLE 代码似乎正在使用的东西,但我无法找到如何在 AD 中查询这样的令牌。
在以下代码中,WAFFLE 使用 SSPI 进行一些身份验证。我不完全理解它是如何工作的,但我想看看我是否可以将它在此处使用的令牌发送到 LINUX 服务器以在 AD 中查找以检查它是否有效,但它似乎不是存储的东西在公元。
任何帮助是极大的赞赏。
private void negotiate() {
IWindowsSecurityContext clientContext = WindowsSecurityContextImpl.getCurrent( "NTLM", "localhost" );
String securityPackage = "Kerberos";
int count = 0;
// initialize a security context on the client
clientContext = WindowsSecurityContextImpl.getCurrent( securityPackage, clientContext.getPrincipalName() );
// create an auth provider and a security context for the client
// on the server
WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
// now you would send the byte[] token to the server and the server will
// response with another byte[] token, which the client needs to answer again
IWindowsSecurityContext serverContext = null;
// Step 1: accept the token on the server and build a security context
// representing the client on the server
byte[] tokenForTheServerOnTheClient = clientContext.getToken();
serverContext = provider.acceptSecurityToken("server-connection", tokenForTheServerOnTheClient, securityPackage);
do {
count++;
// Step 2: If you have already build an initial security context for the client
// on the server, send a token back to the client, which the client needs to
// accept and send back to the server again (a handshake)
if (serverContext != null) {
byte[] tokenForTheClientOnTheServer = serverContext.getToken();
SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, tokenForTheClientOnTheServer);
clientContext.initialize(clientContext.getHandle(), continueToken, clientContext.getPrincipalName());
System.out.println(tokenForTheClientOnTheServer);
}
tokenForTheServerOnTheClient = clientContext.getToken();
serverContext = provider.acceptSecurityToken("server-connection", tokenForTheServerOnTheClient, securityPackage);
} while (clientContext.isContinue() && count < 5);
if(count >= 5) {
System.out.println("Unable to authenticate the user.");
}else {
// at the end of this handshake, we know on the server side who the
// client is, only by exchanging byte[] arrays
System.out.println(serverContext.getIdentity().getFqn());
}
}