SlideShare uma empresa Scribd logo
1 de 39
1   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Utilize the Full Power of
GlassFish Server and Java
EE Security
Masoud Kalali
Principal Member of Technical Staff -
ORACLE
Twitter: @MasoudKalali
Blog: http://kalali.me

2   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Program Agenda


         Introduction
         Java EE Security API
         Java Authentication Service Provider Interface (JSR-
                  196)
         Java Authorization Contract for Containers (JSR-115)



3   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Introduction




4   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
        Terms


          A Subject: An individual identity which is to be authenticated.
          A Group: Group of users with common permissions and access levels.
          A Security Realm: Connects the application server identity storage.
          A Role: A Java EE concept to define access levels
          A Principal: Aka, A role attached to a authenticated subject
          A Credential: Contains or references information used to authenticate a
               principal



5   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
        Before anything else


          Identify the sensitive data
          Identify the roles having access to sensitive data
          Identify resources representing sensitive data
          Group the mentioned resources into meaningful sets


         And Document the above items!




6   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
        Resource Protection


          Authentication
                    – At Web Container
                    – Application Client Container
          Authorization (Access Control)
                    – At Web Container
                    – EJB Container
          Subject Propagation
                    – From Web Container to EJB Container
                    – From App Client To EJB container
                    – EIS to Connector (inflow messages)


7   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
        Authentication


          When a protected resource is requested
          Establish the client’s identity
          Authentication Methods
                    – Form
                    – Basic
                    – Digest
                    – Client-Cert




8   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
        Authentication Continued…
          Specify the protected resources
                    <security-constraint>
                             <web-resource-collection>
                                 <url-pattern>/manager/*</url-pattern>
                                 <http-method>GET</http-method>
                                 <http-method>POST</http-method>
                             </web-resource-collection>
                             <auth-constraint>
                                 <role-name>manager</role-name>                Specify the permitted role/s
                             </auth-constraint>
                    <user-data-constraint>
                     <transport-guarantee>CONFIDENTIAL</transport-guarantee>
                                                                                Specify the transport guarantee
                    </user-data-constraint>                                     level
                    </security-constraint>




9   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
          Authentication Continued…


      Specify the login configuration
     <login-config>
           <auth-method>FORM</auth-method>
           <realm-name>jdbc-realm</realm-name>
                                                                             Pick one of:
     </login-config>                                                             •   HTTP Basic Authentication: BASIC
                                                                                 •   Digest Authentication: DIGEST
                                                                                 •   HTTPS Client Authentication:
                                                                                     CLIENT-CERT
                                                                                 •   Form-Based Authentication:
                                                                                     FORM

                                                                               Specify the security realm name

10    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
         Got your own way of authenticating?


          Use programmatic login in Java EE 6
           Benefit from all that container security provides
                     – Principal propagation
                     – Unified security exceptions
                     – Any auditing/logging that container provides
                     – Authenticate against the configured realm
           Do more than just two tokens (multi factor authentication)
                     – Mix and match 3rd soft tokens with username/passwords


11   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
         Got your own way of authenticating?
      String userName = request.getParameter("user");
      String password = request.getParameter("password");
      String enteredSmsCode = request.getParameter("enteredSms");
      if(enteredSmsCode.equals(getLastActiveSmsForUser(userName))){
      try {
         request.login(userName, password);
         }
      catch(ServletException ex) {
           //Handling Exception
          }
      }
      else{
      invalidateLastSmsForUser(userName);
      }


12   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
To wrap it up
         The web.xml, *-web.xml security related structure, role mapping




13   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
          Security related methods on HTTPServletRequest
     Method                                                                  Description
                                                                             If the user is authenticated returns the username otherwise return null.

     String getRemoteUser()

 boolean isUserInRole(String role)                                           Return whether the current user has the specified roles or not.


 Principal getUserPrincipal()                                                Returns a java.security.Principal object containing the name of the
                                                                             current authenticated user.
 String getAuthType()                                                        Returns an String containing authentication method used to protect this
                                                                             application.
 void login(String username, String password) Perform the explained programmatic login


 Void logout()                                                               Establish null as the value returned when getUserPrincipal,
                                                                             getRemoteUser, and getAuthType is called on the request.
 String getScheme()                                                          Returns the schema portion of the URL, for example HTTP or HTTPS.


14    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
         Authorization (Access Control)


          Now that you established the user identity we can Enforce access
          control:
                     – Using Annotations to annotate the permitted and not permitted roles
                     – Using XML Description to specify the permitted and not permitted roles




15   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
         Authorization (Access Control): Security constraints (Web, EJB..)
                         Annotation                                         Description
                                                                            Prior to referencing to any role, it should be defined. The
                         @DeclareRoles                                      @DeclareRoles acts like security-role element in defining
                                                                            the roles used in application.

                         @RunAs                                             Specifies the run-as role for the given Components.

                         @ServletSecurity                                   Specifies the security constraint for the annotated Servlet.
                                                                            Permitting users with any role to access the given method,
                         @PermitAll
                                                                            EJB or Servlet
                                                                            On method permits the included roles to invoke it. On class,
                         @RolesAllowed                                      all methods are accessible to the roles unless the annotated
                                                                            with a different set of roles using @RolesAllowed

                                                                            On a method.
                         @DenyAll



16   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
         Where to place the Annotations?
                         Annotation                                         Target Level    Target Kind
                                                                                            EJB, Servlet
                         @DeclareRoles                                      Class


                                                                                            EJB, Servlet
                         @RunAs                                             Class

                         @ServletSecurity                                   Class           Servlet

                         @PermitAll                                         Class, Method   EJB, Servlet

                         @RolesAllowed                                      Class, Method   EJB, Servlet


                         @DenyAll                                           Method          EJB, Servlet




17   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security API
         Transport Security


           Apply right level of transport security on your resources
                     – CONFIDENTIAL
                     – INTEGRAL
           Use as much strengths as needed, the best is not always the best
           Check country regulation before choosing cipher suites




18   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Is that all that we can do?



                                                                            No,
                             There are much more…

19   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         What JSR-196 is…
           SPI for integrating authentication mechanism implementations in
            message processing runtimes
           Authentication is delegated to the corresponding provider at message
            processing points
           Develop authentication modules that utilize non supported credentials
            or headers
           Utilize the Container security integration
           Can plug-in off the shelf 3rd party Authentication Module implementing
            JSR-196
20   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         Message interception points
           In the client, before transmitting the request to the server.
           In the server, before the target service receives the client request.
           In the server, before a response can be sent back to the client.
           In the client, before the server response can be consumed.




21   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         How you can benefit from it
           Integrate any COTS authentication module
           Develop your own credentials and use them for authentication
           Benefit from container provided security
                     – Access control
                     – Subject propagation
                     – Unified error messages
                     – Auditing
                     – Etc


22   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         The good part, the SPI…
           The interface is javax.security.auth.message.module.ServerAuthModule
           An overall of 5 methods to implement
                     – 2 directly from javax.security.auth.message.module.ServerAuthModule
                     – 3 derived from javax.security.auth.message.ServerAuth
           Implementation can be plugged to the container
           Implementation can be used by the web apps
           Supported by any Java EE 6 compliant app server



23   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         2 directly from ServerAuthModule
          void initialize(MessagePolicy requestPolicy, MessagePolicy
          responsePolicy, CallbackHandler handler, Map options)
                     – Called for each authentication event
                     – requestPolicy and responsePolicy specifies if authentication is
                            mandatory or not
                     – handler communicate the user and group principals to be used in
                            establishing the runtime's security context
                     – options coming from the container for having parameterized behavior in
                            the SAM module.


24   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         2 directly from ServerAuthModule
          Class[] getSupportedMessageTypes()
           Returns an array of the supported message type class names.
                     – HttpServletRequest.class
                     – HttpServletResponse.class




25   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         3 derived from javax.security.auth.message.ServerAuth
          AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
          Subject serviceSubject)
                     – Custom credential scraping and/or authentication happens here
                     – Communicate authentication result and/or identity assertions to the
                            message processing runtime through callbackHandler.




26   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         3 derived from javax.security.auth.message.ServerAuth
         AuthStatus secureResponse(MessageInfo messageInfo, Subject
         serviceSubject)
                     – Nothing much to do here for servlet profile
                     – Usually return return AuthStatus.SEND_SUCCESS;




27   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         3 derived from javax.security.auth.message.ServerAuth
          void cleanSubject(MessageInfo messageInfo, Subject subject)
           remove method specific principals and groups from the provided
            Subject
           Update the messageInfo if needed for multi step message exchange




28   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         GlassFish and JSR-196, Install it in the domain
     Create a new provider under Security>Message Security>HttpServlet




29   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authentication Service Provider Interface
         (JSR-196)
         GlassFish and JSR-196


           Use it for one web application if not made default
                     – Use the httpservlet-security-provider attribute of glassfish-web.xml’s sun-
                            web-app element
           And you are done!                                               <glassfish-web-app httpservlet-security-provider="new-
                                                                            sam">
                                                                              <security-role-mapping>
                                                                                <role-name>role_1</role-name>
                                                                                <group-name>group_1</group-name>
                                                                              </security-role-mapping>
                                                                            </glassfish-web-app>




30   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authorization Contract for Containers
         (JSR-115)
         What is JSR-115
           To plug a new access control mechanism to the container
           Container delegates access control decision to the provider
           Use the same role mapping that is supported by Java EE
           Correlates with Authentication mechanism (Subject’s role)




31   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authorization Contract for Containers
         (JSR-115)
         How you can benefit from it
           Add a new decision making mechanism:
                     – Add time of the day to decision making
                     – Use a different type of policy storage
                     – etc




32   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authorization Contract for Containers
         (JSR-115)
         The good part, the SPI…
           Mainly two classes should be implanted by provider:
                     – javax.security.jacc.PolicyConfigurationFactory
                     – javax.security.jacc.PolicyConfiguration
           If it is not compliant with default Java SE policy should implement
                     – java.security.Policy
           The rest is already done by the container!




33   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Authorization Contract for Containers
         (JSR-115)
         To install a new provider
           Under Server-Config or any other config node:
                     – Create new entry under Security>JACC Provider
                     – Select the newly installed provider under Security




34   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Are there more basics to know:



                                                                            Yes,
                                                                OWASP Top 10

35   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security, GlassFish
         Things to remember:


           Comparative data should be stored salted hashed
           Encrypted data does not need to have clear text copies
           Keys must be protected properly
           Use security manager and policy files
           Avoid forward, redirect based on user provided values
           Paying enough attention to role mappings
           Choose the right security realm



36   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security, GlassFish
         Things to remember:


           Watch out for SQL injection, limit database access, use bind
            parameters, etc.
           Understand what you are storing in the session
           Never store unencrypted cookies with important bits
           Transmit cookies securely when needed Cookie.setSecure(true)




37   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java EE Security, GlassFish
         Things to remember:


           To use service specific user in the os
           To use security manager and policy files
           To properly configuring the listeners
           Not to use the alias feature
           Not to Use default accounts (admin accounts)
           To Check the OWASP top 10 talk, and resources




38   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
39   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Mais conteúdo relacionado

Mais procurados

Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJini Lee
 
Iiw2007b Madsen 01
Iiw2007b Madsen 01Iiw2007b Madsen 01
Iiw2007b Madsen 01Paul Madsen
 
What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013Jagadish Prasath
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012Arun Gupta
 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7Bruno Borges
 
What's new in Java Message Service 2?
What's new in Java Message Service 2?What's new in Java Message Service 2?
What's new in Java Message Service 2?Sivakumar Thyagarajan
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformArun Gupta
 
Java Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityJava Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityIMC Institute
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Hamed Hatami
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudArun Gupta
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nationArun Gupta
 
Java EE7 in action
Java EE7 in actionJava EE7 in action
Java EE7 in actionAnkara JUG
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
Ejb 3.0 Runtime Environment
Ejb 3.0 Runtime EnvironmentEjb 3.0 Runtime Environment
Ejb 3.0 Runtime Environmentrradhak
 
XEO Framework - TDose 2011
XEO Framework - TDose 2011XEO Framework - TDose 2011
XEO Framework - TDose 2011Pedro
 
2012-03 MultiFactor Not Just For Auditors
2012-03 MultiFactor Not Just For Auditors2012-03 MultiFactor Not Just For Auditors
2012-03 MultiFactor Not Just For AuditorsRaleigh ISSA
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
Designing JEE Application Structure
Designing JEE Application StructureDesigning JEE Application Structure
Designing JEE Application Structureodedns
 
02 hibernateintroduction
02 hibernateintroduction02 hibernateintroduction
02 hibernateintroductionthirumuru2012
 

Mais procurados (20)

Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
Iiw2007b Madsen 01
Iiw2007b Madsen 01Iiw2007b Madsen 01
Iiw2007b Madsen 01
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013What's new in JMS 2.0 - OTN Bangalore 2013
What's new in JMS 2.0 - OTN Bangalore 2013
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7
 
What's new in Java Message Service 2?
What's new in Java Message Service 2?What's new in Java Message Service 2?
What's new in Java Message Service 2?
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 Platform
 
Java Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application SecurityJava Web Programming [9/9] : Web Application Security
Java Web Programming [9/9] : Web Application Security
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the Cloud
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
 
Java EE7 in action
Java EE7 in actionJava EE7 in action
Java EE7 in action
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Ejb 3.0 Runtime Environment
Ejb 3.0 Runtime EnvironmentEjb 3.0 Runtime Environment
Ejb 3.0 Runtime Environment
 
XEO Framework - TDose 2011
XEO Framework - TDose 2011XEO Framework - TDose 2011
XEO Framework - TDose 2011
 
2012-03 MultiFactor Not Just For Auditors
2012-03 MultiFactor Not Just For Auditors2012-03 MultiFactor Not Just For Auditors
2012-03 MultiFactor Not Just For Auditors
 
Understanding
Understanding Understanding
Understanding
 
Designing JEE Application Structure
Designing JEE Application StructureDesigning JEE Application Structure
Designing JEE Application Structure
 
02 hibernateintroduction
02 hibernateintroduction02 hibernateintroduction
02 hibernateintroduction
 

Destaque

Destaque (6)

Secure REST with JAX-RS
Secure REST with JAX-RSSecure REST with JAX-RS
Secure REST with JAX-RS
 
CRM 2.0 - Frameworks for Program Strategy
CRM 2.0 - Frameworks for Program StrategyCRM 2.0 - Frameworks for Program Strategy
CRM 2.0 - Frameworks for Program Strategy
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Mavenizing your Liferay project
Mavenizing your Liferay projectMavenizing your Liferay project
Mavenizing your Liferay project
 

Semelhante a Utilize the Full Power of GlassFish Server and Java EE Security

Introduction to PicketLink
Introduction to PicketLinkIntroduction to PicketLink
Introduction to PicketLinkJBUG London
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Matt Raible
 
securing-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdfsecuring-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdfjcarrey
 
securing-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdfsecuring-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdfjcarrey
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Matt Raible
 
JavaEE Security
JavaEE SecurityJavaEE Security
JavaEE SecurityAlex Kim
 
Java EE 8 security and JSON binding API
Java EE 8 security and JSON binding APIJava EE 8 security and JSON binding API
Java EE 8 security and JSON binding APIAlex Theedom
 
Security As A Service
Security As A ServiceSecurity As A Service
Security As A Serviceguest536dd0e
 
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)Shing Wai Chan
 
Java EE Application Security With PicketLink
Java EE Application Security With PicketLinkJava EE Application Security With PicketLink
Java EE Application Security With PicketLinkpigorcraveiro
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0Bruno Borges
 
Security in java ee platform: what is included, what is missing
Security in java ee platform: what is included, what is missingSecurity in java ee platform: what is included, what is missing
Security in java ee platform: what is included, what is missingMasoud Kalali
 
State of the art authentication mit Java EE 8
State of the art authentication mit Java EE 8State of the art authentication mit Java EE 8
State of the art authentication mit Java EE 8OPEN KNOWLEDGE GmbH
 
Troubleshooting Novell Access Manager 3.1
Troubleshooting Novell Access Manager 3.1Troubleshooting Novell Access Manager 3.1
Troubleshooting Novell Access Manager 3.1Novell
 
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8OPEN KNOWLEDGE GmbH
 
Application Services On The Web Sales Forcecom
Application Services On The Web Sales ForcecomApplication Services On The Web Sales Forcecom
Application Services On The Web Sales ForcecomQConLondon2008
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX London
 
Java ee 8 + security overview
Java ee 8 + security overviewJava ee 8 + security overview
Java ee 8 + security overviewRudy De Busscher
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
Session 8 Tp8
Session 8 Tp8Session 8 Tp8
Session 8 Tp8phanleson
 

Semelhante a Utilize the Full Power of GlassFish Server and Java EE Security (20)

Introduction to PicketLink
Introduction to PicketLinkIntroduction to PicketLink
Introduction to PicketLink
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
 
securing-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdfsecuring-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdf
 
securing-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdfsecuring-portlets-with-spring-security.pdf
securing-portlets-with-spring-security.pdf
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
 
JavaEE Security
JavaEE SecurityJavaEE Security
JavaEE Security
 
Java EE 8 security and JSON binding API
Java EE 8 security and JSON binding APIJava EE 8 security and JSON binding API
Java EE 8 security and JSON binding API
 
Security As A Service
Security As A ServiceSecurity As A Service
Security As A Service
 
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
 
Java EE Application Security With PicketLink
Java EE Application Security With PicketLinkJava EE Application Security With PicketLink
Java EE Application Security With PicketLink
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0
 
Security in java ee platform: what is included, what is missing
Security in java ee platform: what is included, what is missingSecurity in java ee platform: what is included, what is missing
Security in java ee platform: what is included, what is missing
 
State of the art authentication mit Java EE 8
State of the art authentication mit Java EE 8State of the art authentication mit Java EE 8
State of the art authentication mit Java EE 8
 
Troubleshooting Novell Access Manager 3.1
Troubleshooting Novell Access Manager 3.1Troubleshooting Novell Access Manager 3.1
Troubleshooting Novell Access Manager 3.1
 
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
STATE OF THE ART AUTHENTICATION MIT JAVA EE 8
 
Application Services On The Web Sales Forcecom
Application Services On The Web Sales ForcecomApplication Services On The Web Sales Forcecom
Application Services On The Web Sales Forcecom
 
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun GuptaJAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
JAX-RS 2.0: New and Noteworthy in RESTful Web Services API - Arun Gupta
 
Java ee 8 + security overview
Java ee 8 + security overviewJava ee 8 + security overview
Java ee 8 + security overview
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
Session 8 Tp8
Session 8 Tp8Session 8 Tp8
Session 8 Tp8
 

Mais de Masoud Kalali

Real world RESTful service development problems and solutions
Real world RESTful service development problems and solutionsReal world RESTful service development problems and solutions
Real world RESTful service development problems and solutionsMasoud Kalali
 
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EECON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EEMasoud Kalali
 
BOF 2193 - How to work from home effectively
BOF 2193 - How to work from home effectivelyBOF 2193 - How to work from home effectively
BOF 2193 - How to work from home effectivelyMasoud Kalali
 
Real-World RESTful Service Development Problems and Solutions
Real-World RESTful Service Development Problems and SolutionsReal-World RESTful Service Development Problems and Solutions
Real-World RESTful Service Development Problems and SolutionsMasoud Kalali
 
How to avoid top 10 security risks in Java EE applications and how to avoid them
How to avoid top 10 security risks in Java EE applications and how to avoid themHow to avoid top 10 security risks in Java EE applications and how to avoid them
How to avoid top 10 security risks in Java EE applications and how to avoid themMasoud Kalali
 
Confess 2013: OWASP Top 10 and Java EE security in practice
Confess 2013: OWASP Top 10 and Java EE security in practiceConfess 2013: OWASP Top 10 and Java EE security in practice
Confess 2013: OWASP Top 10 and Java EE security in practiceMasoud Kalali
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Masoud Kalali
 
Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881Masoud Kalali
 
An Overview of RUP methodology
An Overview of RUP methodologyAn Overview of RUP methodology
An Overview of RUP methodologyMasoud Kalali
 
An overview of software development methodologies.
An overview of software development methodologies.An overview of software development methodologies.
An overview of software development methodologies.Masoud Kalali
 
NIO.2, the I/O API for the future
NIO.2, the I/O API for the futureNIO.2, the I/O API for the future
NIO.2, the I/O API for the futureMasoud Kalali
 

Mais de Masoud Kalali (11)

Real world RESTful service development problems and solutions
Real world RESTful service development problems and solutionsReal world RESTful service development problems and solutions
Real world RESTful service development problems and solutions
 
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EECON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
 
BOF 2193 - How to work from home effectively
BOF 2193 - How to work from home effectivelyBOF 2193 - How to work from home effectively
BOF 2193 - How to work from home effectively
 
Real-World RESTful Service Development Problems and Solutions
Real-World RESTful Service Development Problems and SolutionsReal-World RESTful Service Development Problems and Solutions
Real-World RESTful Service Development Problems and Solutions
 
How to avoid top 10 security risks in Java EE applications and how to avoid them
How to avoid top 10 security risks in Java EE applications and how to avoid themHow to avoid top 10 security risks in Java EE applications and how to avoid them
How to avoid top 10 security risks in Java EE applications and how to avoid them
 
Confess 2013: OWASP Top 10 and Java EE security in practice
Confess 2013: OWASP Top 10 and Java EE security in practiceConfess 2013: OWASP Top 10 and Java EE security in practice
Confess 2013: OWASP Top 10 and Java EE security in practice
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
 
Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881Slides for the #JavaOne Session ID: CON11881
Slides for the #JavaOne Session ID: CON11881
 
An Overview of RUP methodology
An Overview of RUP methodologyAn Overview of RUP methodology
An Overview of RUP methodology
 
An overview of software development methodologies.
An overview of software development methodologies.An overview of software development methodologies.
An overview of software development methodologies.
 
NIO.2, the I/O API for the future
NIO.2, the I/O API for the futureNIO.2, the I/O API for the future
NIO.2, the I/O API for the future
 

Utilize the Full Power of GlassFish Server and Java EE Security

  • 1. 1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 2. Utilize the Full Power of GlassFish Server and Java EE Security Masoud Kalali Principal Member of Technical Staff - ORACLE Twitter: @MasoudKalali Blog: http://kalali.me 2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 3. Program Agenda  Introduction  Java EE Security API  Java Authentication Service Provider Interface (JSR- 196)  Java Authorization Contract for Containers (JSR-115) 3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 4. Introduction 4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 5. Java EE Security API Terms  A Subject: An individual identity which is to be authenticated.  A Group: Group of users with common permissions and access levels.  A Security Realm: Connects the application server identity storage.  A Role: A Java EE concept to define access levels  A Principal: Aka, A role attached to a authenticated subject  A Credential: Contains or references information used to authenticate a principal 5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 6. Java EE Security API Before anything else  Identify the sensitive data  Identify the roles having access to sensitive data  Identify resources representing sensitive data  Group the mentioned resources into meaningful sets And Document the above items! 6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 7. Java EE Security API Resource Protection  Authentication – At Web Container – Application Client Container  Authorization (Access Control) – At Web Container – EJB Container  Subject Propagation – From Web Container to EJB Container – From App Client To EJB container – EIS to Connector (inflow messages) 7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 8. Java EE Security API Authentication  When a protected resource is requested  Establish the client’s identity  Authentication Methods – Form – Basic – Digest – Client-Cert 8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 9. Java EE Security API Authentication Continued…  Specify the protected resources <security-constraint> <web-resource-collection> <url-pattern>/manager/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <auth-constraint> <role-name>manager</role-name> Specify the permitted role/s </auth-constraint> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> Specify the transport guarantee </user-data-constraint> level </security-constraint> 9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 10. Java EE Security API Authentication Continued…  Specify the login configuration <login-config> <auth-method>FORM</auth-method> <realm-name>jdbc-realm</realm-name> Pick one of: </login-config> • HTTP Basic Authentication: BASIC • Digest Authentication: DIGEST • HTTPS Client Authentication: CLIENT-CERT • Form-Based Authentication: FORM Specify the security realm name 10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 11. Java EE Security API Got your own way of authenticating? Use programmatic login in Java EE 6  Benefit from all that container security provides – Principal propagation – Unified security exceptions – Any auditing/logging that container provides – Authenticate against the configured realm  Do more than just two tokens (multi factor authentication) – Mix and match 3rd soft tokens with username/passwords 11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 12. Java EE Security API Got your own way of authenticating? String userName = request.getParameter("user"); String password = request.getParameter("password"); String enteredSmsCode = request.getParameter("enteredSms"); if(enteredSmsCode.equals(getLastActiveSmsForUser(userName))){ try { request.login(userName, password); } catch(ServletException ex) { //Handling Exception } } else{ invalidateLastSmsForUser(userName); } 12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 13. To wrap it up The web.xml, *-web.xml security related structure, role mapping 13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 14. Java EE Security API Security related methods on HTTPServletRequest Method Description If the user is authenticated returns the username otherwise return null. String getRemoteUser() boolean isUserInRole(String role) Return whether the current user has the specified roles or not. Principal getUserPrincipal() Returns a java.security.Principal object containing the name of the current authenticated user. String getAuthType() Returns an String containing authentication method used to protect this application. void login(String username, String password) Perform the explained programmatic login Void logout() Establish null as the value returned when getUserPrincipal, getRemoteUser, and getAuthType is called on the request. String getScheme() Returns the schema portion of the URL, for example HTTP or HTTPS. 14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 15. Java EE Security API Authorization (Access Control) Now that you established the user identity we can Enforce access control: – Using Annotations to annotate the permitted and not permitted roles – Using XML Description to specify the permitted and not permitted roles 15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 16. Java EE Security API Authorization (Access Control): Security constraints (Web, EJB..) Annotation Description Prior to referencing to any role, it should be defined. The @DeclareRoles @DeclareRoles acts like security-role element in defining the roles used in application. @RunAs Specifies the run-as role for the given Components. @ServletSecurity Specifies the security constraint for the annotated Servlet. Permitting users with any role to access the given method, @PermitAll EJB or Servlet On method permits the included roles to invoke it. On class, @RolesAllowed all methods are accessible to the roles unless the annotated with a different set of roles using @RolesAllowed On a method. @DenyAll 16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 17. Java EE Security API Where to place the Annotations? Annotation Target Level Target Kind EJB, Servlet @DeclareRoles Class EJB, Servlet @RunAs Class @ServletSecurity Class Servlet @PermitAll Class, Method EJB, Servlet @RolesAllowed Class, Method EJB, Servlet @DenyAll Method EJB, Servlet 17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 18. Java EE Security API Transport Security  Apply right level of transport security on your resources – CONFIDENTIAL – INTEGRAL  Use as much strengths as needed, the best is not always the best  Check country regulation before choosing cipher suites 18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 19. Is that all that we can do? No, There are much more… 19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 20. Java Authentication Service Provider Interface (JSR-196) What JSR-196 is…  SPI for integrating authentication mechanism implementations in message processing runtimes  Authentication is delegated to the corresponding provider at message processing points  Develop authentication modules that utilize non supported credentials or headers  Utilize the Container security integration  Can plug-in off the shelf 3rd party Authentication Module implementing JSR-196 20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 21. Java Authentication Service Provider Interface (JSR-196) Message interception points  In the client, before transmitting the request to the server.  In the server, before the target service receives the client request.  In the server, before a response can be sent back to the client.  In the client, before the server response can be consumed. 21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 22. Java Authentication Service Provider Interface (JSR-196) How you can benefit from it  Integrate any COTS authentication module  Develop your own credentials and use them for authentication  Benefit from container provided security – Access control – Subject propagation – Unified error messages – Auditing – Etc 22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 23. Java Authentication Service Provider Interface (JSR-196) The good part, the SPI…  The interface is javax.security.auth.message.module.ServerAuthModule  An overall of 5 methods to implement – 2 directly from javax.security.auth.message.module.ServerAuthModule – 3 derived from javax.security.auth.message.ServerAuth  Implementation can be plugged to the container  Implementation can be used by the web apps  Supported by any Java EE 6 compliant app server 23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 24. Java Authentication Service Provider Interface (JSR-196) 2 directly from ServerAuthModule void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler, Map options) – Called for each authentication event – requestPolicy and responsePolicy specifies if authentication is mandatory or not – handler communicate the user and group principals to be used in establishing the runtime's security context – options coming from the container for having parameterized behavior in the SAM module. 24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 25. Java Authentication Service Provider Interface (JSR-196) 2 directly from ServerAuthModule Class[] getSupportedMessageTypes()  Returns an array of the supported message type class names. – HttpServletRequest.class – HttpServletResponse.class 25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 26. Java Authentication Service Provider Interface (JSR-196) 3 derived from javax.security.auth.message.ServerAuth AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) – Custom credential scraping and/or authentication happens here – Communicate authentication result and/or identity assertions to the message processing runtime through callbackHandler. 26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 27. Java Authentication Service Provider Interface (JSR-196) 3 derived from javax.security.auth.message.ServerAuth AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) – Nothing much to do here for servlet profile – Usually return return AuthStatus.SEND_SUCCESS; 27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 28. Java Authentication Service Provider Interface (JSR-196) 3 derived from javax.security.auth.message.ServerAuth void cleanSubject(MessageInfo messageInfo, Subject subject)  remove method specific principals and groups from the provided Subject  Update the messageInfo if needed for multi step message exchange 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 29. Java Authentication Service Provider Interface (JSR-196) GlassFish and JSR-196, Install it in the domain Create a new provider under Security>Message Security>HttpServlet 29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 30. Java Authentication Service Provider Interface (JSR-196) GlassFish and JSR-196  Use it for one web application if not made default – Use the httpservlet-security-provider attribute of glassfish-web.xml’s sun- web-app element  And you are done! <glassfish-web-app httpservlet-security-provider="new- sam"> <security-role-mapping> <role-name>role_1</role-name> <group-name>group_1</group-name> </security-role-mapping> </glassfish-web-app> 30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 31. Java Authorization Contract for Containers (JSR-115) What is JSR-115  To plug a new access control mechanism to the container  Container delegates access control decision to the provider  Use the same role mapping that is supported by Java EE  Correlates with Authentication mechanism (Subject’s role) 31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 32. Java Authorization Contract for Containers (JSR-115) How you can benefit from it  Add a new decision making mechanism: – Add time of the day to decision making – Use a different type of policy storage – etc 32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 33. Java Authorization Contract for Containers (JSR-115) The good part, the SPI…  Mainly two classes should be implanted by provider: – javax.security.jacc.PolicyConfigurationFactory – javax.security.jacc.PolicyConfiguration  If it is not compliant with default Java SE policy should implement – java.security.Policy  The rest is already done by the container! 33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 34. Java Authorization Contract for Containers (JSR-115) To install a new provider  Under Server-Config or any other config node: – Create new entry under Security>JACC Provider – Select the newly installed provider under Security 34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 35. Are there more basics to know: Yes, OWASP Top 10 35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 36. Java EE Security, GlassFish Things to remember:  Comparative data should be stored salted hashed  Encrypted data does not need to have clear text copies  Keys must be protected properly  Use security manager and policy files  Avoid forward, redirect based on user provided values  Paying enough attention to role mappings  Choose the right security realm 36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 37. Java EE Security, GlassFish Things to remember:  Watch out for SQL injection, limit database access, use bind parameters, etc.  Understand what you are storing in the session  Never store unencrypted cookies with important bits  Transmit cookies securely when needed Cookie.setSecure(true) 37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 38. Java EE Security, GlassFish Things to remember:  To use service specific user in the os  To use security manager and policy files  To properly configuring the listeners  Not to use the alias feature  Not to Use default accounts (admin accounts)  To Check the OWASP top 10 talk, and resources 38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 39. 39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.