1 2 3 Previous Next 44 Replies Latest reply on Feb 16, 2007 6:10 PM by shane.bryzak Go to original post
      • 30. Re: Seam Security

         

        "lightbulb432" wrote:
        When catching NotLoggedInException in exceptions.xml, I have a

        <redirect view-id="/login.xhtml">Not logged in</redirect>
        for the NotLoggedInException.

        While the redirect works correctly, the message "Not logged in" doesn't display in login.xhtml's
        <h:messages globalOnly="true" />


        Why won't this message appear?


        I spoke too soon when I said the above problem sorted itself out. The following does not work:

        <exception class="org.jboss.seam.NotLoggedInException">
         <redirect view-id="/login.xhtml">
         <message>Not logged in</message>
         </redirect>
        </exception>


        This does not appear in any case. Only for authorization exceptions (when the user doesn't have appropriate permissions) does the message appear. Keep in mind the redirect is working, however, and the login.xhtml does have an h:messages. Is this a bug in Seam?

        • 31. Re: Seam Security
          shane.bryzak

           

          "venkateshbr" wrote:
          does the seam security support multiple authentication modes in the same application such as Digital Certificate login and Username/Password login.


          There is no special support for X509 authentication as yet, although it's on the to-do list.

          • 32. Re: Seam Security
            shane.bryzak

             

            "lightbulb432" wrote:

            I spoke too soon when I said the above problem sorted itself out. The following does not work:

            <exception class="org.jboss.seam.NotLoggedInException">
             <redirect view-id="/login.xhtml">
             <message>Not logged in</message>
             </redirect>
            </exception>


            This does not appear in any case. Only for authorization exceptions (when the user doesn't have appropriate permissions) does the message appear. Keep in mind the redirect is working, however, and the login.xhtml does have an h:messages. Is this a bug in Seam?


            This is definitely working in the seamspace example in cvs. Navigating to the url http://localhost:8080/seam-space/comment.seam?name=Mr_Smiley&blogId=2 while not logged in will cause a redirect to the registration page, with the error message being displayed. You might like to compare the config files with your own to see if there's anything majorly different, otherwise if you post a working example to jira I'd be happy to look at it for you.


            • 33. Re: Seam Security

              I'll give it a shot, thanks.


              How would you use enums as roles added to the identity? Right now I'm using an enum but it expects strings, so instead of having a simple enum with just { ROLE1, ROLE2 }, I have to have a constructor and String property in the enum.

              I also must refer to it as myEnumEntry.getStringProperty() instead of just myEnumEntry. Is there any support for using enums as roles, or must I convert everything to a String before doing it?

              I figure enums could be a nice, clean, and simple way of doing this...? (An example of where enums are appropriate, no?)

              • 34. Re: Seam Security
                shane.bryzak

                I personally wouldn't use enums for roles - unless perhaps you're persisting user roles as enums. Of course there's no problem doing this, you just need to call Identity.addRole(myEnum.toString()) in your authenticator method. I could modify the addRole() method to accept an Object instead of a String, the only difference being that it would call toString() on whatever object you pass in.

                In the other areas of the security API, I can't really see any advantage doing this though, especially since the security expressions only work with string values anyway.

                • 35. Re: Seam Security
                  smurfs

                  I've had no problems implementing the latest authentication/authorisation security features thanks to the contributors to this thread :)

                  I now need to roll my own implementation of org.jboss.seam.security.Identity to include a third log-in form attribute called 'organisation'. This identifies the user as a member of a particular organisation, fulfilling one or more roles. I need to use this approach as the user could also be a member of one or more organisations with a totally different set of roles/permissions for each.

                  I have extended the Identity class to implement the additional attribute, however I am stuck when it comes to annotating MyIdentity class in such a way that Seam 'knows' this is the identity type to use. I have injected MyIdentity into the Authenticator implementation but get the following exception which indicates Seam is still looking at its' own version:

                  javax.faces.el.PropertyNotFoundException: /login.xhtml @45,84 value="#{identity.organisation}": Bean: org.jboss.seam.security.Identity, property: organisation

                  Can anyone point me in the right direction please?

                  Thanks Andrew

                  • 36. Re: Seam Security
                    pmuir

                    I use this:

                    @Name("org.jboss.seam.security.identity")
                    public class Identity extends org.jboss.seam.security.Identity {
                    
                    ...
                    
                     public static Identity instance() {
                     if ( !Contexts.isSessionContextActive() ) {
                     throw new IllegalStateException("No active session context");
                     }
                    
                     Identity instance = (Identity) Component.getInstance(Identity.class, ScopeType.SESSION, true);
                    
                     if (instance == null) {
                     throw new IllegalStateException("No Identity could be created");
                     }
                     return instance;
                     }
                    }


                    (Running from CVS from earlier this week)

                    • 37. Re: Seam Security
                      smurfs

                      Thanks for response Pete.

                      One problem I have run up against is the annotation @Name("org.jboss.seam.security.identity") is not unique - trying to use this in the derived class as per your code snippet throws "java.lang.IllegalStateException: Two components with the same name and precedence: org.jboss.seam.security.identity", which is what one would expect.

                      How have you overcome this (short of changing the parent Identity annotation in the source)?

                      • 38. Re: Seam Security

                        Your one should have application precedence (the default), the core one has the lower built in precedence.

                        From the source

                        @Name("org.jboss.seam.security.identity")
                        @Scope(SESSION)
                        @Install(precedence = BUILT_IN, classDependencies="org.drools.WorkingMemory")
                        


                        So if you define a component with the same name and leave the precedence as default it should prefer your component over the default one.

                        If you're getting a clash like that you are probably either specifying @Install( BUILT_IN ) by accident or have the component duplicated somewhere.

                        Cheers.

                        Mike.

                        • 39. Re: Seam Security
                          pmuir

                          You have <security:identity /> in your components.xml right? As Seam's Identity is not marked @Install(value=false) by putting that line in components.xml you end up creating an Identity component (which has APPLICATION precedence (as per the defaults)). So, what you in fact need to do, in components.xml, is to configure *your* Identity component rather than Seam's.

                          • 40. Re: Seam Security
                            smurfs

                            Pete, I had overlooked the extra attributes on the <security:identity /> tag that provide for a bespoke Identity so thank you for making me revisit this - I will amend my configuration.

                            Mike, thanks for your pointers. I actually got my Identity working by changing the precedence as per your suggestion.

                            Thank you both for your guidance (and patience).

                            • 41. Re: Seam Security

                              So to get it working, did you have the same @Name as the built-in component, @Scope of APPLICATION, and no @Install annotation?

                              Could you show what the line in your components.xml that you changed to get it working was? I'm about to start doing this, so your help would be greatly appreciated.

                              • 42. Re: Seam Security
                                smurfs

                                I've tried to apply the settings via the 'class' and 'precedence' attributes of the <security:identity .../> element but to no avail.

                                My implementation of Identity does work however with the following annotation - @Install(precedence = DEPLOYMENT). According to the javadocs this is the "precedence to use for components which override application components in a particular deployment". As this works for me I am not going to fiddle with my <security:identity .../> element any further, so if you get it working that way let us know.

                                For completeness I have included my code below. I hope this helps.

                                @Name("org.jboss.seam.security.identity")
                                @Scope(SESSION)
                                @Install(precedence = DEPLOYMENT)
                                public class Identity extends org.jboss.seam.security.Identity {
                                
                                 private static final long serialVersionUID = 3102222149672922155L;
                                
                                 private String organisation;
                                
                                 public static Identity instance() {
                                 if ( !Contexts.isSessionContextActive() ) {
                                 throw new IllegalStateException("No active session context");
                                 }
                                
                                 Identity instance =
                                 (Identity)Component.getInstance(Identity.class, ScopeType.SESSION, true);
                                
                                 if (instance == null) {
                                 throw new IllegalStateException("No Identity could be created");
                                 }
                                 return instance;
                                 }
                                
                                 public String getOrganisation() {
                                 return organisation;
                                 }
                                
                                 public void setOrganisation(String organisation) {
                                 setDirty(this.organisation, organisation);
                                 this.organisation = organisation;
                                 }
                                
                                }
                                


                                • 43. Re: Seam Security
                                  smurfs

                                  P.S. Components.xml remains unchanged i.e.

                                  <security:identity authenticate-method="#{authenticator.authenticate}"/>
                                  


                                  • 44. Re: Seam Security
                                    shane.bryzak

                                    If you're using your own Identity implementation you can't configure it with <security:identity ...> in components.xml, you need to add a <component class="com.mycustom.identity" ...> element instead.

                                    1 2 3 Previous Next