【发布时间】:2021-05-11 19:38:44
【问题描述】:
我正在尝试使用 openidconnect 方法将 azure ad 集成到 Java Web 应用程序中。我的 Web 应用程序部署在 weblogic 应用程序服务器上。
我使用的基本代码来自 microsoft github repo:Link
集成后,我能够将我的登录页面重定向到 Microsoft 登录页面,输入凭据,然后当 Microsoft 重定向回我的登录页面时,它会降落在控制器下方,这是我的重定向回复 URL,这里是结果对象 (AuthenticationResult ) 一片空白。会话对象似乎没有称为“原则”的属性。我不确定我哪里出错了,谁能指出我正确的方向?
@Controller
@RequestMapping("/jsp/MyClientControllerServlet")
public class AadController {
private static Logger logger = Logger.getLogger(AadController.class);
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public String getDirectoryObjects(ModelMap model, HttpServletRequest httpRequest) {
logger.info("Starting getDirectoryObjects");
HttpSession session = httpRequest.getSession();
logger.info("session: "+session);
//The principle session name variable has the string 'principle'.
//I am not sure if this is a static attribute that applies to all applications.
//I guess this attribute is not available on my HttpSession which is why my AuthenticationResult is null
AuthenticationResult result = (AuthenticationResult) session.getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME);
if (result == null) {
model.addAttribute("error", new Exception("AuthenticationResult not found in session."));
return "/error";
} else {
System.out.println("Login session success");
更新 #1:我尝试通过枚举来打印 HttpSession 的内容,但我发现它只有一个名为“states”的属性,它也是空的。
来自我的日志:
INFO BasicFilter:81 - doFilter
INFO BasicFilter:134 - processAuthenticationData
INFO AuthenticationAuthority:149 - [Correlation ID: 546546454-18e3-499e-8cc9-0ABCDf3a3584] Instance discovery was successful
DEBUG DispatcherServlet:693 - DispatcherServlet with name 'mvc-dispatcher' processing POST request for [/myPortal/jsp/MyClientControllerServlet]
DEBUG DefaultAnnotationHandlerMapping:221 - Mapping [/jsp/MyClientControllerServlet] to HandlerExecutionChain with handler [com.microsoft.aad.adal4jsample.AadController@50f6da2b] and 2 interceptors
DEBUG HandlerMethodInvoker:173 - Invoking request handler method: public java.lang.String com.microsoft.aad.adal4jsample.AadController.getDirectoryObjects(org.springframework.ui.ModelMap,javax.servlet.http.HttpServletRequest)
INFO AadController:54 - Starting getDirectoryObjects
INFO AadController:56 - session: weblogic.servlet.internal.session.MemorySessionData@17d119dd
INFO AadController:61 - states : {}
更新 #2: 我尝试通过枚举来打印 HttpServletRequest 对象的属性,其中一个属性称为 error 具有此值。
INFO AadController:81 - error : com/nimbusds/jose/shaded/json/parser/ParseException
【问题讨论】:
-
您使用的是哪个样本? github.com/Azure-Samples/… 还是 github.com/Azure-Samples/ms-identity-java-webapp/tree/master/…?并请提供更多错误信息。当应用 Microsoft 重定向回您的页面时可以看到什么?
-
嗨,艾伦,我正在使用来自 github.com/Azure-Samples/… 的样本。当微软重定向回我的页面时,在 UI 端我看到以下消息:[错误页面! com/nimbusds/jose/shaded/json/parser/ParseException Home Page] 日志没有显示堆栈跟踪或错误,只是说结果为空(AuthenticationResult result = (AuthenticationResult) session.getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME); )并尝试显示显示上述消息的 error.jsp 文件。
标签: java azure azure-active-directory adal