You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by miro <mi...@yahoo.com> on 2008/12/04 21:25:10 UTC

using annotation @AuthorizeInstantiation

I am using this  @AuthorizeInstantiation   (wicket authetication annotation)
in my pages , the code for this annotation

@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.PACKAGE, ElementType.TYPE })
@Documented
@Inherited
public @interface AuthorizeInstantiation {

	/**
	 * Gets the roles that are allowed to take the action.
	 * 
	 * @return the roles that are allowed. Returns a zero length array by
default
	 */
	String[] value() default {};
}


I created my enum with representing authorities

public enum  Authorities {
	
	LIASION_OFFICER,
	GRANTS_OFFICER,
	PROGRAM_ANALYST,
	ADMIN;

}

I am trying to use  AuthorizeInstantiation   in my page  here an example 

@AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
public class HomePage extends BasePage {


this line does not compile, I get the error 

The value of annotation attribute AuthorizeInstantiation .value must be a
constant expression  .please help me resolve this .
-- 
View this message in context: http://www.nabble.com/using--annotation-%40AuthorizeInstantiation-tp20841729p20841729.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
Yes Adriano, that's what I said on my last reply. :-)

 >> So, the only way, for now, to have type-safety is using that 
Class-thing. I don't vote for this though. A simple class with String 
constants does de job quite well. :-D

Cheers,
Bruno

Adriano dos Santos Fernandes wrote:
> Bruno Borges escreveu:
>> Note that this is really type-safe, and these classes will never be 
>> instantiated.
> I don't think this has any value in this context. Where will the roles 
> x user will be? On the database, certainly...
>
> So why declare dummy classes for them? If yon don't want to repeat 
> strings, you could create static final constants somewhere...
>
>
> Adriano
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Adriano dos Santos Fernandes <ad...@uol.com.br>.
Bruno Borges escreveu:
> Note that this is really type-safe, and these classes will never be 
> instantiated.
I don't think this has any value in this context. Where will the roles x 
user will be? On the database, certainly...

So why declare dummy classes for them? If yon don't want to repeat 
strings, you could create static final constants somewhere...


Adriano


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
It is not possible to extend enums nor annotations. And as the question 
here is about the use of @AuthorizeInstantiation, there's no way to 
declare MyEnum[], of course :-)

So, the only way, for now, to have type-safety is using that 
Class-thing. I don't vote for this though. A simple class with String 
constants does de job quite well. :-D

James Carman wrote:
> But, you can declare the values "property" to be of type MyEnum[].  Is what
> we're really looking for here the ability to extend an enum (if that even
> makes sense)?  I've often thought it would be nice if I could add stuff to
> an enum from the outside.  But, that kind of goes against the idea of an
> enum, doesn't it?
>
> On Thu, Dec 4, 2008 at 11:51 PM, Bruno Borges <br...@gmail.com>wrote:
>
>   
>> Well... you can't do this:
>>
>> @Foo(values={MyEnum.FOO,  MyEnum.BAR});
>>
>> @interface Foo {
>>  Object[] values() default {};
>>
>> }
>>
>> James Carman wrote:
>>
>>     
>>> What do you mean by "Enums as Objects"?
>>>
>>> On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <bruno.borges@gmail.com
>>>       
>>>> wrote:
>>>>         
>>>
>>>       
>>>> Well... You don't have to create one java file for each class. You can
>>>> put
>>>> all of them on the same file, like:
>>>>
>>>> public final class MyAppRoles {
>>>>  private MyAppRoles() {}
>>>>  public static final class Admin extends Role {
>>>>      private Admin() {}
>>>>  }
>>>>
>>>>  public static final class User extends Role {
>>>>      private User() {}
>>>>  }
>>>> }
>>>>
>>>> Note that this is really type-safe, and these classes will never be
>>>> instantiated.
>>>> But, I'm not defending that we should change that. I'm just showing a
>>>> possibility. :-)
>>>>
>>>> I really did't understand why Sun decided to reject Enums as Objects in
>>>> this context of annotations.
>>>>
>>>> cheers,
>>>> Bruno
>>>>
>>>> James Carman wrote:
>>>>
>>>>
>>>>
>>>>         
>>>>> I don't know about this.  It would work (and break existing code, unless
>>>>> you
>>>>> use something other than value for the annotation).  I don't know if I
>>>>> would
>>>>> want to have to create a new class for each role in my project.  Yes, it
>>>>> would be a small price to pay, but it just feels wrong.
>>>>>
>>>>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>>>>>
>>>>>
>>>>>           
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>             
>>>>>
>>>>>           
>>>>>> I've found a way to implement a type-safe check for this. Here it goes:
>>>>>>
>>>>>> import java.lang.annotation.Documented;
>>>>>> import java.lang.annotation.ElementType;
>>>>>> import java.lang.annotation.Inherited;
>>>>>> import java.lang.annotation.Retention;
>>>>>> import java.lang.annotation.RetentionPolicy;
>>>>>> import java.lang.annotation.Target;
>>>>>>
>>>>>> @AuthorizeInstantiation(value = { User.class, Admin.class })
>>>>>> public class EnumAnnotation {
>>>>>>
>>>>>> }
>>>>>>
>>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>>>> @Documented
>>>>>> @Inherited
>>>>>> @interface AuthorizeInstantiation {
>>>>>>
>>>>>>  Class<? extends Role>[] value() default {};
>>>>>>
>>>>>> }
>>>>>>
>>>>>> class Role {
>>>>>> }
>>>>>>
>>>>>> class User extends Role {
>>>>>> }
>>>>>>
>>>>>> class Admin extends Role {
>>>>>> }
>>>>>>
>>>>>> So, the only thing that must change is the annotation
>>>>>> @AuthorizeInstantiation, to accept classes that extends roles.
>>>>>>
>>>>>> Thoughts anyone?
>>>>>>
>>>>>> cheers,
>>>>>> Bruno
>>>>>>
>>>>>>
>>>>>>
>>>>>> Bruno Borges wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>>>> You simply can't do that because the nature of Annotations.
>>>>>>>
>>>>>>> Even if AuthorizeInstantiation's values were of type Object[] you
>>>>>>> wouldn't
>>>>>>> be able to do that with Enums.
>>>>>>>
>>>>>>> You will have to use Strings.
>>>>>>>
>>>>>>> Although there's some hack you can make using Java 6 to accomplish
>>>>>>> what
>>>>>>> you want. If you are interested, take a look at this link:
>>>>>>>
>>>>>>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>>>>> <
>>>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>>>               
>>>>>>> <
>>>>>>>
>>>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>>>          Good luck!!
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Bruno
>>>>>>>
>>>>>>> miro wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>>>>>>> annotation)
>>>>>>>> in my pages , the code for this annotation
>>>>>>>>
>>>>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>>>>>> @Documented
>>>>>>>> @Inherited
>>>>>>>> public @interface AuthorizeInstantiation {
>>>>>>>>
>>>>>>>>  /**
>>>>>>>>   * Gets the roles that are allowed to take the action.
>>>>>>>>   *      * @return the roles that are allowed. Returns a zero length
>>>>>>>> array by
>>>>>>>> default
>>>>>>>>   */
>>>>>>>>  String[] value() default {};
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> I created my enum with representing authorities
>>>>>>>>
>>>>>>>> public enum  Authorities {
>>>>>>>>      LIASION_OFFICER,
>>>>>>>>  GRANTS_OFFICER,
>>>>>>>>  PROGRAM_ANALYST,
>>>>>>>>  ADMIN;
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>> I am trying to use  AuthorizeInstantiation   in my page  here an
>>>>>>>> example
>>>>>>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>>>>>>>> public class HomePage extends BasePage {
>>>>>>>>
>>>>>>>>
>>>>>>>> this line does not compile, I get the error
>>>>>>>> The value of annotation attribute AuthorizeInstantiation .value must
>>>>>>>> be
>>>>>>>> a
>>>>>>>> constant expression  .please help me resolve this .
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>                 
>>>>>>> ---------------------------------------------------------------------
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>>
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>         
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by James Carman <ja...@carmanconsulting.com>.
But, you can declare the values "property" to be of type MyEnum[].  Is what
we're really looking for here the ability to extend an enum (if that even
makes sense)?  I've often thought it would be nice if I could add stuff to
an enum from the outside.  But, that kind of goes against the idea of an
enum, doesn't it?

On Thu, Dec 4, 2008 at 11:51 PM, Bruno Borges <br...@gmail.com>wrote:

> Well... you can't do this:
>
> @Foo(values={MyEnum.FOO,  MyEnum.BAR});
>
> @interface Foo {
>  Object[] values() default {};
>
> }
>
> James Carman wrote:
>
>> What do you mean by "Enums as Objects"?
>>
>> On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <bruno.borges@gmail.com
>> >wrote:
>>
>>
>>
>>> Well... You don't have to create one java file for each class. You can
>>> put
>>> all of them on the same file, like:
>>>
>>> public final class MyAppRoles {
>>>  private MyAppRoles() {}
>>>  public static final class Admin extends Role {
>>>      private Admin() {}
>>>  }
>>>
>>>  public static final class User extends Role {
>>>      private User() {}
>>>  }
>>> }
>>>
>>> Note that this is really type-safe, and these classes will never be
>>> instantiated.
>>> But, I'm not defending that we should change that. I'm just showing a
>>> possibility. :-)
>>>
>>> I really did't understand why Sun decided to reject Enums as Objects in
>>> this context of annotations.
>>>
>>> cheers,
>>> Bruno
>>>
>>> James Carman wrote:
>>>
>>>
>>>
>>>> I don't know about this.  It would work (and break existing code, unless
>>>> you
>>>> use something other than value for the annotation).  I don't know if I
>>>> would
>>>> want to have to create a new class for each role in my project.  Yes, it
>>>> would be a small price to pay, but it just feels wrong.
>>>>
>>>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>>>>
>>>>
>>>>> wrote:
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>> I've found a way to implement a type-safe check for this. Here it goes:
>>>>>
>>>>> import java.lang.annotation.Documented;
>>>>> import java.lang.annotation.ElementType;
>>>>> import java.lang.annotation.Inherited;
>>>>> import java.lang.annotation.Retention;
>>>>> import java.lang.annotation.RetentionPolicy;
>>>>> import java.lang.annotation.Target;
>>>>>
>>>>> @AuthorizeInstantiation(value = { User.class, Admin.class })
>>>>> public class EnumAnnotation {
>>>>>
>>>>> }
>>>>>
>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>>> @Documented
>>>>> @Inherited
>>>>> @interface AuthorizeInstantiation {
>>>>>
>>>>>  Class<? extends Role>[] value() default {};
>>>>>
>>>>> }
>>>>>
>>>>> class Role {
>>>>> }
>>>>>
>>>>> class User extends Role {
>>>>> }
>>>>>
>>>>> class Admin extends Role {
>>>>> }
>>>>>
>>>>> So, the only thing that must change is the annotation
>>>>> @AuthorizeInstantiation, to accept classes that extends roles.
>>>>>
>>>>> Thoughts anyone?
>>>>>
>>>>> cheers,
>>>>> Bruno
>>>>>
>>>>>
>>>>>
>>>>> Bruno Borges wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> You simply can't do that because the nature of Annotations.
>>>>>>
>>>>>> Even if AuthorizeInstantiation's values were of type Object[] you
>>>>>> wouldn't
>>>>>> be able to do that with Enums.
>>>>>>
>>>>>> You will have to use Strings.
>>>>>>
>>>>>> Although there's some hack you can make using Java 6 to accomplish
>>>>>> what
>>>>>> you want. If you are interested, take a look at this link:
>>>>>>
>>>>>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>>>> <
>>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>> >
>>>>>> <
>>>>>>
>>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>>          Good luck!!
>>>>>>
>>>>>> Cheers,
>>>>>> Bruno
>>>>>>
>>>>>> miro wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>>>>>> annotation)
>>>>>>> in my pages , the code for this annotation
>>>>>>>
>>>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>>>>> @Documented
>>>>>>> @Inherited
>>>>>>> public @interface AuthorizeInstantiation {
>>>>>>>
>>>>>>>  /**
>>>>>>>   * Gets the roles that are allowed to take the action.
>>>>>>>   *      * @return the roles that are allowed. Returns a zero length
>>>>>>> array by
>>>>>>> default
>>>>>>>   */
>>>>>>>  String[] value() default {};
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> I created my enum with representing authorities
>>>>>>>
>>>>>>> public enum  Authorities {
>>>>>>>      LIASION_OFFICER,
>>>>>>>  GRANTS_OFFICER,
>>>>>>>  PROGRAM_ANALYST,
>>>>>>>  ADMIN;
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> I am trying to use  AuthorizeInstantiation   in my page  here an
>>>>>>> example
>>>>>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>>>>>>> public class HomePage extends BasePage {
>>>>>>>
>>>>>>>
>>>>>>> this line does not compile, I get the error
>>>>>>> The value of annotation attribute AuthorizeInstantiation .value must
>>>>>>> be
>>>>>>> a
>>>>>>> constant expression  .please help me resolve this .
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>>
>>>>>>
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
Well... you can't do this:

@Foo(values={MyEnum.FOO,  MyEnum.BAR});

@interface Foo {
  Object[] values() default {};
}

James Carman wrote:
> What do you mean by "Enums as Objects"?
>
> On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <br...@gmail.com>wrote:
>
>   
>> Well... You don't have to create one java file for each class. You can put
>> all of them on the same file, like:
>>
>> public final class MyAppRoles {
>>   private MyAppRoles() {}
>>   public static final class Admin extends Role {
>>       private Admin() {}
>>   }
>>
>>   public static final class User extends Role {
>>       private User() {}
>>   }
>> }
>>
>> Note that this is really type-safe, and these classes will never be
>> instantiated.
>> But, I'm not defending that we should change that. I'm just showing a
>> possibility. :-)
>>
>> I really did't understand why Sun decided to reject Enums as Objects in
>> this context of annotations.
>>
>> cheers,
>> Bruno
>>
>> James Carman wrote:
>>
>>     
>>> I don't know about this.  It would work (and break existing code, unless
>>> you
>>> use something other than value for the annotation).  I don't know if I
>>> would
>>> want to have to create a new class for each role in my project.  Yes, it
>>> would be a small price to pay, but it just feels wrong.
>>>
>>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>>>       
>>>> wrote:
>>>>         
>>>
>>>       
>>>> I've found a way to implement a type-safe check for this. Here it goes:
>>>>
>>>> import java.lang.annotation.Documented;
>>>> import java.lang.annotation.ElementType;
>>>> import java.lang.annotation.Inherited;
>>>> import java.lang.annotation.Retention;
>>>> import java.lang.annotation.RetentionPolicy;
>>>> import java.lang.annotation.Target;
>>>>
>>>> @AuthorizeInstantiation(value = { User.class, Admin.class })
>>>> public class EnumAnnotation {
>>>>
>>>> }
>>>>
>>>> @Retention(RetentionPolicy.RUNTIME)
>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>> @Documented
>>>> @Inherited
>>>> @interface AuthorizeInstantiation {
>>>>
>>>>  Class<? extends Role>[] value() default {};
>>>>
>>>> }
>>>>
>>>> class Role {
>>>> }
>>>>
>>>> class User extends Role {
>>>> }
>>>>
>>>> class Admin extends Role {
>>>> }
>>>>
>>>> So, the only thing that must change is the annotation
>>>> @AuthorizeInstantiation, to accept classes that extends roles.
>>>>
>>>> Thoughts anyone?
>>>>
>>>> cheers,
>>>> Bruno
>>>>
>>>>
>>>>
>>>> Bruno Borges wrote:
>>>>
>>>>
>>>>
>>>>         
>>>>> You simply can't do that because the nature of Annotations.
>>>>>
>>>>> Even if AuthorizeInstantiation's values were of type Object[] you
>>>>> wouldn't
>>>>> be able to do that with Enums.
>>>>>
>>>>> You will have to use Strings.
>>>>>
>>>>> Although there's some hack you can make using Java 6 to accomplish what
>>>>> you want. If you are interested, take a look at this link:
>>>>>
>>>>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>>> <
>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>           
>>>>> Good luck!!
>>>>>
>>>>> Cheers,
>>>>> Bruno
>>>>>
>>>>> miro wrote:
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>>>>> annotation)
>>>>>> in my pages , the code for this annotation
>>>>>>
>>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>>>> @Documented
>>>>>> @Inherited
>>>>>> public @interface AuthorizeInstantiation {
>>>>>>
>>>>>>   /**
>>>>>>    * Gets the roles that are allowed to take the action.
>>>>>>    *      * @return the roles that are allowed. Returns a zero length
>>>>>> array by
>>>>>> default
>>>>>>    */
>>>>>>   String[] value() default {};
>>>>>> }
>>>>>>
>>>>>>
>>>>>> I created my enum with representing authorities
>>>>>>
>>>>>> public enum  Authorities {
>>>>>>       LIASION_OFFICER,
>>>>>>   GRANTS_OFFICER,
>>>>>>   PROGRAM_ANALYST,
>>>>>>   ADMIN;
>>>>>>
>>>>>> }
>>>>>>
>>>>>> I am trying to use  AuthorizeInstantiation   in my page  here an
>>>>>> example
>>>>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>>>>>> public class HomePage extends BasePage {
>>>>>>
>>>>>>
>>>>>> this line does not compile, I get the error
>>>>>> The value of annotation attribute AuthorizeInstantiation .value must be
>>>>>> a
>>>>>> constant expression  .please help me resolve this .
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>> ---------------------------------------------------------------------
>>>>>           
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>         
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by James Carman <ja...@carmanconsulting.com>.
What do you mean by "Enums as Objects"?

On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <br...@gmail.com>wrote:

> Well... You don't have to create one java file for each class. You can put
> all of them on the same file, like:
>
> public final class MyAppRoles {
>   private MyAppRoles() {}
>   public static final class Admin extends Role {
>       private Admin() {}
>   }
>
>   public static final class User extends Role {
>       private User() {}
>   }
> }
>
> Note that this is really type-safe, and these classes will never be
> instantiated.
> But, I'm not defending that we should change that. I'm just showing a
> possibility. :-)
>
> I really did't understand why Sun decided to reject Enums as Objects in
> this context of annotations.
>
> cheers,
> Bruno
>
> James Carman wrote:
>
>> I don't know about this.  It would work (and break existing code, unless
>> you
>> use something other than value for the annotation).  I don't know if I
>> would
>> want to have to create a new class for each role in my project.  Yes, it
>> would be a small price to pay, but it just feels wrong.
>>
>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>> >wrote:
>>
>>
>>
>>> I've found a way to implement a type-safe check for this. Here it goes:
>>>
>>> import java.lang.annotation.Documented;
>>> import java.lang.annotation.ElementType;
>>> import java.lang.annotation.Inherited;
>>> import java.lang.annotation.Retention;
>>> import java.lang.annotation.RetentionPolicy;
>>> import java.lang.annotation.Target;
>>>
>>> @AuthorizeInstantiation(value = { User.class, Admin.class })
>>> public class EnumAnnotation {
>>>
>>> }
>>>
>>> @Retention(RetentionPolicy.RUNTIME)
>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>> @Documented
>>> @Inherited
>>> @interface AuthorizeInstantiation {
>>>
>>>  Class<? extends Role>[] value() default {};
>>>
>>> }
>>>
>>> class Role {
>>> }
>>>
>>> class User extends Role {
>>> }
>>>
>>> class Admin extends Role {
>>> }
>>>
>>> So, the only thing that must change is the annotation
>>> @AuthorizeInstantiation, to accept classes that extends roles.
>>>
>>> Thoughts anyone?
>>>
>>> cheers,
>>> Bruno
>>>
>>>
>>>
>>> Bruno Borges wrote:
>>>
>>>
>>>
>>>> You simply can't do that because the nature of Annotations.
>>>>
>>>> Even if AuthorizeInstantiation's values were of type Object[] you
>>>> wouldn't
>>>> be able to do that with Enums.
>>>>
>>>> You will have to use Strings.
>>>>
>>>> Although there's some hack you can make using Java 6 to accomplish what
>>>> you want. If you are interested, take a look at this link:
>>>>
>>>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>> <
>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>> >
>>>>
>>>>
>>>> Good luck!!
>>>>
>>>> Cheers,
>>>> Bruno
>>>>
>>>> miro wrote:
>>>>
>>>>
>>>>
>>>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>>>> annotation)
>>>>> in my pages , the code for this annotation
>>>>>
>>>>> @Retention(RetentionPolicy.RUNTIME)
>>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>>> @Documented
>>>>> @Inherited
>>>>> public @interface AuthorizeInstantiation {
>>>>>
>>>>>   /**
>>>>>    * Gets the roles that are allowed to take the action.
>>>>>    *      * @return the roles that are allowed. Returns a zero length
>>>>> array by
>>>>> default
>>>>>    */
>>>>>   String[] value() default {};
>>>>> }
>>>>>
>>>>>
>>>>> I created my enum with representing authorities
>>>>>
>>>>> public enum  Authorities {
>>>>>       LIASION_OFFICER,
>>>>>   GRANTS_OFFICER,
>>>>>   PROGRAM_ANALYST,
>>>>>   ADMIN;
>>>>>
>>>>> }
>>>>>
>>>>> I am trying to use  AuthorizeInstantiation   in my page  here an
>>>>> example
>>>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>>>>> public class HomePage extends BasePage {
>>>>>
>>>>>
>>>>> this line does not compile, I get the error
>>>>> The value of annotation attribute AuthorizeInstantiation .value must be
>>>>> a
>>>>> constant expression  .please help me resolve this .
>>>>>
>>>>>
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
Well... You don't have to create one java file for each class. You can 
put all of them on the same file, like:

public final class MyAppRoles {
    private MyAppRoles() {}
    public static final class Admin extends Role {
        private Admin() {}
    }

    public static final class User extends Role {
        private User() {}
    }
}

Note that this is really type-safe, and these classes will never be 
instantiated.
But, I'm not defending that we should change that. I'm just showing a 
possibility. :-)

I really did't understand why Sun decided to reject Enums as Objects in 
this context of annotations.

cheers,
Bruno

James Carman wrote:
> I don't know about this.  It would work (and break existing code, unless you
> use something other than value for the annotation).  I don't know if I would
> want to have to create a new class for each role in my project.  Yes, it
> would be a small price to pay, but it just feels wrong.
>
> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <br...@gmail.com>wrote:
>
>   
>> I've found a way to implement a type-safe check for this. Here it goes:
>>
>> import java.lang.annotation.Documented;
>> import java.lang.annotation.ElementType;
>> import java.lang.annotation.Inherited;
>> import java.lang.annotation.Retention;
>> import java.lang.annotation.RetentionPolicy;
>> import java.lang.annotation.Target;
>>
>> @AuthorizeInstantiation(value = { User.class, Admin.class })
>> public class EnumAnnotation {
>>
>> }
>>
>> @Retention(RetentionPolicy.RUNTIME)
>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>> @Documented
>> @Inherited
>> @interface AuthorizeInstantiation {
>>
>>   Class<? extends Role>[] value() default {};
>>
>> }
>>
>> class Role {
>> }
>>
>> class User extends Role {
>> }
>>
>> class Admin extends Role {
>> }
>>
>> So, the only thing that must change is the annotation
>> @AuthorizeInstantiation, to accept classes that extends roles.
>>
>> Thoughts anyone?
>>
>> cheers,
>> Bruno
>>
>>
>>
>> Bruno Borges wrote:
>>
>>     
>>> You simply can't do that because the nature of Annotations.
>>>
>>> Even if AuthorizeInstantiation's values were of type Object[] you wouldn't
>>> be able to do that with Enums.
>>>
>>> You will have to use Strings.
>>>
>>> Although there's some hack you can make using Java 6 to accomplish what
>>> you want. If you are interested, take a look at this link:
>>>
>>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>
>>> Good luck!!
>>>
>>> Cheers,
>>> Bruno
>>>
>>> miro wrote:
>>>
>>>       
>>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>>> annotation)
>>>> in my pages , the code for this annotation
>>>>
>>>> @Retention(RetentionPolicy.RUNTIME)
>>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>>> @Documented
>>>> @Inherited
>>>> public @interface AuthorizeInstantiation {
>>>>
>>>>    /**
>>>>     * Gets the roles that are allowed to take the action.
>>>>     *      * @return the roles that are allowed. Returns a zero length
>>>> array by
>>>> default
>>>>     */
>>>>    String[] value() default {};
>>>> }
>>>>
>>>>
>>>> I created my enum with representing authorities
>>>>
>>>> public enum  Authorities {
>>>>        LIASION_OFFICER,
>>>>    GRANTS_OFFICER,
>>>>    PROGRAM_ANALYST,
>>>>    ADMIN;
>>>>
>>>> }
>>>>
>>>> I am trying to use  AuthorizeInstantiation   in my page  here an example
>>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>>>> public class HomePage extends BasePage {
>>>>
>>>>
>>>> this line does not compile, I get the error
>>>> The value of annotation attribute AuthorizeInstantiation .value must be a
>>>> constant expression  .please help me resolve this .
>>>>
>>>>
>>>>         
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by James Carman <ja...@carmanconsulting.com>.
I don't know about this.  It would work (and break existing code, unless you
use something other than value for the annotation).  I don't know if I would
want to have to create a new class for each role in my project.  Yes, it
would be a small price to pay, but it just feels wrong.

On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <br...@gmail.com>wrote:

> I've found a way to implement a type-safe check for this. Here it goes:
>
> import java.lang.annotation.Documented;
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Inherited;
> import java.lang.annotation.Retention;
> import java.lang.annotation.RetentionPolicy;
> import java.lang.annotation.Target;
>
> @AuthorizeInstantiation(value = { User.class, Admin.class })
> public class EnumAnnotation {
>
> }
>
> @Retention(RetentionPolicy.RUNTIME)
> @Target( { ElementType.PACKAGE, ElementType.TYPE })
> @Documented
> @Inherited
> @interface AuthorizeInstantiation {
>
>   Class<? extends Role>[] value() default {};
>
> }
>
> class Role {
> }
>
> class User extends Role {
> }
>
> class Admin extends Role {
> }
>
> So, the only thing that must change is the annotation
> @AuthorizeInstantiation, to accept classes that extends roles.
>
> Thoughts anyone?
>
> cheers,
> Bruno
>
>
>
> Bruno Borges wrote:
>
>> You simply can't do that because the nature of Annotations.
>>
>> Even if AuthorizeInstantiation's values were of type Object[] you wouldn't
>> be able to do that with Enums.
>>
>> You will have to use Strings.
>>
>> Although there's some hack you can make using Java 6 to accomplish what
>> you want. If you are interested, take a look at this link:
>>
>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>
>> Good luck!!
>>
>> Cheers,
>> Bruno
>>
>> miro wrote:
>>
>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>> annotation)
>>> in my pages , the code for this annotation
>>>
>>> @Retention(RetentionPolicy.RUNTIME)
>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>> @Documented
>>> @Inherited
>>> public @interface AuthorizeInstantiation {
>>>
>>>    /**
>>>     * Gets the roles that are allowed to take the action.
>>>     *      * @return the roles that are allowed. Returns a zero length
>>> array by
>>> default
>>>     */
>>>    String[] value() default {};
>>> }
>>>
>>>
>>> I created my enum with representing authorities
>>>
>>> public enum  Authorities {
>>>        LIASION_OFFICER,
>>>    GRANTS_OFFICER,
>>>    PROGRAM_ANALYST,
>>>    ADMIN;
>>>
>>> }
>>>
>>> I am trying to use  AuthorizeInstantiation   in my page  here an example
>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>>> public class HomePage extends BasePage {
>>>
>>>
>>> this line does not compile, I get the error
>>> The value of annotation attribute AuthorizeInstantiation .value must be a
>>> constant expression  .please help me resolve this .
>>>
>>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Casper Bang <ca...@jbr.dk>.
Yeah, I asked about this last week or so when running into the same 
problem. I now also do it the class way, and although that does feel 
better than using strings, in my opinion it still isn't type safe. It 
gives no syntax lookup and people are free to write Object.class which 
will compile just fine. Marker interfaces are better for composability, 
however if you are going to make a truly role based system, chances are 
you'll want a  backing roles table and that can get tricky with inheritance.

I'll probably go back to the enum way, which works fine enough IF you 
are ok with having the role definitions mixed with the authorization 
code. It's a small price to pay, I rewrote some of the annotation stuff 
to make it easier to use anyway (AccessableTo, EnabledTo and VisibleTo ) 
which now just takes an array of values which means clean code like this:

@VisibleTo({Administrator.class, User.class})

...rather than:

|@AuthorizeAction(action = Action.RENDER, roles = {Roles.ADMIN, 
Roles.USER})|

Anyway, just my 2 cents on the topic.

/Casper



Jeremy Thomerson wrote:
> If you were going to do this, it would be much better (IMHO) to use
> interfaces...  This gives you interesting possibilities:
>
> (Disclaimer - the following is not an original thought - Igor mentioned this
> last week - give credit where it's due)
>
> interface User
>
> interface Admin extends User
>
> interface ProjectManager extends Admin
>
> interface SalesManager extends Admin
>
> HERE'S THE KICKER:
>
> interface TheBigBoss extends ProjectManager, SalesManager
>
> Since those are just marker interfaces, I guess each of those would need
> something like a single public static final implementation like:
> public static final TheBigBoss INSTANCE = new TheBigBoss() {};
>
> Something like that - anyway, MULTIPLE INHERITANCE FOR ROLES RULES!
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Jeremy Thomerson <je...@wickettraining.com>.
I'm not, because as was mentioned elsewhere on the thread, you almost always
need to go back to some (or other - int) mechanism because in reality,
permissions typically end up being:

User has a Role (or multiple roles)
Those Role objects have Permission objects
User can also have Permission objects that are outside of his normal role.

For instance, I'm a regional manager, so I have that role and maybe others
that go with it, but the national manager gives me the extra permission to
view sales reports for while he's gone or because I'm assisting him.  I
don't get everything in his role - seeing salaries for instance, but I have
certain permissions in addition to my role-inherited permissions.

Anyway, the idea I gave below is certainly an intriguing one to me, and I
think it's interesting, but there are holes in it.  So - nino - I guess it's
your potato :)

On Fri, Dec 5, 2008 at 7:21 AM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> wrote:

> Yeah this is a much nicer way.. So whos gonna implement it? :)
>
> regards Nino
>
> Jeremy Thomerson wrote:
>
>> If you were going to do this, it would be much better (IMHO) to use
>> interfaces...  This gives you interesting possibilities:
>>
>> (Disclaimer - the following is not an original thought - Igor mentioned
>> this
>> last week - give credit where it's due)
>>
>> interface User
>>
>> interface Admin extends User
>>
>> interface ProjectManager extends Admin
>>
>> interface SalesManager extends Admin
>>
>> HERE'S THE KICKER:
>>
>> interface TheBigBoss extends ProjectManager, SalesManager
>>
>> Since those are just marker interfaces, I guess each of those would need
>> something like a single public static final implementation like:
>> public static final TheBigBoss INSTANCE = new TheBigBoss() {};
>>
>> Something like that - anyway, MULTIPLE INHERITANCE FOR ROLES RULES!
>>
>>
>>
>>
>
>
>  ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: using annotation @AuthorizeInstantiation

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Yeah this is a much nicer way.. So whos gonna implement it? :)

regards Nino

Jeremy Thomerson wrote:
> If you were going to do this, it would be much better (IMHO) to use
> interfaces...  This gives you interesting possibilities:
>
> (Disclaimer - the following is not an original thought - Igor mentioned this
> last week - give credit where it's due)
>
> interface User
>
> interface Admin extends User
>
> interface ProjectManager extends Admin
>
> interface SalesManager extends Admin
>
> HERE'S THE KICKER:
>
> interface TheBigBoss extends ProjectManager, SalesManager
>
> Since those are just marker interfaces, I guess each of those would need
> something like a single public static final implementation like:
> public static final TheBigBoss INSTANCE = new TheBigBoss() {};
>
> Something like that - anyway, MULTIPLE INHERITANCE FOR ROLES RULES!
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Jeremy Thomerson <je...@wickettraining.com>.
If you were going to do this, it would be much better (IMHO) to use
interfaces...  This gives you interesting possibilities:

(Disclaimer - the following is not an original thought - Igor mentioned this
last week - give credit where it's due)

interface User

interface Admin extends User

interface ProjectManager extends Admin

interface SalesManager extends Admin

HERE'S THE KICKER:

interface TheBigBoss extends ProjectManager, SalesManager

Since those are just marker interfaces, I guess each of those would need
something like a single public static final implementation like:
public static final TheBigBoss INSTANCE = new TheBigBoss() {};

Something like that - anyway, MULTIPLE INHERITANCE FOR ROLES RULES!


-- 
Jeremy Thomerson
http://www.wickettraining.com


On Thu, Dec 4, 2008 at 9:33 PM, Bruno Borges <br...@gmail.com> wrote:

> I've found a way to implement a type-safe check for this. Here it goes:
>
> import java.lang.annotation.Documented;
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Inherited;
> import java.lang.annotation.Retention;
> import java.lang.annotation.RetentionPolicy;
> import java.lang.annotation.Target;
>
> @AuthorizeInstantiation(value = { User.class, Admin.class })
> public class EnumAnnotation {
>
> }
>
> @Retention(RetentionPolicy.RUNTIME)
> @Target( { ElementType.PACKAGE, ElementType.TYPE })
> @Documented
> @Inherited
> @interface AuthorizeInstantiation {
>
>   Class<? extends Role>[] value() default {};
>
> }
>
> class Role {
> }
>
> class User extends Role {
> }
>
> class Admin extends Role {
> }
>
> So, the only thing that must change is the annotation
> @AuthorizeInstantiation, to accept classes that extends roles.
>
> Thoughts anyone?
>
> cheers,
> Bruno
>
>
>
> Bruno Borges wrote:
>
>> You simply can't do that because the nature of Annotations.
>>
>> Even if AuthorizeInstantiation's values were of type Object[] you wouldn't
>> be able to do that with Enums.
>>
>> You will have to use Strings.
>>
>> Although there's some hack you can make using Java 6 to accomplish what
>> you want. If you are interested, take a look at this link:
>>
>> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/
>>
>> Good luck!!
>>
>> Cheers,
>> Bruno
>>
>> miro wrote:
>>
>>> I am using this  @AuthorizeInstantiation   (wicket authetication
>>> annotation)
>>> in my pages , the code for this annotation
>>>
>>> @Retention(RetentionPolicy.RUNTIME)
>>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>>> @Documented
>>> @Inherited
>>> public @interface AuthorizeInstantiation {
>>>
>>>    /**
>>>     * Gets the roles that are allowed to take the action.
>>>     *      * @return the roles that are allowed. Returns a zero length
>>> array by
>>> default
>>>     */
>>>    String[] value() default {};
>>> }
>>>
>>>
>>> I created my enum with representing authorities
>>>
>>> public enum  Authorities {
>>>        LIASION_OFFICER,
>>>    GRANTS_OFFICER,
>>>    PROGRAM_ANALYST,
>>>    ADMIN;
>>>
>>> }
>>>
>>> I am trying to use  AuthorizeInstantiation   in my page  here an example
>>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name<http://authorities.liasion_officer.name/>
>>> ()})
>>> public class HomePage extends BasePage {
>>>
>>>
>>> this line does not compile, I get the error
>>> The value of annotation attribute AuthorizeInstantiation .value must be a
>>> constant expression  .please help me resolve this .
>>>
>>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
I've found a way to implement a type-safe check for this. Here it goes:

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@AuthorizeInstantiation(value = { User.class, Admin.class })
public class EnumAnnotation {

}

@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.PACKAGE, ElementType.TYPE })
@Documented
@Inherited
@interface AuthorizeInstantiation {

    Class<? extends Role>[] value() default {};

}

class Role {
}

class User extends Role {
}

class Admin extends Role {
}

So, the only thing that must change is the annotation 
@AuthorizeInstantiation, to accept classes that extends roles.

Thoughts anyone?

cheers,
Bruno


Bruno Borges wrote:
> You simply can't do that because the nature of Annotations.
>
> Even if AuthorizeInstantiation's values were of type Object[] you 
> wouldn't be able to do that with Enums.
>
> You will have to use Strings.
>
> Although there's some hack you can make using Java 6 to accomplish 
> what you want. If you are interested, take a look at this link:
>
> http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/
>
> Good luck!!
>
> Cheers,
> Bruno
>
> miro wrote:
>> I am using this  @AuthorizeInstantiation   (wicket authetication 
>> annotation)
>> in my pages , the code for this annotation
>>
>> @Retention(RetentionPolicy.RUNTIME)
>> @Target( { ElementType.PACKAGE, ElementType.TYPE })
>> @Documented
>> @Inherited
>> public @interface AuthorizeInstantiation {
>>
>>     /**
>>      * Gets the roles that are allowed to take the action.
>>      *      * @return the roles that are allowed. Returns a zero 
>> length array by
>> default
>>      */
>>     String[] value() default {};
>> }
>>
>>
>> I created my enum with representing authorities
>>
>> public enum  Authorities {
>>     
>>     LIASION_OFFICER,
>>     GRANTS_OFFICER,
>>     PROGRAM_ANALYST,
>>     ADMIN;
>>
>> }
>>
>> I am trying to use  AuthorizeInstantiation   in my page  here an example
>> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
>> public class HomePage extends BasePage {
>>
>>
>> this line does not compile, I get the error
>> The value of annotation attribute AuthorizeInstantiation .value must 
>> be a
>> constant expression  .please help me resolve this .
>>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
You simply can't do that because the nature of Annotations.

Even if AuthorizeInstantiation's values were of type Object[] you 
wouldn't be able to do that with Enums.

You will have to use Strings.

Although there's some hack you can make using Java 6 to accomplish what 
you want. If you are interested, take a look at this link:

http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/

Good luck!!

Cheers,
Bruno

miro wrote:
> I am using this  @AuthorizeInstantiation   (wicket authetication annotation)
> in my pages , the code for this annotation
>
> @Retention(RetentionPolicy.RUNTIME)
> @Target( { ElementType.PACKAGE, ElementType.TYPE })
> @Documented
> @Inherited
> public @interface AuthorizeInstantiation {
>
> 	/**
> 	 * Gets the roles that are allowed to take the action.
> 	 * 
> 	 * @return the roles that are allowed. Returns a zero length array by
> default
> 	 */
> 	String[] value() default {};
> }
>
>
> I created my enum with representing authorities
>
> public enum  Authorities {
> 	
> 	LIASION_OFFICER,
> 	GRANTS_OFFICER,
> 	PROGRAM_ANALYST,
> 	ADMIN;
>
> }
>
> I am trying to use  AuthorizeInstantiation   in my page  here an example 
>
> @AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
> public class HomePage extends BasePage {
>
>
> this line does not compile, I get the error 
>
> The value of annotation attribute AuthorizeInstantiation .value must be a
> constant expression  .please help me resolve this .
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org