Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Taming Tiger, Part 3

Decorate your code with Java annotations

  • Print
  • Feedback

Page 4 of 4

  1. The first thread (role set to "HR") has access only to the unRestrictedMethod() and partiallyRestrictedMethod2() methods.
  2. The second thread (role set to "Manager") has access to the unRestrictedMethod(), partiallyRestrictedMethod(), and partiallyRestrictedMethod2() methods.
  3. Neither thread has access to the fullyRestrictedMethod() method.
  4. Both threads can access the unRestrictedMethod() method.
  5. Both threads were able to create an instance of the AnnotationsTest class because the class was annotated with the SecurityPermission annotation SecurityPermission("All"). If All was changed to None, then neither thread could have created an instance of the class.


The best way to see what's going on is to play around with the code and change the values of the various SecurityPermission annotations that are sprinkled around the AnnotationsTest class.

Finally, an awesome exercise would be to use AspectJ to define and implement the appropriate pointcuts that would allow you to completely remove the manual call to SecurityBlanket.checkPermission() from your code. Now that would be real "magic," and AspectJ makes it easy.

Conclusion

This concludes my three-part series on J2SE 5. Along the way, I have covered many interesting new language features, some more useful than others. I talked at length about the new Java metadata facility called annotations in this article. Annotations provide us with a host of new capabilities. Expect to see many tools in the next couple of years that capitalize on Java annotations to provide new value-added services either at compile time by code modification or at runtime.

About the author

Tarak Modi has been architecting scalable, high-performance, distributed applications for more than eight years and is currently a senior specialist with North Highland, a management and technology consulting company. His professional experience includes hardcore C++ and Java programming; working with Microsoft technologies such as COM, MTS, COM+, and more recently .Net; Java-based technologies including J2EE; and CORBA. He has written many articles in well-known .Net and Java publications including several in JavaWorld. He currently hosts the Java Design blog at JavaWorld. He is also coauthor of Professional Java Web Services (Wrox Press, 2002; ISBN 1861003757). To find out more about him, visit his personal Website at http://www.tekNirvana.com.
  • Print
  • Feedback

Resources