[JBoss Seam] - Help restrict access to pages before login
by rmemoria
Hi all,
I've upgraded SEAM from 1.1.5 to 1.1.6.
All I want is to restrict access to some pages before the user login (in this example, restrict access to /admin.xhtml page). This is my config
components.xml
<security:identity authenticate-method="#{authenticator.login}"/>
|
| <event type="org.jboss.seam.notLoggedIn">
| <action expression="#{redirect.captureCurrentView}"/>
| </event>
| <event type="org.jboss.seam.postAuthenticate">
| <action expression="#{redirect.returnToCapturedView}"/>
| </event>
|
pages.xml
<pages>
|
| <page view-id="/admin.xhtml" >
| <restrict />
| </page>
|
| <page view-id="*">
| <navigation>
| <rule if-outcome="home">
| <redirect view-id="/index.xhtml"/>
| </rule>
| </navigation>
| </page>
|
| <page view-id="/login.xhtml">
| <navigation from-action="#{identity.login}">
| <rule if-outcome="success">
| <redirect view-id="/index.xhtml"/>
| </rule>
| </navigation>
| </page>
|
| <exception class="javax.persistence.EntityNotFoundException">
| <redirect view-id="/error.xhtml">
| <message>Not found</message>
| </redirect>
| </exception>
|
| <exception class="javax.persistence.OptimisticLockException">
| <end-conversation/>
| <redirect view-id="/error.xhtml">
| <message>Another user changed the same data, please try again</message>
| </redirect>
| </exception>
|
| <exception class="org.jboss.seam.security.AuthorizationException">
| <redirect>
| <message>You don't have permission to do this</message>
| </redirect>
| </exception>
|
| <exception class="org.jboss.seam.security.NotLoggedInException">
| <redirect view-id="/pub/login.xhtml">
| <message>Please log in first</message>
| </redirect>
| </exception>
|
| <exception>
| <redirect view-id="/error.xhtml">
| <message>Unexpected error, please try again</message>
| </redirect>
| </exception>
|
| </pages>
and part of my login.xhtml
<tr><td colSpan="2"><h:messages styleClass="erro" layout="table"/> </td></tr>
| <tr>
| <td>#{messages.user_login}: </td>
| <td><h:inputText id="nome" value="#{identity.username}" ></h:inputText></td>
| </tr>
| <tr>
| <td>#{messages.password}: </td>
| <td><h:inputSecret value="#{identity.password}" /></td>
| </tr>
| <tr>
| <td></td>
| <td><h:commandButton id="btnOk" value="#{messages.enter}" action="#{identity.login}"></h:commandButton></td>
| </tr>
If I try to access /admin.xhtml before login, the system redirects to /login.xhtml. That's ok!
After a successful login nothing happens but if I check JBOSS console I see the same exception being raised in an infinite loop forcing me to stop the server:
18:08:04,765 ERROR [SeamPhaseListener] uncaught exception
| org.jboss.seam.security.AuthorizationException: Authorization check failed for expression [#{s:hasPermission('/admin.xhtml', 'render', null)}]
| at org.jboss.seam.security.Identity.checkRestriction(Identity.java:174)
| at org.jboss.seam.pages.Page.enter(Page.java:186)
| at org.jboss.seam.core.Pages.enterPage(Pages.java:239)
| at org.jboss.seam.jsf.AbstractSeamPhaseListener.enterPage(AbstractSeamPhaseListener.java:242)
| at org.jboss.seam.jsf.AbstractSeamPhaseListener.beforeRender(AbstractSeamPhaseListener.java:193)
| at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:57)
I guess the reason is the <restrict/ tag inside the /admin.xhtml page in pages.xml, but it was the only way I found to redirect to the login page if the user isn't logged.
Any help????
Ricardo Memória
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4015983#4015983
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4015983
19Â years, 2Â months
[JBoss Seam] - Re: seam-gen enhancement
by kentlam
This is the solution I have to get seam-gen to work on existing entities:
1) Either append the following target to the seam-gen/build.xml or just modify the generate-entities target:
| <target name="generate-domain" depends="validate-project"
| description="Generate based on existing domain entities">
|
| <taskdef name="hibernate"
| classname="org.hibernate.tool.ant.HibernateToolTask">
| <classpath>
| <fileset dir="lib">
| <include name="*.jar" />
| </fileset>
| <fileset dir="../hibernate/lib">
| <include name="*.jar" />
| </fileset>
| <pathelement path="${driver.jar}" />
| <pathelement path="../jboss-seam-gen.jar" />
| </classpath>
| </taskdef>
|
| <hibernate templatepath=".">
| <jpaconfiguration persistenceunit="testproject" />
| <classpath>
| <pathelement path="${project.home}/dist" />
| </classpath>
|
| <property key="hibernatetool.util.toolclass"
| value="org.jboss.seam.tool.Util" />
|
| <hbmtemplate filepattern="{class-name}List.xhtml"
| template="view/list.xhtml.ftl"
| destdir="${project.home}/view" />
| <hbmtemplate filepattern="{class-name}.xhtml"
| template="view/view.xhtml.ftl"
| destdir="${project.home}/view" />
| <hbmtemplate filepattern="{class-name}.page.xml"
| template="view/view.page.xml.ftl"
| destdir="${project.home}/view" />
| <hbmtemplate filepattern="{class-name}Edit.xhtml"
| template="view/edit.xhtml.ftl"
| destdir="${project.home}/view" />
| <hbmtemplate filepattern="{class-name}Edit.page.xml"
| template="view/edit.page.xml.ftl"
| destdir="${project.home}/view" />
| <hbmtemplate filepattern="{package-name}/{class-name}List.java"
| template="src/EntityList.java.ftl"
| destdir="${project.home}/src" />
| <hbmtemplate filepattern="{class-name}List.page.xml"
| template="view/list.page.xml.ftl"
| destdir="${project.home}/view" />
| <hbmtemplate filepattern="{package-name}/{class-name}Home.java"
| template="src/EntityHome.java.ftl"
| destdir="${project.home}/src" />
| <hbmtemplate filepattern="menu.xhtml"
| template="view/layout/menu.xhtml.ftl"
| destdir="${project.home}/view/layout" />
| </hibernate>
|
| <taskdef name="javaformatter"
| classname="org.hibernate.tool.ant.JavaFormatterTask">
| <classpath>
| <fileset dir="lib">
| <include name="*.jar" />
| </fileset>
| </classpath>
| </taskdef>
|
| <javaformatter>
| <fileset dir="${project.home}/src">
| <include name="**/*.java" />
| </fileset>
| </javaformatter>
|
| <echo
| message="Type 'seam restart' and go to http://localhost:8080/${project.name}" />
|
| </target>
|
2) Run 'seam setup' and 'seam new-project' to generate the project skeleton
3) create a 'dist' directory under the newly created project directory
4) copy all your compiled classes for the domain model into the 'dist' directory
5) copy all your src code for the domain model into the 'src' directory under the newly created project directory
6) create a META-INF directory inside 'dist' directory
7) copy the persistence-dev.xml from the resources directory in the newly created project to the dist/META-INF directory and rename it to persistence.xml
8) Now change the persistenceunit under <jpaconfiguration .../> in the seam-gen/build.xml to match the persistentunit in the persistence.xml
9) download the put the javassist.jar into your [Seam installation dir]/hibernate/lib directory
10) run seam generate-domain (or seam generate-entities if you modify the ant target)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4015981#4015981
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4015981
19Â years, 2Â months
[JBoss Seam] - Rules and navigation
by Stateless Bean
Hi all,
I'm newbie in seam...
I want to use drools and rules in my seam pages but i dont understand how and where are used those roles.
can anyone give me link or post me litle example how to use those drools?
On doc files i found somethink like this:
| <page view-id="/editDocument.xhtml">
|
| <navigation from-action="#{documentEditor.update}">
| <rule if="#{documentEditor.errors.empty}">
| <end-conversation/>
| <render view-id="/viewDocument.xhtml"/>
| <rule/>
| </navigation-case>
|
| </navigation-rule>
|
if my undestanding is well here we use rule, but what how? and where is "name" of those rule?
I understand little bit rules but i still have problems with implementation in code and don't know where are they used (in source code) and in with cases.
Stateless Bean
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4015979#4015979
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4015979
19Â years, 2Â months