4 Replies Latest reply on Jul 27, 2011 5:06 PM by smurfs.smurfsturf.googlemail.com

    Custom Credentials in Seam 3

    jmonteiro

      Hi, is there any way to customize seam 3 credentials object?


      I need to add one more attribute to credentials (captcha). I tryed the following code:




      @Named("credentials") @SessionScoped
      public class Credentials extends CredentialsImpl {
           
           private static final long serialVersionUID = -4377742708407292709L;
           
           private String captcha;
      
           public String getCaptcha() {
                return captcha;
           }
      
           public void setCaptcha(String captcha) {
                this.captcha = captcha;
           }
      
      }



      But it has a conflict with org.jboss.seam.security.CredentialsImpl @Named annotation. How can i override the credentials.

        • 1. Re: Custom Credentials in Seam 3
          lightguard

          The short answer is you'll have to Veto it.


          The way to do that varies, you could create an extension to do it, I think you can also do it with Seam Config.


          This also seems like a bug, those classes should be the default if there isn't another one that satisfies the contract. Could you please add a JIRA (Arquillian test case preferred)?

          • 2. Re: Custom Credentials in Seam 3
            hantsy

            try add @Specializes to the bean, according to weld doc, it will override and replace the default bean at runtime.

            • 3. Re: Custom Credentials in Seam 3
              azakovorotny

              Hi Jorge,


              I use @Specialized version of the CredantialsImpl (as suggested by hantsy bay) and it works fine:




              @Inject Credentials credentials;
              
              String captcha = ((CustomCredentials) credentials.getCapture;
              



              • 4. Re: Custom Credentials in Seam 3
                smurfs.smurfsturf.googlemail.com

                You can also use @Alternative, as in...


                package com.example;
                
                @Alternative
                @Named("credentials")
                @SessionScoped
                public class MyCredentialsImpl extends CredentialsImpl {
                    //...implementation
                }
                


                and include the following in beans.xml


                <alternatives>
                    <class>com.example.MyCredentialsImpl</class>
                </alternatives>
                


                You may find you need to use this approach if you are running JBoss AS (I'm developing with AS 7). There is a known bug in Weld with the @Specializes annotation, specifically, deployment fails when the annotated class specialises a class in a different archive (as is the case with Seam Security). See https://issues.jboss.org/browse/WELD-912 for more info.