CDI and Seam 3An exciting new landscape for JavaEE development        Shane Bryzak        21/04/10
The History of Seam                (In 2 minutes or less)• First beta in September 2005• 1.0.0.GA released in June 2006• 2...
Sub Headline               3
Sub Headline               4
5
6
JSR-299 Implementations• Weld (by Red Hat - Reference Implementation)• OpenWebBeans (by Apache)• CanDI (by Caucho)        ...
Portable Extensions•   One of the most exciting features in CDI•   Extend the behaviour of the Java EE platform•   Seam 3 ...
Just how easy?3 simple steps:• Create a new Java class• Register the extension• Implement the extension logic             ...
Portable Extensions               Creating the Java classpackage com.acme;import javax.enterprise.inject.spi.Extension;pub...
Portable Extensions               Registering the extension• Create a file in the META-INF/services directory called  java...
Portable Extensions          Implementing the extension logic• Listen to events fired by the container at deployment time•...
A real world example                     Seam Security• Portable extension for CDI• Provides authentication, identity mana...
Typesafe authorization@SecurityBindingType@Retention(RUNTIME)@Target({TYPE, METHOD})public @interface Manager {}          ...
Typesafe authorization@Managerpublic void generateSalesReport() {   ...}                                      15
Typesafe authorization@Secures @Managerpublic boolean isManager(Identity identity)  {  return identity.hasRole("manager", ...
The extension must:• Match all methods annotated with a security binding type  with an authorizer method• Add an intercept...
Scanning the methods            ProcessAnnotatedType Event• Fired by the container for each Java class or interface it  di...
Event observerspublic class SecurityExtension implements Extension  {public <X> void processAnnotatedType(    @Observes Pr...
Interceptors• Interceptors specification part of JSR-318• CDI builds on this specification by introducing interceptor  bin...
Interceptor Bindings                     How they work• Create an interceptor binding annotation• Apply it to the intercep...
Interceptor Bindings             Creating the binding type@Retention(RUNTIME)@InterceptorBinding@Target( { TYPE, METHOD })...
Interceptor Bindings            Applying to the Interceptor@SecurityInterceptorBinding @Interceptorpublic class SecurityIn...
Interceptor Bindings            Applying it to a methodpublic @Model class DocumentAction {    @SecurityInterceptorBinding...
Dynamic interceptors• Our extension can apply an interceptor binding  dynamically, at deployment time• (Code demo - Eclips...
Upcoming SlideShare
Loading in …5
×

CDI and Seam 3: an Exciting New Landscape for Java EE Development

1,134 views

Published on

CDI (Contexts and Dependency Injection) for Java, aka JSR-299 has given us a new playing field for developing Java EE applications, by providing a standardised dependency injection framework and contextual component model. The CDI specification defines a feature for "portable extensions", which allow framework developers to extend the default behaviour of the Java EE container. By providing a number of useful portable extensions, Seam 3 increases developer productivity by solving the problems common to many enterprise projects. In this talk we will look at a number of features that Seam provides, dealing with transactions and persistence, security, internationalisation, bean validation and tooling, and how you can use them to improve your productivity in the real-world to develop rich internet applications. We'll also look at some of the cool upcoming features of Seam such as social network integration, and more.

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,134
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

CDI and Seam 3: an Exciting New Landscape for Java EE Development

  1. 1. CDI and Seam 3An exciting new landscape for JavaEE development Shane Bryzak 21/04/10
  2. 2. The History of Seam (In 2 minutes or less)• First beta in September 2005• 1.0.0.GA released in June 2006• 2.0.0.GA released in November 2007 2
  3. 3. Sub Headline 3
  4. 4. Sub Headline 4
  5. 5. 5
  6. 6. 6
  7. 7. JSR-299 Implementations• Weld (by Red Hat - Reference Implementation)• OpenWebBeans (by Apache)• CanDI (by Caucho) 7
  8. 8. Portable Extensions• One of the most exciting features in CDI• Extend the behaviour of the Java EE platform• Seam 3 is a collection of portable extensions• SPI defined by the JSR-299 spec• Easy to write 8
  9. 9. Just how easy?3 simple steps:• Create a new Java class• Register the extension• Implement the extension logic 9
  10. 10. Portable Extensions Creating the Java classpackage com.acme;import javax.enterprise.inject.spi.Extension;public class MyExtension implements Extension {} 10
  11. 11. Portable Extensions Registering the extension• Create a file in the META-INF/services directory called javax.enterprise.inject.spi.Extension• It should contain the name of your classcom.acme.MyExtension 11
  12. 12. Portable Extensions Implementing the extension logic• Listen to events fired by the container at deployment time• Extensions can observe these events and make changes to the containers metadata model• Dynamically change the default behaviour of beans, injection points• Implement new context types 12
  13. 13. A real world example Seam Security• Portable extension for CDI• Provides authentication, identity management and federated identity via OpenID, SAML, SSO• Provides typesafe authorization through the use of annotation-based metadata 13
  14. 14. Typesafe authorization@SecurityBindingType@Retention(RUNTIME)@Target({TYPE, METHOD})public @interface Manager {} 14
  15. 15. Typesafe authorization@Managerpublic void generateSalesReport() { ...} 15
  16. 16. Typesafe authorization@Secures @Managerpublic boolean isManager(Identity identity) { return identity.hasRole("manager", "USERS", "GROUP");} 16
  17. 17. The extension must:• Match all methods annotated with a security binding type with an authorizer method• Add an interceptor binding to the secured method• Throw an exception if there are any secured methods without a matching authorizer method 17
  18. 18. Scanning the methods ProcessAnnotatedType Event• Fired by the container for each Java class or interface it discovers• We can use this event to find classes or methods annotated with security binding types• Our extension class can observe this event 18
  19. 19. Event observerspublic class SecurityExtension implements Extension {public <X> void processAnnotatedType( @Observes ProcessAnnotatedType<X> event, final BeanManager beanManager){ ...} 19
  20. 20. Interceptors• Interceptors specification part of JSR-318• CDI builds on this specification by introducing interceptor bindings• Interceptor bindings are used to create a link between an interceptor and the bean to be intercepted 20
  21. 21. Interceptor Bindings How they work• Create an interceptor binding annotation• Apply it to the interceptor class• Apply it to the method or class that you want to be intercepted 21
  22. 22. Interceptor Bindings Creating the binding type@Retention(RUNTIME)@InterceptorBinding@Target( { TYPE, METHOD })@interface SecurityInterceptorBinding { } 22
  23. 23. Interceptor Bindings Applying to the Interceptor@SecurityInterceptorBinding @Interceptorpublic class SecurityInterceptor implements Serializable { @Inject SecurityExtension extension; @AroundInvoke public Object aroundInvoke(InvocationContext invocation) throws Exception { 23
  24. 24. Interceptor Bindings Applying it to a methodpublic @Model class DocumentAction { @SecurityInterceptorBinding public void createDocument() { }} 24
  25. 25. Dynamic interceptors• Our extension can apply an interceptor binding dynamically, at deployment time• (Code demo - Eclipse) 25

×