<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technotrance, Illusions and Perspectives &#187; seam-security</title>
	<atom:link href="http://myblog.shriharisc.com/tag/seam-security/feed/" rel="self" type="application/rss+xml" />
	<link>http://myblog.shriharisc.com</link>
	<description>A dose of everyday bruises with Java/JEE</description>
	<lastBuildDate>Mon, 02 Aug 2010 17:45:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Forking navigations based on user roles in JBoss Seam using Seam-Security</title>
		<link>http://myblog.shriharisc.com/2009/10/14/forking-navigations-based-on-user-roles-in-jboss-seam-using-seam-security/</link>
		<comments>http://myblog.shriharisc.com/2009/10/14/forking-navigations-based-on-user-roles-in-jboss-seam-using-seam-security/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 10:19:27 +0000</pubDate>
		<dc:creator>Shrihari</dc:creator>
				<category><![CDATA[jee-light]]></category>
		<category><![CDATA[jboss-seam]]></category>
		<category><![CDATA[seam-security]]></category>

		<guid isPermaLink="false">http://schakrap.wordpress.com/?p=130</guid>
		<description><![CDATA[This particular tip on loading different homepages for the role associated for a specific logged in user for a JSF web application written using JBoss Seam and identity management using Seam-Security. This tip assumes that a single user will be associated with a single role.
Assume we need to develop a course management JSF application which [...]]]></description>
			<content:encoded><![CDATA[<p>This particular tip on loading different homepages for the role associated for a specific logged in user for a JSF web application written using JBoss Seam and identity management using Seam-Security. This tip assumes that a single user will be associated with a single role.</p>
<p>Assume we need to develop a course management JSF application which supports users of 2 different roles : teacher and student. This means if a user with teacher role logs in teacher specific homepage should come  and student logging in should display student homepage. The following are steps to achieve this requirement.</p>
<p>1) Change WEB-INF/components.xml to include the seam-security authentication patterns</p>
<pre class="brush: xml">
  &lt;components xmlns=&quot;http://jboss.com/products/seam/components&quot;
          ....
          xmlns:security=&quot;http://jboss.com/products/seam/security&quot;
          xsi:schemaLocation=&quot;http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                ....
          &quot;&gt;
 ...
 &lt;security:identity authenticate-method=&quot;#{authenticator.authenticate}&quot;/&gt;
&lt;/components&gt;
</pre>
<p>2) Define an Authenticator action class with JBoss Seam component name &#8220;authenticator&#8221; and define an authenticate method inside</p>
<pre class="brush: java">
@Name(&quot;authenticator&quot;)
public class AuthenticatorAction
{   @In
    private Identity identity;
    @In(create=true)
    private AuthService service;

    ...
    @SuppressWarnings(&quot;deprecated&quot;)
    public boolean authenticate()
    {   String username = identity.getUsername();
        String password = identity.getPassword();
        if(username==null || password==null)
           return false;
        //authenticate the user from database
        User user = service.authenticate(username,password);
        // check user validity.
        identity.addRole(user.getRole());
        return true;
    }
}
</pre>
<p>3) Define the login portal widget in the login-page (say login.xhtml)</p>
<pre class="brush: xml">
&lt;ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
 .....
   &lt;h:panelGrid columns=&quot;2&quot; style=&quot;width:27px&quot;&gt;
      &lt;h:outputText value=&quot;Username: &quot;/&gt;
      &lt;h:inputText id=&quot;username&quot; value=&quot;#{identity.username}&quot; rows=&quot;1&quot; cols=&quot;12&quot;&gt;
         &lt;f:validateLength minimum=&quot;8&quot;  /&gt;
      &lt;/h:inputText&gt;
      &lt;h:outputText value=&quot;Password:&quot; rows=&quot;1&quot; cols=&quot;12&quot;/&gt;
      &lt;h:inputSecret id=&quot;password&quot; value=&quot;#{identity.password}&quot; /&gt;
   &lt;/h:panelGrid&gt;
   &lt;h:commandButton id=&quot;login&quot; action=&quot;#{identity.login}&quot; value=&quot;Login&quot;/&gt;
    ...
 &lt;/ui:composition&gt;
</pre>
<p>4) Wire the action outcomes to set up the navigation paths in WEB-INF/pages.xml</p>
<pre class="brush: xml">
&lt;pages xmlns=&quot;http://jboss.com/products/seam/pages&quot;
       ....
       no-conversation-view-id=&quot;/index.html&quot;&gt;

     &lt;page view-id=&quot;/login.xhtml&quot;&gt;
        &lt;navigation from-action=&quot;#{authenticator.checkLogin}&quot;&gt;
           &lt;rule if=&quot;#{identity.loggedIn and identity.role==&#039;Teacher&#039;}&quot;&gt;
               &lt;redirect view-id=&quot;/teacher/homepage.xhtml&quot; /&gt;
          &lt;/rule&gt;
       &lt;/navigation&gt;
       &lt;navigation from-action=&quot;#{identity.login}&quot;&gt;
           &lt;rule if=&quot;#{identity.loggedIn and identity.hasRole(&#039;Teacher&#039;)}&quot;&gt;
              &lt;redirect view-id=&quot;/teacher/homepage.xhtml&quot; /&gt;
          &lt;/rule&gt;
       &lt;/navigation&gt;
       &lt;navigation from-action=&quot;#{authenticator.checkLogin}&quot;&gt;
          &lt;rule if=&quot;#{identity.loggedIn and identity.role==&#039;Student&#039;}&quot;&gt;
               &lt;redirect view-id=&quot;/student/homepage.xhtml&quot; /&gt;
          &lt;/rule&gt;
       &lt;/navigation&gt;
       &lt;navigation from-action=&quot;#{identity.login}&quot;&gt;
           &lt;rule if=&quot;#{identity.loggedIn and identity.hasRole(&#039;Student&#039;)}&quot;&gt;
              &lt;redirect view-id=&quot;/student/homepage.xhtml&quot; /&gt;
          &lt;/rule&gt;
       &lt;/navigation&gt;
    &lt;/page&gt;
    ....
   &lt;exception&gt;
        &lt;redirect view-id=&quot;/index.xhtml&quot;&gt;
           &lt;message&gt;Please log in first&lt;/message&gt;
        &lt;/redirect&gt;
   &lt;/exception&gt;
&lt;/pages&gt;
</pre>
<p>You can extend this tip to come out of different other user-role combinations.</p>
]]></content:encoded>
			<wfw:commentRss>http://myblog.shriharisc.com/2009/10/14/forking-navigations-based-on-user-roles-in-jboss-seam-using-seam-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
