English 中文(简体)
三. 关于联邦法院授权的建议
原标题:Suggestion on JSF authorization
  • 时间:2011-08-12 08:44:39
  •  标签:
  • jsf

I learnt how to use container authentication with JDBC realm. I searched a lot on internet but I couldn t find anything on JSF authorization except the following article. JSF authorization

My goal is to avoid access to protected pages using direct links and to show/hide menu items and form components based on the authenticated user privileges. The last part can be implemented using the rendered attribute of JSF tags but before creating my own dirty and high coupled solution I wonder if there are some specific best practices or libraries that can help. in fact the number of components to be conditionally rendered is quite high and I wouldn t like to write a specific function for each of them. Perhaps I can create for each authenticated user a map with the names (id) of all the conditionally rendered components and a single function with a String parameter (the unique name/id of the component). Is that a good idea ? What alternatives do I have ? I wouldn t like to add to the project other general purpose frameworks such as spring for using only a small part of them (the security one).

Thanks Filippo

最佳回答

有了Java EE 6的表达语言版本,你就应当能够使用这些表达方式:

<h:inputText rendered="#{facesContext.externalContext.isUserInRole( foo )}" />

有了较老的版本,你就能够形成一种管理好的方式:

public class RoleMap implements Map<String, Boolean> {

    public Boolean get(Object key) {
        ExternalContext extCtxt = FacesContext.getCurrentInstance()
                                              .getExternalContext();
        return extCtxt.isUserInRole(key.toString());
    }

    //TODO: other methods; mostly throwing UnsupportedOperationException

试验可以表现为:

<h:inputText rendered="#{roleMap[ foo ]}" />

Third party frameworks offer other options, such as the Apache Tomahawk library s visibleOnUserRole component attributes.

问题回答

参看,Apache Shiro,这是一个专门的安全框架(而且据称是晚期使用的安保系统)。





相关问题
JSF a4j:support with h:selectManyCheckbox

I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

Mojarra for JSF Encoding

Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

如何拦截要求终止?

在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

ICEFaces inputFile getting the file content without upload

Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

How to correctly use ResultSet with h:dataTable

The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...

热门标签