【发布时间】:2017-11-22 04:56:22
【问题描述】:
我是一位经验丰富的 Java 开发人员(4 到 5 年),但对 Azure AD 及其功能不熟悉,因此对于一个潜在的基本问题,我提前道歉。我一直在努力在 Java 中找到任何涵盖该主题的 Microsoft 文档或 Stack Overflow 问题(绝大多数都在 C# 中),据我了解,C# 比 Java 拥有更多的 Azure AD 库,因此 C# 中的解决方案不一定是解决方案Java。
我正在尝试根据一个场景完成身份验证 POC,其中有一个现有的 Azure AD 系统,其中满是用户,我想将其用作身份验证点。我的 Java 应用程序将收集用户的用户名和密码(我知道这是不推荐使用且不理想的,但出于遗留原因需要)并使用 Microsoft adal4j 库调用 Azure 端点,我可以成功返回 JWC 访问令牌(除了刷新和 ID 令牌)。
这是我现有的用于检索 JWC 访问令牌的代码 sn-p。
private static AuthenticationResult getAccessTokenFromUserCredentials(String username, String password, String
AUTHORITY, String CLIENT_ID) throws Exception {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
Future<AuthenticationResult> future = context.acquireToken(
"https://graph.windows.net", CLIENT_ID, username, password,
null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
System.out.println("ex)");
}
return result;
}
public void azureAuthenticate(String authority, String clientID, String username, String password){
AuthenticationResult result = null;
try {
result = getAccessTokenFromUserCredentials(username, password, authority, clientID);
DecodedJWT accessToken = JWT.decode(result.getAccessToken());
//Want to verify the validity of this access token
} catch (Exception ex) {
ex.printStackTrace();
}
}
我的代码主要基于这个Microsoft documentation
收到令牌后,我需要能够验证其真实性(我了解确认其声明的业务逻辑方面,但我对如何验证签名是否合法感到困惑)。
提前感谢您的帮助,我很乐意提供任何所需的说明。
【问题讨论】:
标签: java azure active-directory azure-active-directory azure-ad-graph-api