SlideShare uma empresa Scribd logo
1 de 59
Simple Application Security
                   Les Hazlewood
         Apache Shiro Project Chair
                  CTO, Stormpath
What is Apache Shiro?
• Application security framework
• ASF TLP - http://shiro.apache.org
• Quick and Easy
• Simplifies Security Concepts & Design
Agenda

    Authentication   Authorization

      Session
                     Cryptography
    Management

             Web Support
          Auxiliary Features
Quick Terminology
• Subject – Security-specific user ‘view’

• Principals – Subject’s identifying attributes

• Credentials – Secret values that verify identity

• Realm – Security-specific DAO
Authentication

     Authentication   Authorization

       Session
                      Cryptography
     Management

              Web Support
           Auxiliary Features
Authentication Defined

Identity verification:

Proving a user is who he says he is
Shiro Authentication Features
• Subject-based (current user)
• Single method call

• Rich Exception Hierarchy

• ‘Remember Me’ built in

• Event listeners
How to Authenticate with Shiro

Steps

1. Collect principals & credentials

2. Submit to Authentication System

3. Allow, retry, or block access
Step 1: Collecting Principals & Credentials

UsernamePasswordToken token = new
  UsernamePasswordToken(username, password);

//”Remember Me” built-in:
token.setRememberMe(true);
Step 2: Submission
Subject currentUser =
  SecurityUtils.getSubject();

currentUser.login(token);
Step 3: Grant Access or Handle Failure
try {
currentUser.login(token);
} catch (UnknownAccountExceptionuae){ ...
} catch (IncorrectCredentialsException ice {
    ...
} catch ( LockedAccountExceptionlae ) { ...
} catch ( ExcessiveAttemptsExceptioneae ) { ...
} ... catch your own ...
} catch ( AuthenticationExceptionae ) {
    //unexpected error?
}
//No problems, show authenticated view…
How does it work?
           Subject .login(token)
How does it work?
           Subject .login(token)



         SecurityManager
How does it work?
           Subject .login(token)



         SecurityManager

           Authenticator
How does it work?
                Subject .login(token)



               SecurityManager

                 Authenticator


     Realm 1     Realm 2    …     Realm N
How does it work?
                Subject .login(token)



               SecurityManager

                                        Authentication
                 Authenticator             Strategy




     Realm 1     Realm 2    …     Realm N
Authorization

     Authentication   Authorization

       Session
                      Cryptography
     Management

              Web Support
           Auxiliary Features
Authorization Defined
Process of determining “who can do what”
AKA Access Control

Elements of Authorization
• Permissions
• Roles
• Users
Permissions Defined

• Most atomic security element

• Describes resource types and their behavior

• The “what” of an application

• Does not define “who”

• AKA “rights”
Roles Defined
• Implicit or Explicit construct
• Implicit: Name only

• Explicit: A named collection of Permissions
   Allows behavior aggregation

   Enables dynamic (runtime) alteration of user abilities.
Users Defined
• The “who” of the application

• What each user can do is defined by their
  association with Roles or Permissions

Example: User’s roles imply PrinterPermission
Authorization Features
• Subject-centric (current user)

• Checks based on roles or permissions

• Powerful out-of-the-box WildcardPermission

• Any data model – Realms decide
How to Authorize with Shiro
Multiple means of checking access control:
• Programmatically

• JDK 1.5 annotations & AOP

• JSP/GSP/JSF* TagLibs (web support)
Programmatic Authorization
  Role Check

//get the current Subject
Subject currentUser=
SecurityUtils.getSubject();

if (currentUser.hasRole(“administrator”)) {
    //show the „delete user‟ button
} else {
    //don‟t show the button?)
}
Programmatic Authorization
  Permission Check
Subject currentUser=
SecurityUtils.getSubject();

Permission deleteUser=
new UserPermission(“jsmith”,“delete”);

If (currentUser.isPermitted(deleteUser)) {
    //show the „delete user‟ button
} else {
//don‟t show the button?
}
Programmatic Authorization
  Permission Check (String-based)
String perm = “user:delete:jsmith”;

if(currentUser.isPermitted(perm)){
//show the „delete user‟ button
} else {
//don‟t show the button?
}
Annotation Authorization
  Role Check
@RequiresRoles( “teller” )
public void openAccount(Account a) {
    //do something in here that
   //only a „teller‟ should do
}
Annotation Authorization
  Permission Check
@RequiresPermissions(“account:create”)
public void openAccount(Account a) {
    //create the account
}
Enterprise Session Management

     Authentication   Authorization

       Session
                      Cryptography
     Management

              Web Support
           Auxiliary Features
Session Management Defined
Managing the lifecycle of Subject-specific
 temporal data context
Session Management Features
•   Heterogeneous client access
•   POJO/J2SE based (IoC friendly)
•   Event listeners
•   Host address retention
•   Inactivity/expiration support (touch())
•   Transparent web use - HttpSession
•   Container-Independent Clustering!
Acquiring and Creating Sessions
Subject currentUser =
SecurityUtils.getSubject()

//guarantee a session
Session session =
subject.getSession();



//get a session if it exists
subject.getSession(false);
Session API
getStartTimestamp()
getLastAccessTime()
getAttribute(key)
setAttribute(key, value)
get/setTimeout(long)
touch()
...
Cryptography

     Authentication   Authorization

       Session
                      Cryptography
     Management

              Web Support
           Auxiliary Features
Cryptography Defined
Protecting information from undesired access by
hiding it or converting it into nonsense.

Elements of Cryptography
• Ciphers
• Hashes
Ciphers Defined
Encryption and decryption data based on shared
or public/private keys.

• Symmetric Cipher – same key
  • Block Cipher – chunks of bits
  • Stream Cipher – stream of bits

• Asymmetric Cipher - different keys
Hashes Defined
A one-way, irreversible conversion of an input
source (a.k.a. Message Digest)
Used for:
• Credentials transformation, Checksum
• Data with underlying byte array
  Files, Streams, etc
Cryptography Features
Simplicity
• Interface-driven, POJO based
• Simplified wrapper over JCE infrastructure.

• “Object Orientifies” cryptography concepts

• Easier to understand API
Cipher Features
• OO Hierarchy
  JcaCipherService, AbstractSymmetricCipherService,
    DefaultBlockCipherService, etc

• Just instantiate a class
  No “Transformation String”/Factory methods

• More secure default settings than JDK!
  Cipher Modes, Initialization Vectors, et. al.
Example: Plaintext




           (image courtesy WikiPedia)
Example: ECB Mode (JDK Default!)




          (image courtesy WikiPedia)
Example: Shiro Defaults




           (image courtesy WikiPedia)
Shiro’sCipherService Interface
public interface CipherService {

ByteSourceencrypt(byte[] raw,
      byte[] key);

   void encrypt(InputStream in,
OutputStreamout, byte[] key);

ByteSourcedecrypt( byte[] cipherText,
       byte[] key);

   void decrypt(InputStream in,
OutputStreamout, byte[] key);
}
Hash Features
• Default interface implementations
   MD5, SHA1, SHA-256, et. al.

• Built in Hex &Base64 conversion

• Built-in support for Salts and repeated hashing
Shiro’s Hash Interface
public interface Hash {

    byte[] getBytes();

    String toHex();

    String toBase64();

}
Intuitive OO Hash API
//some examples:
new Md5Hash(“foo”).toHex();

//File MD5 Hash value for checksum:
new Md5Hash( aFile ).toHex();

//store password, but not plaintext:
new Sha512(aPassword, salt,
1024).toBase64();
Web Support

    Authentication   Authorization

                     Session
     Cryptography
                     Management

             Web Support
          Auxiliary Features
Web Support Features
• Simple ShiroFilter web.xml definition
• Protects all URLs

• Innovative Filtering (URL-specific chains)

• JSP Tag support

• Transparent HttpSession support
web.xml
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>
org.apache.shiro.web.servlet.IniShiroFilter
</filter-class>
</filter>

<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
shiro.ini
[main]
ldapRealm = org.apache.shiro.realm.ldap.JndiLdapRealm
ldapRealm.userDnTemplate = uid={0},ou=users,dc=mycompany,dc=com
ldapRealm.contextFactory.url = ldap://ldapHost:389

securityManager.realm= $realm

[urls]
/images/** = anon
/account/** = authc
/rest/** = authcBasic
/remoting/** = authc, roles[b2bClient], …
JSP TagLib Authorization
<%@ taglib prefix=“shiro”
uri=“http://shiro.apache.org/tags” %>
<html>
<body>
<shiro:hasRole name=“administrator”>
<a href=“manageUsers.jsp”>
            Click here to manage users
</a>
</shiro:hasRole>
<shiro:lacksRole name=“administrator”>
        No user admin for you!
</shiro:hasRole>
</body>
</html>
JSP TagLibs
<%@ taglib prefix=“shiro”
uri=http://shiro.apache.org/tags %>

<!-- Other tags: -->
<shiro:guest/>
<shiro:user/>
<shiro:principal/>
<shiro:hasRole/>
<shiro:lacksRole/>
<shiro:hasAnyRoles/>
<shiro:hasPermission/>
<shiro:lacksPermission/>
<shiro:authenticated/>
<shiro:notAuthenticated/>
Auxiliary Features

     Authentication   Authorization

                      Session
      Cryptography
                      Management

              Web Support
           Auxiliary Features
Auxiliary Features
• Threading & Concurrency
  Callable/Runnable & Executor/ExecutorService
• “Run As” support
• Ad-hoc Subject instance creation
• Unit Testing
• Remembered vs Authenticated
Logging Out
One method: user out, relinquishes account
//Logs the
//data, and invalidates any Session
SecurityUtils.getSubject().logout();


App-specific log-out logic:
  Before/After the call

  Listen for Authentication or StoppedSession events.
Stormpath:Application Security Service
                • Realms + Plug-ins
  Application
                • REST API
                                              Stormpath
  +Stormpath
     Realm                            Authentication   Access Control



Out-of-the-box Features
• Managed security data model
• Secure credential storage
• Flexible permissions
• Password self-service GUI
• Management GUI
Stormpath: Cloud Deployment

                Public Cloud
                                                       CorporateNetwork
  Application       REST




                                         Firewall
                OpenId/OAu                                      Active
  Application       th       Stormpath              Outbound   Directory
                                                      Sync

  Application       SAML
Thank You!
• les@stormpath.com
• http://www.stormpath.com

• Seeking engineering talent

• Seeking product feedback

Mais conteúdo relacionado

Mais procurados

Build A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON APIBuild A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON APIStormpath
 
Authentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrongAuthentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrongDerek Perkins
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJSrobertjd
 
The Ultimate Guide to Mobile API Security
The Ultimate Guide to Mobile API SecurityThe Ultimate Guide to Mobile API Security
The Ultimate Guide to Mobile API SecurityStormpath
 
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
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101 Stormpath
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreStormpath
 
Securing Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based AuthenticationSecuring Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based AuthenticationStefan Achtsnit
 
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
 
Token Authentication for Java Applications
Token Authentication for Java ApplicationsToken Authentication for Java Applications
Token Authentication for Java ApplicationsStormpath
 
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...CA API Management
 
JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2Rodrigo Cândido da Silva
 
Secure API Services in Node with Basic Auth and OAuth2
Secure API Services in Node with Basic Auth and OAuth2Secure API Services in Node with Basic Auth and OAuth2
Secure API Services in Node with Basic Auth and OAuth2Stormpath
 
Access Control Pitfalls v2
Access Control Pitfalls v2Access Control Pitfalls v2
Access Control Pitfalls v2Jim Manico
 
Octopus framework; Permission based security framework for Java EE
Octopus framework; Permission based security framework for Java EEOctopus framework; Permission based security framework for Java EE
Octopus framework; Permission based security framework for Java EERudy De Busscher
 
Spring Security
Spring SecuritySpring Security
Spring SecurityBoy Tech
 
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...Hermann Burgmeier
 
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
 

Mais procurados (20)

Build A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON APIBuild A Killer Client For Your REST+JSON API
Build A Killer Client For Your REST+JSON API
 
Authentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrongAuthentication: Cookies vs JWTs and why you’re doing it wrong
Authentication: Cookies vs JWTs and why you’re doing it wrong
 
Spring Security 3
Spring Security 3Spring Security 3
Spring Security 3
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJS
 
The Ultimate Guide to Mobile API Security
The Ultimate Guide to Mobile API SecurityThe Ultimate Guide to Mobile API Security
The Ultimate Guide to Mobile API Security
 
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
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
 
Securing Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based AuthenticationSecuring Single Page Applications with Token Based Authentication
Securing Single Page Applications with Token Based Authentication
 
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!
 
Token Authentication for Java Applications
Token Authentication for Java ApplicationsToken Authentication for Java Applications
Token Authentication for Java Applications
 
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
 
JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2
 
Secure API Services in Node with Basic Auth and OAuth2
Secure API Services in Node with Basic Auth and OAuth2Secure API Services in Node with Basic Auth and OAuth2
Secure API Services in Node with Basic Auth and OAuth2
 
Access Control Pitfalls v2
Access Control Pitfalls v2Access Control Pitfalls v2
Access Control Pitfalls v2
 
Octopus framework; Permission based security framework for Java EE
Octopus framework; Permission based security framework for Java EEOctopus framework; Permission based security framework for Java EE
Octopus framework; Permission based security framework for Java EE
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
 
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
 

Semelhante a Intro to Apache Shiro

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
 
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
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19Smita B Kumar
 
Bsidesnova- Pentesting Methodology - Making bits less complicated
Bsidesnova- Pentesting Methodology - Making bits less complicatedBsidesnova- Pentesting Methodology - Making bits less complicated
Bsidesnova- Pentesting Methodology - Making bits less complicatedOctavio Paguaga
 
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
 
Java ee 8 + security overview
Java ee 8 + security overviewJava ee 8 + security overview
Java ee 8 + security overviewRudy De Busscher
 
What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)Rudy De Busscher
 
Rest API Security
Rest API SecurityRest API Security
Rest API SecurityStormpath
 
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
 
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
 
Ruby on Rails Security Guide
Ruby on Rails Security GuideRuby on Rails Security Guide
Ruby on Rails Security Guideihji
 
Try {stuff} Catch {hopefully not} - Evading Detection & Covering Tracks
Try {stuff} Catch {hopefully not} - Evading Detection & Covering TracksTry {stuff} Catch {hopefully not} - Evading Detection & Covering Tracks
Try {stuff} Catch {hopefully not} - Evading Detection & Covering TracksYossi Sassi
 
Spring4 security
Spring4 securitySpring4 security
Spring4 securitySang Shin
 
Can you keep a secret? (XP Days 2017)
Can you keep a secret? (XP Days 2017)Can you keep a secret? (XP Days 2017)
Can you keep a secret? (XP Days 2017)Valerii Moisieienko
 
4 the 3rd party libraries
4 the 3rd party libraries4 the 3rd party libraries
4 the 3rd party librariesjavadch
 
Externalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services worldExternalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services worldSitaraman Lakshminarayanan
 
AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)
AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)
AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)Amazon Web Services
 
How to Use Stormpath in angular js
How to Use Stormpath in angular jsHow to Use Stormpath in angular js
How to Use Stormpath in angular jsStormpath
 

Semelhante a Intro to Apache Shiro (20)

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
 
Secure all things with CBSecurity 3
Secure all things with CBSecurity 3Secure all things with CBSecurity 3
Secure all things with CBSecurity 3
 
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
 
Advance java session 19
Advance java session 19Advance java session 19
Advance java session 19
 
Bsidesnova- Pentesting Methodology - Making bits less complicated
Bsidesnova- Pentesting Methodology - Making bits less complicatedBsidesnova- Pentesting Methodology - Making bits less complicated
Bsidesnova- Pentesting Methodology - Making bits less complicated
 
Rails Security
Rails SecurityRails Security
Rails 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
 
Java ee 8 + security overview
Java ee 8 + security overviewJava ee 8 + security overview
Java ee 8 + security overview
 
What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
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
 
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
 
Ruby on Rails Security Guide
Ruby on Rails Security GuideRuby on Rails Security Guide
Ruby on Rails Security Guide
 
Try {stuff} Catch {hopefully not} - Evading Detection & Covering Tracks
Try {stuff} Catch {hopefully not} - Evading Detection & Covering TracksTry {stuff} Catch {hopefully not} - Evading Detection & Covering Tracks
Try {stuff} Catch {hopefully not} - Evading Detection & Covering Tracks
 
Spring4 security
Spring4 securitySpring4 security
Spring4 security
 
Can you keep a secret? (XP Days 2017)
Can you keep a secret? (XP Days 2017)Can you keep a secret? (XP Days 2017)
Can you keep a secret? (XP Days 2017)
 
4 the 3rd party libraries
4 the 3rd party libraries4 the 3rd party libraries
4 the 3rd party libraries
 
Externalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services worldExternalizing Authorization in Micro Services world
Externalizing Authorization in Micro Services world
 
AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)
AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)
AWS re:Invent 2016: IAM Best Practices to Live By (SAC317)
 
How to Use Stormpath in angular js
How to Use Stormpath in angular jsHow to Use Stormpath in angular js
How to Use Stormpath in angular js
 

Último

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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
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
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"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
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: 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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Último (20)

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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
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
 
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
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"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
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: 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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
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.
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Intro to Apache Shiro

  • 1. Simple Application Security Les Hazlewood Apache Shiro Project Chair CTO, Stormpath
  • 2. What is Apache Shiro? • Application security framework • ASF TLP - http://shiro.apache.org • Quick and Easy • Simplifies Security Concepts & Design
  • 3.
  • 4. Agenda Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 5. Quick Terminology • Subject – Security-specific user ‘view’ • Principals – Subject’s identifying attributes • Credentials – Secret values that verify identity • Realm – Security-specific DAO
  • 6. Authentication Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 8. Shiro Authentication Features • Subject-based (current user) • Single method call • Rich Exception Hierarchy • ‘Remember Me’ built in • Event listeners
  • 9. How to Authenticate with Shiro Steps 1. Collect principals & credentials 2. Submit to Authentication System 3. Allow, retry, or block access
  • 10. Step 1: Collecting Principals & Credentials UsernamePasswordToken token = new UsernamePasswordToken(username, password); //”Remember Me” built-in: token.setRememberMe(true);
  • 11. Step 2: Submission Subject currentUser = SecurityUtils.getSubject(); currentUser.login(token);
  • 12. Step 3: Grant Access or Handle Failure try { currentUser.login(token); } catch (UnknownAccountExceptionuae){ ... } catch (IncorrectCredentialsException ice { ... } catch ( LockedAccountExceptionlae ) { ... } catch ( ExcessiveAttemptsExceptioneae ) { ... } ... catch your own ... } catch ( AuthenticationExceptionae ) { //unexpected error? } //No problems, show authenticated view…
  • 13. How does it work? Subject .login(token)
  • 14. How does it work? Subject .login(token) SecurityManager
  • 15. How does it work? Subject .login(token) SecurityManager Authenticator
  • 16. How does it work? Subject .login(token) SecurityManager Authenticator Realm 1 Realm 2 … Realm N
  • 17. How does it work? Subject .login(token) SecurityManager Authentication Authenticator Strategy Realm 1 Realm 2 … Realm N
  • 18. Authorization Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 19. Authorization Defined Process of determining “who can do what” AKA Access Control Elements of Authorization • Permissions • Roles • Users
  • 20. Permissions Defined • Most atomic security element • Describes resource types and their behavior • The “what” of an application • Does not define “who” • AKA “rights”
  • 21. Roles Defined • Implicit or Explicit construct • Implicit: Name only • Explicit: A named collection of Permissions Allows behavior aggregation Enables dynamic (runtime) alteration of user abilities.
  • 22. Users Defined • The “who” of the application • What each user can do is defined by their association with Roles or Permissions Example: User’s roles imply PrinterPermission
  • 23. Authorization Features • Subject-centric (current user) • Checks based on roles or permissions • Powerful out-of-the-box WildcardPermission • Any data model – Realms decide
  • 24. How to Authorize with Shiro Multiple means of checking access control: • Programmatically • JDK 1.5 annotations & AOP • JSP/GSP/JSF* TagLibs (web support)
  • 25. Programmatic Authorization Role Check //get the current Subject Subject currentUser= SecurityUtils.getSubject(); if (currentUser.hasRole(“administrator”)) { //show the „delete user‟ button } else { //don‟t show the button?) }
  • 26. Programmatic Authorization Permission Check Subject currentUser= SecurityUtils.getSubject(); Permission deleteUser= new UserPermission(“jsmith”,“delete”); If (currentUser.isPermitted(deleteUser)) { //show the „delete user‟ button } else { //don‟t show the button? }
  • 27. Programmatic Authorization Permission Check (String-based) String perm = “user:delete:jsmith”; if(currentUser.isPermitted(perm)){ //show the „delete user‟ button } else { //don‟t show the button? }
  • 28. Annotation Authorization Role Check @RequiresRoles( “teller” ) public void openAccount(Account a) { //do something in here that //only a „teller‟ should do }
  • 29. Annotation Authorization Permission Check @RequiresPermissions(“account:create”) public void openAccount(Account a) { //create the account }
  • 30. Enterprise Session Management Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 31. Session Management Defined Managing the lifecycle of Subject-specific temporal data context
  • 32. Session Management Features • Heterogeneous client access • POJO/J2SE based (IoC friendly) • Event listeners • Host address retention • Inactivity/expiration support (touch()) • Transparent web use - HttpSession • Container-Independent Clustering!
  • 33. Acquiring and Creating Sessions Subject currentUser = SecurityUtils.getSubject() //guarantee a session Session session = subject.getSession(); //get a session if it exists subject.getSession(false);
  • 35. Cryptography Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 36. Cryptography Defined Protecting information from undesired access by hiding it or converting it into nonsense. Elements of Cryptography • Ciphers • Hashes
  • 37. Ciphers Defined Encryption and decryption data based on shared or public/private keys. • Symmetric Cipher – same key • Block Cipher – chunks of bits • Stream Cipher – stream of bits • Asymmetric Cipher - different keys
  • 38. Hashes Defined A one-way, irreversible conversion of an input source (a.k.a. Message Digest) Used for: • Credentials transformation, Checksum • Data with underlying byte array Files, Streams, etc
  • 39. Cryptography Features Simplicity • Interface-driven, POJO based • Simplified wrapper over JCE infrastructure. • “Object Orientifies” cryptography concepts • Easier to understand API
  • 40. Cipher Features • OO Hierarchy JcaCipherService, AbstractSymmetricCipherService, DefaultBlockCipherService, etc • Just instantiate a class No “Transformation String”/Factory methods • More secure default settings than JDK! Cipher Modes, Initialization Vectors, et. al.
  • 41. Example: Plaintext (image courtesy WikiPedia)
  • 42. Example: ECB Mode (JDK Default!) (image courtesy WikiPedia)
  • 43. Example: Shiro Defaults (image courtesy WikiPedia)
  • 44. Shiro’sCipherService Interface public interface CipherService { ByteSourceencrypt(byte[] raw, byte[] key); void encrypt(InputStream in, OutputStreamout, byte[] key); ByteSourcedecrypt( byte[] cipherText, byte[] key); void decrypt(InputStream in, OutputStreamout, byte[] key); }
  • 45. Hash Features • Default interface implementations MD5, SHA1, SHA-256, et. al. • Built in Hex &Base64 conversion • Built-in support for Salts and repeated hashing
  • 46. Shiro’s Hash Interface public interface Hash { byte[] getBytes(); String toHex(); String toBase64(); }
  • 47. Intuitive OO Hash API //some examples: new Md5Hash(“foo”).toHex(); //File MD5 Hash value for checksum: new Md5Hash( aFile ).toHex(); //store password, but not plaintext: new Sha512(aPassword, salt, 1024).toBase64();
  • 48. Web Support Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 49. Web Support Features • Simple ShiroFilter web.xml definition • Protects all URLs • Innovative Filtering (URL-specific chains) • JSP Tag support • Transparent HttpSession support
  • 51. shiro.ini [main] ldapRealm = org.apache.shiro.realm.ldap.JndiLdapRealm ldapRealm.userDnTemplate = uid={0},ou=users,dc=mycompany,dc=com ldapRealm.contextFactory.url = ldap://ldapHost:389 securityManager.realm= $realm [urls] /images/** = anon /account/** = authc /rest/** = authcBasic /remoting/** = authc, roles[b2bClient], …
  • 52. JSP TagLib Authorization <%@ taglib prefix=“shiro” uri=“http://shiro.apache.org/tags” %> <html> <body> <shiro:hasRole name=“administrator”> <a href=“manageUsers.jsp”> Click here to manage users </a> </shiro:hasRole> <shiro:lacksRole name=“administrator”> No user admin for you! </shiro:hasRole> </body> </html>
  • 53. JSP TagLibs <%@ taglib prefix=“shiro” uri=http://shiro.apache.org/tags %> <!-- Other tags: --> <shiro:guest/> <shiro:user/> <shiro:principal/> <shiro:hasRole/> <shiro:lacksRole/> <shiro:hasAnyRoles/> <shiro:hasPermission/> <shiro:lacksPermission/> <shiro:authenticated/> <shiro:notAuthenticated/>
  • 54. Auxiliary Features Authentication Authorization Session Cryptography Management Web Support Auxiliary Features
  • 55. Auxiliary Features • Threading & Concurrency Callable/Runnable & Executor/ExecutorService • “Run As” support • Ad-hoc Subject instance creation • Unit Testing • Remembered vs Authenticated
  • 56. Logging Out One method: user out, relinquishes account //Logs the //data, and invalidates any Session SecurityUtils.getSubject().logout(); App-specific log-out logic: Before/After the call Listen for Authentication or StoppedSession events.
  • 57. Stormpath:Application Security Service • Realms + Plug-ins Application • REST API Stormpath +Stormpath Realm Authentication Access Control Out-of-the-box Features • Managed security data model • Secure credential storage • Flexible permissions • Password self-service GUI • Management GUI
  • 58. Stormpath: Cloud Deployment Public Cloud CorporateNetwork Application REST Firewall OpenId/OAu Active Application th Stormpath Outbound Directory Sync Application SAML
  • 59. Thank You! • les@stormpath.com • http://www.stormpath.com • Seeking engineering talent • Seeking product feedback

Notas do Editor

  1. If this is interesting to you please contact me after this presentation or view email because we are looking for people to test our product and give us feedback.
  2. In order to better support your cloud-based application we are building a cloud version of the product where we manage back-ups, upgrades, support, and server level hassles for security and you just have to use it.