Retrieve object add in JAAS login module from JSF managedbean

那年仲夏 提交于 2020-01-07 04:51:27

问题


Our application uses JSF 2.2 and use glassfish 4 as the server. I need to add some object in the login module during authenticate user, so in the web application, the managed bean can retrieve that object.

In the loginModule I did the following (if it is not the case please tell me the right way to do):

_subject.getPublicCredentials().add(someObject); 

But how can I retrieve it in ManagedBean. Any help will be much appreciated.


回答1:


This is part of the JSR-115 specification JavaTM Authorization Contract for Containers. See section 4.6.1.1 Container Subject Policy Context Handler:

4.6.1.1 Container Subject Policy Context Handler

All EJB and Servlet containers must register a PolicyContextHandler whose getContext method returns a javax.security.auth.Subject object when invoked with the key “javax.security.auth.Subject.container”.

In your application, you can retrieve the object through the following commands:

import javax.security.jacc.PolicyContext;
Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");

Note: the class should be added in get[Private|Public]Credentials() (with no args). The get[Public|Private]Credentials(Class<T>.class) generates a copy of the content, "filtering" the classes that are instances of the argument, serving only to retrieve saved classes.

Note: Not tested on JBoss, but I think it applies in the same way, based on JBoss Doc.


References:

  • JSR-115 Java Authorization Contract for Containers (Maintenance Release 3)
  • Arjan Tijms' Weblog


来源:https://stackoverflow.com/questions/27271121/retrieve-object-add-in-jaas-login-module-from-jsf-managedbean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!