通过 Kerberos 使用 Active Directory 进行身份验证

发布于 2024-12-09 08:14:42 字数 603 浏览 0 评论 0原文

我正在构建一个需要不同级别身份验证的 Android 应用程序,并且我想使用 Active Directory 来实现这一点。

据我所知,使用 Kerberos 是 Microsoft 建议的方式。对于 Android,我该如何执行此操作?我看到 javax.security.auth doc,但它并没有告诉我太多。

我还在某处看到一条注释,指出 Kerberos 不包含用户组 - 这是真的吗?在这种情况下,我是否还必须以某种方式结合 LDAP?

编辑

这里的主要目标是实现与活动目录的 LDAP 连接,以便进行身份验证并为用户提供企业 Android 应用程序的正确权限。这里真正的障碍是 Google 在移植到 Android 时遗漏了许多 Java Web 服务 API。 (即javax.naming)此外,Android jar 中的许多连接机制似乎只作为遗留代码包含在内,实际上它们实际上什么也不做。

I'm working on building an android application which requires different levels of authentication, and I would like to do so using Active Directory.

From what I've read, using Kerberos is the way Microsoft suggests. How do I do this for Android? I see the javax.security.auth doc, but it doesn't tell me too much.

I also saw a note somewhere that Kerberos does not contain user groups - is this true? In that case, would I have to somehow combine LDAP as well?

EDIT

The main goal here is achieving an LDAP connection to the active directory in order to authenticate and give the user correct permissions for the enterprise Android application. The real barrier here is the fact that Google left out many of the Java Web Services API from it's port to android. (i.e. javax.naming) Also, many of the connection mechanisms in the Android jar seem to be only included as legacy code, and they in fact actually do nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

前事休说 2024-12-16 08:14:42

为此,您可能最好完全留在 LDAP 中,而不要冒险进入 kerberos。 Kerberos 为您提供了单点登录的优势,但由于您的 Android 应用程序没有任何凭据,因此它并不能真正帮助您。我猜谷歌有他们自己的理由不将 javax.naming 包含到发行版中。这是相当重的东西。

您可以自己从 java 运行时库源移植这些内容,或者最好使用本机 LDAP 库。例如这个一个

请记住使用安全 LDAP 连接或至少使用安全身份验证方法。有关此内容的详细信息请参见此处

For that you might be better off just staying completely within LDAP and don't venture into the kerberos. Kerberos gives you advantage of Single Sign On, but since your android app doesn't have any credentials already in place it doesn't really help you. I guess google had their own reasons not to include the javax.naming into the distro. It is pretty heavy stuff.

You might be able to either port the stuff yourself from java runtime library sources, or might be better off using native LDAP library. For example this one.

Just remember to use secure LDAP connection or at least secure authentication method. More info about this is here.

樱&纷飞 2024-12-16 08:14:42

我发现此处的文档非常有用,当我正在编写我的代码以通过我的 Kerberos 服务器进行身份验证。以下是我如何使用我的 kerberos 服务器进行身份验证,但您可能需要对其进行调整(因此我包括链接):

public static final int REGISTRATION_TIMEOUT = 30 * 1000; // ms

private static DefaultHttpClient httpClient;

private static final AuthScope SERVER_AUTH_SCOPE =
    new AuthScope("urls to kerberos server", AuthScope.ANY_PORT);


public static DefaultHttpClient getHttpClient(){
    if(httpClient == null){
      httpClient = new DefaultHttpClient();
      final HttpParams params = httpClient.getParams();
      HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
      HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
      ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);
    }
    return httpClient;
  }

  public static boolean authenticate(String username, String password)
  {

    UsernamePasswordCredentials creds =
      new UsernamePasswordCredentials(username, password);
    DefaultHttpClient client = getHttpClient();
    client.getCredentialsProvider().setCredentials(SERVER_AUTH_SCOPE, creds);

    boolean authWorked = false;
    try{
      HttpGet get = new HttpGet(AUTH_URI);
      HttpResponse resp = client.execute(get);
      authWorked = resp.getStatusLine().getStatusCode() != 403
    }
    catch(IOException e){
      Log.e("TAG", "IOException exceptions");
      //TODO maybe do something?
    }
    return authWorked;
  }

I found the documentation here to be really useful when I was writing my code to authenticate with my Kerberos server. Here's how I authenticate with my kerberos server, but you might need to tweak it for yours (hence me including the link):

public static final int REGISTRATION_TIMEOUT = 30 * 1000; // ms

private static DefaultHttpClient httpClient;

private static final AuthScope SERVER_AUTH_SCOPE =
    new AuthScope("urls to kerberos server", AuthScope.ANY_PORT);


public static DefaultHttpClient getHttpClient(){
    if(httpClient == null){
      httpClient = new DefaultHttpClient();
      final HttpParams params = httpClient.getParams();
      HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
      HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT);
      ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT);
    }
    return httpClient;
  }

  public static boolean authenticate(String username, String password)
  {

    UsernamePasswordCredentials creds =
      new UsernamePasswordCredentials(username, password);
    DefaultHttpClient client = getHttpClient();
    client.getCredentialsProvider().setCredentials(SERVER_AUTH_SCOPE, creds);

    boolean authWorked = false;
    try{
      HttpGet get = new HttpGet(AUTH_URI);
      HttpResponse resp = client.execute(get);
      authWorked = resp.getStatusLine().getStatusCode() != 403
    }
    catch(IOException e){
      Log.e("TAG", "IOException exceptions");
      //TODO maybe do something?
    }
    return authWorked;
  }
傲性难收 2024-12-16 08:14:42

您是否考虑过使用JCIFS?基于这些问题 [1] [2]此网站,JCIFS 在 Android 下运行。 JCIFS 站点有一个简单的 NTLM 身份验证器示例,可以帮助您入门。但是,根据此 Samba 列表消息,您将需要使用 LDAP 和自定义代码来获取用户组。

Have you looked at using JCIFS? Based on these questions [1] [2] and this site, JCIFS works under Android. The JCIFS site has a simple NTLM Authenticator example that could help get you started. However, based on this Samba list message, you will need to use LDAP and custom code to get the user's groups.

苍风燃霜 2024-12-16 08:14:42

尝试来自 Oracle 的教程。我的代码就像一个魅力。希望一切都包含在 Android 的 VM 发行版中。

Try this tutorial from Oracle. My code likes a charm. Hopefully everything is included in Android's VM distro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文