可以从自定义Java servlet内的JSESSIONID中提取Maximo用户名吗?

huangapple go评论145阅读模式
英文:

Is there a way to extract Maximo username from JSESSIONID inside of a custom Java servlet?

问题

我正在Maximo内创建一个自定义的Java servlet。我想要利用Maximo的身份验证,并作为其中的一部分,我需要一种从HttpServletRequest对象中检索用户信息(用户名、显示名称等)的方法。我可以从请求的cookie中访问JSESSIONID(据我了解,这是Maximo/WebSphere用来跟踪用户会话的方式),但我还没有找到一种使用它来检索UserInfo对象的方法。

我已经仔细查阅了Javadocs,试图找到解决方法,但没有成功。似乎如今Maximo中的Java自定义相当罕见,因此没有太多资源可以帮助解决这个问题。

英文:

I am creating a custom Java servlet inside of Maximo. I want to piggyback off of Maximo's authentication and as a part of that I need some way of retrieving the user info (user name, display name, etc.) from the HttpServletRequest object. I am able to access the JSESSIONID from the request cookies (which as I understand it is how Maximo/WebSphere keeps track of your user session), but I have not been able to find a way to use that to retrieve the UserInfo object.

I have scoured the Javadocs trying to figure something out but have had no luck. It seems like Java customizations in Maximo are pretty rare nowadays so there are not many resources to figure this one out.

答案1

得分: 2

你尝试过 psdi.webclient.system.session.WebClientSessionManager.getWebClientSessionManager(javax.servlet.http.HttpSession session).getWebClientSession(javax.servlet.http.HttpServletRequest request) 吗?

英文:

Have you tried psdi.webclient.system.session.WebClientSessionManager.getWebClientSessionManager(javax.servlet.http.HttpSession session).getWebClientSession(javax.servlet.http.HttpServletRequest request) ?

答案2

得分: 2

已在查阅Javadocs后解决了这个问题。原来我可以按照以下方式从请求会话对象中获取MXSession:

Enumeration e = req.getSession().getAttributeNames();
String username = null;
while (e.hasMoreElements()) {
String attrName = (String) e.nextElement();
if (attrName.equals("MXSession")) {
  MXSession session = (MXSession) req
    .getSession()
    .getAttribute("MXSession");
  UserInfo user = session.getUserInfo();
  if (user != null) {
    username = user.getUserName().toLowerCase();
  }
}

Preacher的示例也有效,但仅在存在活动的WebclientSession时才有效。对于我的特定用例,我希望它也在只有OslcSession但不总是有关联的WebclientSession的情况下工作。这个解决方案在任何情况下都有效,因为MXSession始终可用。

英文:

Got this figured out after some digging in the Javadocs. Turns out I can pull the MXSession off of the request session object as follows:

Enumeration e = req.getSession().getAttributeNames();
String username = null;
while (e.hasMoreElements()) {
String attrName = (String) e.nextElement();
if (attrName.equals("MXSession")) {
  MXSession session = (MXSession) req
    .getSession()
    .getAttribute("MXSession");
  UserInfo user = session.getUserInfo();
  if (user != null) {
    username = user.getUserName().toLowerCase();
  }
}

Preacher's example also works, but only if there is an active WebclientSession, and for my particular use case, I want it to also work if there is only an OslcSession, which doesn't always have an associated WebclientSession. This solution works in either case, since the MXSession is always available.

huangapple
  • 本文由 发表于 2020年8月4日 06:05:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63237557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定