SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
Securing RESTful 
Resources with OAuth2 
Rodrigo Cândido da Silva 
@rcandidosilva 
JavaOne 2014 
CON4990
About Me 
• Brazilian guy ;) 
• Software Architect 
• Java Platform 
• Work for Integritas Tech 
• http://integritastech.com 
• JUG Leader of GUJavaSC 
• http://gujavasc.org 
• Twitter 
• @rcandidosilva 
• Personal 
• http://rodrigocandido.me
Agenda 
• Why use OAuth2? 
• OAuth2 concepts 
• Grant types 
• OAuth2 Tokens 
• Java Implementations 
• Demo
Public Web Service API’s
Security 
Closed 
Closed 
Open 
Authentication Authorization
Securing APIs 
• Securing resources strategies 
• Basic Auth (HTTP Basic) 
• Sending user credentials in http authentication header 
• Mutual Authentication (HTTP Digest) 
• Based on certificates, server authenticate to client, client to server 
• RESTful architecture not defines security procedures 
• HTTP methods: GET, POST, PUT, DELETE 
• REST API’s are equal vulnerable as standard web apps 
• Injection attacks, replay attacks, cross-site scripting, etc.
Without OAuth
With OAuth
Why OAuth 
• Open standard protocol specification defined by IETF 
• Enables applications to access each other’s data without 
sharing credentials 
• Avoid password issues 
• User and password authentication is fine, but what if your API 
needs to be used by other apps? 
• Required for delegating access 
• Third party applications 
• For specified resource 
• For limited time 
• Can be selectively be revoked
Who is using OAuth
OAuth Timeline 
• OAuth 1.0 
• Core specification published in Dec 2007 
• OAuth 1.0a 
• Revised specification published in June 2009 
• Related to fix a security issue 
• OAuth 2.0 
• Standardized since Oct-2012 
• Be more secure, simple, and standard 
• Additional RFCs are still being worked on
OAuth2 
• No username or passwords (only tokens) 
• Protocol for authorization – not authentication 
• Delegated model 
• Fix the password anti-pattern 
• Trust relationship between resource, identity server and client app 
• Goal was simplicity 
• Relies heavily on TLS/SSL 
• Not backwards compatible 
• Easily to revoke
OAuth2 Roles 
• Resource Owner 
• Entity capable of granting 
access to a protected resource 
• Client Application 
• Application making protected resource requests on behalf of 
the resource owner 
• Resource Server 
• The server hosting the protected resources 
• Authorization Server 
• The server issuing access tokens to the clients
OAuth2 Basic Flow
OAuth2 Grant Types 
• Authorization Code (web apps) 
• Optimized for confidential clients 
• Uses a authorization code from the server 
• Implicit (browser-based and mobile apps) 
• Optimized for script heavy web apps 
• User can see the access token 
• Resource Owner Password Credentials (user / password) 
• Used in cases where the user trusts the client 
• Exposes user credentials to the client 
• Client Credentials (application) 
• Clients gets an access token based on client credentials only
Authorization Code
Implicit
Resource Owner Password Credentials
Client Credentials
OAuth2 Tokens 
• Types 
• Bearer 
• Large random token 
• Need SSL to protect it in transit 
• Server needs to store it securely hashed like a user password 
• Mac 
• Uses a nonce to prevent replay 
• Does not required SSL 
• OAuth 1.0 only supported 
• Access Token 
• Short-lived token 
• Refresh Token 
• Long-lived token 
{ 
"access_token":"2YotnFZFEjr1zCsicMWpAA", 
"token_type":“bearer", 
"expires_in":3600, 
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA", 
}
OAuth2 Pros & Cons 
• Pros 
• Integration of third party apps to any sites 
• Access can be granted for limited scope or duration 
• No need for users to give password on third party 
site 
• Cons 
• Writing an authorization server is somewhat 
complex 
• Interoperability issues 
• Bad implementations can be security issues
OAuth2 Java Implementations 
• Some Java implementations available 
• Jersey 
• Apache Oltu 
• Spring Security OAuth2 
• And others: CXF, Google OAuth2 API, etc 
• Not available as Java EE standard yet
Jersey 
• Open source RESTful Web services framework 
• The JAX-RS reference implementation 
• Integrates with the Java EE standard security 
• @RolesAllowed 
• @PermitAll 
• @DenyAll 
• Supports entity filtering features 
• @EntityFiltering 
• Only supports OAuth2 at client side :/
Jersey 
Java EE security integration 
@Path("restricted-resource") 
@Produces("application/json") 
public class RestrictedResource { 
@GET @Path(”denyAll") 
@DenyAll 
public RestrictedEntity denyAll() { ... } 
@GET @Path("rolesAllowed") 
@RolesAllowed({"manager"}) 
public RestrictedEntity rolesAllowed() { ... } 
}
Jersey 
OAuth2 client support 
OAuth2CodeGrantFlow.Builder builder = 
OAuth2ClientSupport 
.authorizationCodeGrantFlowBuilder( 
clientId, 
"https://example.com/oauth/authorization", 
"https://example.com/oauth/token"); 
OAuth2CodeGrantFlow flow = builder.property( 
OAuth2CodeGrantFlow.Phase.AUTHORIZATION, 
"readOnly", "true") 
.scope("contact") 
.build(); 
String authorizationUri = flow.start(); 
... 
final TokenResult result = flow.finish(code, state); 
...
Apache Oltu 
• Apache OAuth protocol implementation 
• It also covers others related implementations 
• JSON Web Token (JWT) 
• JSON Web Signature (JWS) 
• OpenID Connect 
• Supports the full OAuth2 features 
• Authorization Server 
• Resource Server 
• Client 
• Provides predefined OAuth2 client types 
• Facebook, Foursquare, Github, Google, etc 
• Still being improved…
Apache Oltu 
Authorization endpoint 
protected void doGet(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException { 
//dynamically recognize an OAuth profile and perform validation 
OAuthAuthzRequest oauthRequest = new OAuthAuthzRequest(request); 
validateRedirectionURI(oauthRequest) 
//build OAuth response 
OAuthResponse resp = OAuthASResponse 
.authorizationResponse(HttpServletResponse.SC_FOUND) 
.setCode(oauthIssuerImpl.authorizationCode()) 
.location(ex.getRedirectUri()) 
.buildQueryMessage(); 
response.sendRedirect(resp.getLocationUri()); 
}
Apache Oltu 
Token endpoint 
protected void doPost(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException { 
OAuthIssuer oauthIssuerImpl = 
new OAuthIssuerImpl(new MD5Generator()); 
OAuthTokenRequest oauthRequest = 
new OAuthTokenRequest(request); 
validateClient(oauthRequest); 
String authzCode = oauthRequest.getCode(); 
String accessToken = oauthIssuerImpl.accessToken(); 
String refreshToken = oauthIssuerImpl.refreshToken(); 
OAuthResponse r = OAuthASResponse(...); 
}
Apache Oltu 
Protecting the resources 
protected void doGet(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException { 
// Make the OAuth Request and validate it 
OAuthAccessResourceRequest oauthRequest = new 
OAuthAccessResourceRequest(request, 
ParameterStyle.BODY); 
// Get the access token 
String accessToken = 
oauthRequest.getAccessToken(); 
//... validate access token 
}
Apache Oltu 
OAuth2 client 
OAuthClientRequest request = OAuthClientRequest 
.tokenProvider(OAuthProviderType.FACEBOOK) 
.setGrantType(GrantType.AUTHORIZATION_CODE) 
.setClientId("your-facebook-application-client-id") 
.setClientSecret("your-facebook-application-client-secret") 
.setRedirectURI("http://www.example.com/redirect") 
.setCode(code) 
.buildQueryMessage(); 
//create OAuth client that uses custom http client under the hood 
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); 
OAuthAccessTokenResponse oAuthResponse = 
oAuthClient.accessToken(request); 
String accessToken = oAuthResponse.getAccessToken(); 
String expiresIn = oAuthResponse.getExpiresIn();
Spring Security OAuth 
• Provides OAuth (1a) and OAuth2 support 
• Implements 4 types of authorization grants 
• Supports the OAuth2 full features 
• Authorization Server 
• Resources Server 
• Client 
• Good integration with JAX-RS and Spring MVC 
• Configuration using annotation support 
• Integrates with the Spring ecosystem
Spring Authorization Server 
• @EnableAuthorizationServer 
• Annotation used to configure OAuth2 authorization server 
• There is also XML configuration related <authorization-server/> 
• ClientDetailsServiceConfigurer 
• Defines the client details service 
• In-memory or JDBC implementation 
• AuthorizationServerTokenServices 
• Operations to manage OAuth2 tokens 
• Tokens in-memory, JDBC or JSON Web Token (JWT) 
• AuthorizationServerEndpointConfigurer 
• Grant types supported by the server 
• All grant types are supported except password types
Spring Resource Server 
• Can be the same as Authorization Server 
• Or deployed in a separate application 
• Provides a authentication filter for web protection 
• @EnableResourceServer 
• Annotation used to configure OAuth2 resource server 
• There is also XML configuration related <resource-server/> 
• Supports expression-based access control 
• #oauth2.clientHasRole 
• #oauth2.clientHasAnyRole 
• #oauth2.denyClient
Spring OAuth2 Client 
• Creates a filter to store the current request and context 
• Manages the redirection to and from the OAuth 
authentication URI 
• @EnableOAuth2Client 
• Annotation used to configure OAuth2 client 
• There is also XML configuration related <client/> 
• OAuth2RestTemplate 
• Wrapper client object to access the resources
Demo 
• OAuth2 Use Case 
• Conference application sharing resources with different clients 
• http://github.com/rcandidosilva/rest-oauth2-sample
Questions 
?
References 
• http://oauth.net/2/ 
• http://tools.ietf.org/html/rfc6749 
• http://projects.spring.io/spring-security-oauth/ 
• https://github.com/spring-projects/spring-security-oauth 
• http://cxf.apache.org/docs/jax-rs-oauth2.html 
• https://jersey.java.net/documentation/latest/security.html#d0e10940 
• https://oltu.apache.org
Thank you! 
@rcandidosilva 
rodrigocandido.me

Contenu connexe

Tendances

C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTDr. Awase Khirni Syed
 
INTRODUCTION TO IIS
INTRODUCTION TO IISINTRODUCTION TO IIS
INTRODUCTION TO IISsanya6900
 
Android Deep Linking
Android Deep Linking  Android Deep Linking
Android Deep Linking Ketan Raval
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014JWORKS powered by Ordina
 
Secure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with KeycloakSecure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with KeycloakRed Hat Developers
 
Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJSLuigi Saetta
 
REST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTsREST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTsJon Todd
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Mindfire Solutions
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start GuideAndrii Gakhov
 
Introduction to Docker Compose | Docker Intermediate Workshop
Introduction to Docker Compose | Docker Intermediate WorkshopIntroduction to Docker Compose | Docker Intermediate Workshop
Introduction to Docker Compose | Docker Intermediate WorkshopAjeet Singh Raina
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 

Tendances (20)

OAuth2 + API Security
OAuth2 + API SecurityOAuth2 + API Security
OAuth2 + API Security
 
C# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENTC# ASP.NET WEB API APPLICATION DEVELOPMENT
C# ASP.NET WEB API APPLICATION DEVELOPMENT
 
INTRODUCTION TO IIS
INTRODUCTION TO IISINTRODUCTION TO IIS
INTRODUCTION TO IIS
 
Android Deep Linking
Android Deep Linking  Android Deep Linking
Android Deep Linking
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Secure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with KeycloakSecure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with Keycloak
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Rest API with Swagger and NodeJS
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
 
REST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTsREST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTs
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
 
Maven
MavenMaven
Maven
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Swagger UI
Swagger UISwagger UI
Swagger UI
 
Introduction to Docker Compose | Docker Intermediate Workshop
Introduction to Docker Compose | Docker Intermediate WorkshopIntroduction to Docker Compose | Docker Intermediate Workshop
Introduction to Docker Compose | Docker Intermediate Workshop
 
How to implement Google One Tap Login in Reactjs?
How to implement Google One Tap Login in Reactjs?How to implement Google One Tap Login in Reactjs?
How to implement Google One Tap Login in Reactjs?
 
Packer
Packer Packer
Packer
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 

Similaire à JavaOne 2014 - Securing RESTful Resources with OAuth2

ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2Rodrigo Cândido da Silva
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authenticationjeremysbrown
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleMayank Sharma
 
OAuth 2.0 at the Globiots
OAuth 2.0 at the GlobiotsOAuth 2.0 at the Globiots
OAuth 2.0 at the GlobiotsTran Thanh Thi
 
Building an Effective Architecture for Identity and Access Management.pdf
Building an Effective Architecture for Identity and Access Management.pdfBuilding an Effective Architecture for Identity and Access Management.pdf
Building an Effective Architecture for Identity and Access Management.pdfJorge Alvarez
 
Authenticating Angular Apps with JWT
Authenticating Angular Apps with JWTAuthenticating Angular Apps with JWT
Authenticating Angular Apps with JWTJennifer Estrada
 
REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!Stormpath
 
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"Andreas Falk
 
Introduction to sitecore identity
Introduction to sitecore identityIntroduction to sitecore identity
Introduction to sitecore identityGopikrishna Gujjula
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2Pratik Khasnabis
 
Authentication in microservice systems - fsto 2017
Authentication in microservice systems - fsto 2017Authentication in microservice systems - fsto 2017
Authentication in microservice systems - fsto 2017Dejan Glozic
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPRafal Gancarz
 
Adding Identity Management and Access Control to your App
Adding Identity Management and Access Control to your AppAdding Identity Management and Access Control to your App
Adding Identity Management and Access Control to your AppFIWARE
 
Introduction to OAuth
Introduction to OAuthIntroduction to OAuth
Introduction to OAuthWei-Tsung Su
 
Java EE Security API - JSR375: Getting Started
Java EE Security API - JSR375: Getting Started Java EE Security API - JSR375: Getting Started
Java EE Security API - JSR375: Getting Started Rudy De Busscher
 
Adding identity management and access control to your app
Adding identity management and access control to your appAdding identity management and access control to your app
Adding identity management and access control to your appÁlvaro Alonso González
 
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization ServerGetting Started with Spring Authorization Server
Getting Started with Spring Authorization ServerVMware Tanzu
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJSrobertjd
 

Similaire à JavaOne 2014 - Securing RESTful Resources with OAuth2 (20)

ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authentication
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 Module
 
OAuth 2.0 at the Globiots
OAuth 2.0 at the GlobiotsOAuth 2.0 at the Globiots
OAuth 2.0 at the Globiots
 
Building an Effective Architecture for Identity and Access Management.pdf
Building an Effective Architecture for Identity and Access Management.pdfBuilding an Effective Architecture for Identity and Access Management.pdf
Building an Effective Architecture for Identity and Access Management.pdf
 
Authenticating Angular Apps with JWT
Authenticating Angular Apps with JWTAuthenticating Angular Apps with JWT
Authenticating Angular Apps with JWT
 
REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!REST API Security: OAuth 2.0, JWTs, and More!
REST API Security: OAuth 2.0, JWTs, and More!
 
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
 
Introduction to sitecore identity
Introduction to sitecore identityIntroduction to sitecore identity
Introduction to sitecore identity
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2
 
Authentication in microservice systems - fsto 2017
Authentication in microservice systems - fsto 2017Authentication in microservice systems - fsto 2017
Authentication in microservice systems - fsto 2017
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
Adding Identity Management and Access Control to your App
Adding Identity Management and Access Control to your AppAdding Identity Management and Access Control to your App
Adding Identity Management and Access Control to your App
 
Introduction to OAuth
Introduction to OAuthIntroduction to OAuth
Introduction to OAuth
 
Api security
Api security Api security
Api security
 
Java EE Security API - JSR375: Getting Started
Java EE Security API - JSR375: Getting Started Java EE Security API - JSR375: Getting Started
Java EE Security API - JSR375: Getting Started
 
Adding identity management and access control to your app
Adding identity management and access control to your appAdding identity management and access control to your app
Adding identity management and access control to your app
 
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization ServerGetting Started with Spring Authorization Server
Getting Started with Spring Authorization Server
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJS
 
OAuth2
OAuth2OAuth2
OAuth2
 

Plus de Rodrigo Cândido da Silva

Protegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de ImplementaçãoProtegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de ImplementaçãoRodrigo Cândido da Silva
 
Protecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and StrategiesProtecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and StrategiesRodrigo Cândido da Silva
 
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e KubernetesWorkshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e KubernetesRodrigo Cândido da Silva
 
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSSWorkshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSSRodrigo Cândido da Silva
 
Workshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring BootWorkshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring BootRodrigo Cândido da Silva
 
Workshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura MicroservicesWorkshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura MicroservicesRodrigo Cândido da Silva
 
TDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com JavaTDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com JavaRodrigo Cândido da Silva
 
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOpsGUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOpsRodrigo Cândido da Silva
 
GUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com JavaGUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com JavaRodrigo Cândido da Silva
 
JavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EEJavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EERodrigo Cândido da Silva
 
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EEJavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EERodrigo Cândido da Silva
 
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data RESTJavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data RESTRodrigo Cândido da Silva
 
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring CloudTDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring CloudRodrigo Cândido da Silva
 
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...Rodrigo Cândido da Silva
 
QCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EEQCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EERodrigo Cândido da Silva
 

Plus de Rodrigo Cândido da Silva (20)

Java 9, 10 e ... 11
Java 9, 10 e ... 11Java 9, 10 e ... 11
Java 9, 10 e ... 11
 
Cloud Native Java EE
Cloud Native Java EECloud Native Java EE
Cloud Native Java EE
 
Protegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de ImplementaçãoProtegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de Implementação
 
Protecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and StrategiesProtecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and Strategies
 
As novidades da nova versão do Java 9
As novidades da nova versão do Java 9As novidades da nova versão do Java 9
As novidades da nova versão do Java 9
 
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e KubernetesWorkshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
 
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSSWorkshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
 
Workshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring BootWorkshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring Boot
 
Workshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura MicroservicesWorkshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura Microservices
 
GUJavaSC - Protegendo Microservices em Java
GUJavaSC - Protegendo Microservices em JavaGUJavaSC - Protegendo Microservices em Java
GUJavaSC - Protegendo Microservices em Java
 
TDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com JavaTDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com Java
 
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOpsGUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
 
GUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com JavaGUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com Java
 
JavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EEJavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EE
 
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EEJavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
 
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data RESTJavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
 
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring CloudTDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
 
GUJavaSC - Combinando AngularJS com Java EE
GUJavaSC - Combinando AngularJS com Java EEGUJavaSC - Combinando AngularJS com Java EE
GUJavaSC - Combinando AngularJS com Java EE
 
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
 
QCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EEQCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EE
 

Dernier

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Dernier (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

JavaOne 2014 - Securing RESTful Resources with OAuth2

  • 1. Securing RESTful Resources with OAuth2 Rodrigo Cândido da Silva @rcandidosilva JavaOne 2014 CON4990
  • 2. About Me • Brazilian guy ;) • Software Architect • Java Platform • Work for Integritas Tech • http://integritastech.com • JUG Leader of GUJavaSC • http://gujavasc.org • Twitter • @rcandidosilva • Personal • http://rodrigocandido.me
  • 3. Agenda • Why use OAuth2? • OAuth2 concepts • Grant types • OAuth2 Tokens • Java Implementations • Demo
  • 5. Security Closed Closed Open Authentication Authorization
  • 6. Securing APIs • Securing resources strategies • Basic Auth (HTTP Basic) • Sending user credentials in http authentication header • Mutual Authentication (HTTP Digest) • Based on certificates, server authenticate to client, client to server • RESTful architecture not defines security procedures • HTTP methods: GET, POST, PUT, DELETE • REST API’s are equal vulnerable as standard web apps • Injection attacks, replay attacks, cross-site scripting, etc.
  • 9. Why OAuth • Open standard protocol specification defined by IETF • Enables applications to access each other’s data without sharing credentials • Avoid password issues • User and password authentication is fine, but what if your API needs to be used by other apps? • Required for delegating access • Third party applications • For specified resource • For limited time • Can be selectively be revoked
  • 10. Who is using OAuth
  • 11. OAuth Timeline • OAuth 1.0 • Core specification published in Dec 2007 • OAuth 1.0a • Revised specification published in June 2009 • Related to fix a security issue • OAuth 2.0 • Standardized since Oct-2012 • Be more secure, simple, and standard • Additional RFCs are still being worked on
  • 12. OAuth2 • No username or passwords (only tokens) • Protocol for authorization – not authentication • Delegated model • Fix the password anti-pattern • Trust relationship between resource, identity server and client app • Goal was simplicity • Relies heavily on TLS/SSL • Not backwards compatible • Easily to revoke
  • 13. OAuth2 Roles • Resource Owner • Entity capable of granting access to a protected resource • Client Application • Application making protected resource requests on behalf of the resource owner • Resource Server • The server hosting the protected resources • Authorization Server • The server issuing access tokens to the clients
  • 15. OAuth2 Grant Types • Authorization Code (web apps) • Optimized for confidential clients • Uses a authorization code from the server • Implicit (browser-based and mobile apps) • Optimized for script heavy web apps • User can see the access token • Resource Owner Password Credentials (user / password) • Used in cases where the user trusts the client • Exposes user credentials to the client • Client Credentials (application) • Clients gets an access token based on client credentials only
  • 18. Resource Owner Password Credentials
  • 20. OAuth2 Tokens • Types • Bearer • Large random token • Need SSL to protect it in transit • Server needs to store it securely hashed like a user password • Mac • Uses a nonce to prevent replay • Does not required SSL • OAuth 1.0 only supported • Access Token • Short-lived token • Refresh Token • Long-lived token { "access_token":"2YotnFZFEjr1zCsicMWpAA", "token_type":“bearer", "expires_in":3600, "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA", }
  • 21. OAuth2 Pros & Cons • Pros • Integration of third party apps to any sites • Access can be granted for limited scope or duration • No need for users to give password on third party site • Cons • Writing an authorization server is somewhat complex • Interoperability issues • Bad implementations can be security issues
  • 22. OAuth2 Java Implementations • Some Java implementations available • Jersey • Apache Oltu • Spring Security OAuth2 • And others: CXF, Google OAuth2 API, etc • Not available as Java EE standard yet
  • 23. Jersey • Open source RESTful Web services framework • The JAX-RS reference implementation • Integrates with the Java EE standard security • @RolesAllowed • @PermitAll • @DenyAll • Supports entity filtering features • @EntityFiltering • Only supports OAuth2 at client side :/
  • 24. Jersey Java EE security integration @Path("restricted-resource") @Produces("application/json") public class RestrictedResource { @GET @Path(”denyAll") @DenyAll public RestrictedEntity denyAll() { ... } @GET @Path("rolesAllowed") @RolesAllowed({"manager"}) public RestrictedEntity rolesAllowed() { ... } }
  • 25. Jersey OAuth2 client support OAuth2CodeGrantFlow.Builder builder = OAuth2ClientSupport .authorizationCodeGrantFlowBuilder( clientId, "https://example.com/oauth/authorization", "https://example.com/oauth/token"); OAuth2CodeGrantFlow flow = builder.property( OAuth2CodeGrantFlow.Phase.AUTHORIZATION, "readOnly", "true") .scope("contact") .build(); String authorizationUri = flow.start(); ... final TokenResult result = flow.finish(code, state); ...
  • 26. Apache Oltu • Apache OAuth protocol implementation • It also covers others related implementations • JSON Web Token (JWT) • JSON Web Signature (JWS) • OpenID Connect • Supports the full OAuth2 features • Authorization Server • Resource Server • Client • Provides predefined OAuth2 client types • Facebook, Foursquare, Github, Google, etc • Still being improved…
  • 27. Apache Oltu Authorization endpoint protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //dynamically recognize an OAuth profile and perform validation OAuthAuthzRequest oauthRequest = new OAuthAuthzRequest(request); validateRedirectionURI(oauthRequest) //build OAuth response OAuthResponse resp = OAuthASResponse .authorizationResponse(HttpServletResponse.SC_FOUND) .setCode(oauthIssuerImpl.authorizationCode()) .location(ex.getRedirectUri()) .buildQueryMessage(); response.sendRedirect(resp.getLocationUri()); }
  • 28. Apache Oltu Token endpoint protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator()); OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request); validateClient(oauthRequest); String authzCode = oauthRequest.getCode(); String accessToken = oauthIssuerImpl.accessToken(); String refreshToken = oauthIssuerImpl.refreshToken(); OAuthResponse r = OAuthASResponse(...); }
  • 29. Apache Oltu Protecting the resources protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Make the OAuth Request and validate it OAuthAccessResourceRequest oauthRequest = new OAuthAccessResourceRequest(request, ParameterStyle.BODY); // Get the access token String accessToken = oauthRequest.getAccessToken(); //... validate access token }
  • 30. Apache Oltu OAuth2 client OAuthClientRequest request = OAuthClientRequest .tokenProvider(OAuthProviderType.FACEBOOK) .setGrantType(GrantType.AUTHORIZATION_CODE) .setClientId("your-facebook-application-client-id") .setClientSecret("your-facebook-application-client-secret") .setRedirectURI("http://www.example.com/redirect") .setCode(code) .buildQueryMessage(); //create OAuth client that uses custom http client under the hood OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient()); OAuthAccessTokenResponse oAuthResponse = oAuthClient.accessToken(request); String accessToken = oAuthResponse.getAccessToken(); String expiresIn = oAuthResponse.getExpiresIn();
  • 31. Spring Security OAuth • Provides OAuth (1a) and OAuth2 support • Implements 4 types of authorization grants • Supports the OAuth2 full features • Authorization Server • Resources Server • Client • Good integration with JAX-RS and Spring MVC • Configuration using annotation support • Integrates with the Spring ecosystem
  • 32. Spring Authorization Server • @EnableAuthorizationServer • Annotation used to configure OAuth2 authorization server • There is also XML configuration related <authorization-server/> • ClientDetailsServiceConfigurer • Defines the client details service • In-memory or JDBC implementation • AuthorizationServerTokenServices • Operations to manage OAuth2 tokens • Tokens in-memory, JDBC or JSON Web Token (JWT) • AuthorizationServerEndpointConfigurer • Grant types supported by the server • All grant types are supported except password types
  • 33. Spring Resource Server • Can be the same as Authorization Server • Or deployed in a separate application • Provides a authentication filter for web protection • @EnableResourceServer • Annotation used to configure OAuth2 resource server • There is also XML configuration related <resource-server/> • Supports expression-based access control • #oauth2.clientHasRole • #oauth2.clientHasAnyRole • #oauth2.denyClient
  • 34. Spring OAuth2 Client • Creates a filter to store the current request and context • Manages the redirection to and from the OAuth authentication URI • @EnableOAuth2Client • Annotation used to configure OAuth2 client • There is also XML configuration related <client/> • OAuth2RestTemplate • Wrapper client object to access the resources
  • 35. Demo • OAuth2 Use Case • Conference application sharing resources with different clients • http://github.com/rcandidosilva/rest-oauth2-sample
  • 37. References • http://oauth.net/2/ • http://tools.ietf.org/html/rfc6749 • http://projects.spring.io/spring-security-oauth/ • https://github.com/spring-projects/spring-security-oauth • http://cxf.apache.org/docs/jax-rs-oauth2.html • https://jersey.java.net/documentation/latest/security.html#d0e10940 • https://oltu.apache.org
  • 38. Thank you! @rcandidosilva rodrigocandido.me