Painless Applica,on Security Les Hazlewood Apache Shiro - - PowerPoint PPT Presentation

painless applica on security
SMART_READER_LITE
LIVE PREVIEW

Painless Applica,on Security Les Hazlewood Apache Shiro - - PowerPoint PPT Presentation

Painless Applica,on Security Les Hazlewood Apache Shiro Project Chair CTO, Kataso5 Inc / CloudDirectory What is Apache Shiro? Applica>on security


slide-1
SLIDE 1

Painless ¡Applica,on ¡Security ¡

Les ¡Hazlewood ¡ Apache ¡Shiro ¡Project ¡Chair ¡ ¡ CTO, ¡Kataso5 ¡Inc ¡/ ¡CloudDirectory ¡

slide-2
SLIDE 2

What ¡is ¡Apache ¡Shiro? ¡

  • Applica>on ¡security ¡framework ¡
  • ASF ¡TLP ¡-­‑ ¡hFp://shiro.apache.org ¡
  • Quick ¡and ¡Easy ¡
  • Comprehensive ¡
  • Simplifies ¡Security ¡Concepts ¡& ¡Design ¡
slide-3
SLIDE 3

Agenda ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Authen>ca>on ¡ Session ¡ Management ¡ Authoriza>on ¡ Cryptography ¡

slide-4
SLIDE 4

Authen,ca,on ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Session ¡ Management ¡ Authoriza>on ¡ Authen,ca,on ¡ Cryptography ¡

slide-5
SLIDE 5

Authen,ca,on ¡Defined ¡

Identity verification: Proving a user is who he says he is

slide-6
SLIDE 6

Shiro ¡Authen,ca,on ¡Features ¡

  • Subject-­‑based ¡(current ¡user) ¡
  • Single ¡method ¡call ¡
  • Rich ¡Excep>on ¡Hierarchy ¡
  • ‘Remember ¡Me’ ¡built ¡in ¡
  • Event ¡listeners ¡
slide-7
SLIDE 7

How ¡to ¡Authen,cate ¡with ¡Shiro ¡

Steps

  • 1. Collect principals & credentials
  • 2. Submit to Authentication System
  • 3. Allow, retry, or block access
slide-8
SLIDE 8

Step ¡1: ¡Collec,ng ¡Principals ¡& ¡Creden,als ¡

UsernamePasswordToken token = new UsernamePasswordToken(username, password); //”Remember Me” built-in: token.setRememberMe(true);

slide-9
SLIDE 9

Step ¡2: ¡Submission ¡

Subject currentUser = SecurityUtils.getSubject(); currentUser.login(token);

slide-10
SLIDE 10

Step ¡3: ¡Grant ¡Access ¡or ¡Handle ¡Failure ¡ ¡

try { currentUser.login(token); } catch (UnknownAccountException uae ){ ... } catch (IncorrectCredentialsException ice { ... } catch ( LockedAccountException lae ) { ... } catch ( ExcessiveAttemptsException eae ) { ... } ... catch your own ... } catch ( AuthenticationException ae ) { //unexpected error? }

//No problems, show authenticated view…

slide-11
SLIDE 11

How ¡does ¡it ¡work? ¡

Subject ¡

SecurityManager ¡

Authen>cator ¡

Realm ¡1 ¡ .login(token) ¡

Authen>ca>on ¡ Strategy ¡

… ¡

Realm ¡2 ¡ Realm ¡N ¡

slide-12
SLIDE 12

Authoriza,on ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Session ¡ Management ¡ Authen>ca>on ¡ Authoriza,on ¡ Cryptography ¡

slide-13
SLIDE 13

Authoriza,on ¡Defined ¡

Process ¡of ¡determining ¡“who ¡can ¡do ¡what” ¡ AKA ¡Access ¡Control ¡

¡

Elements ¡of ¡Authoriza,on ¡

  • Permissions ¡
  • Roles ¡
  • Users ¡
slide-14
SLIDE 14

Authoriza,on ¡Features ¡

  • Subject-­‑centric ¡(current ¡user) ¡
  • Checks ¡based ¡on ¡roles ¡or ¡permissions ¡
  • Powerful ¡out-­‑of-­‑the-­‑box ¡WildcardPermission ¡
  • Any ¡data ¡model ¡– ¡Realms ¡decide ¡
slide-15
SLIDE 15

How ¡to ¡Authorize ¡with ¡Shiro ¡

Mul>ple ¡means ¡of ¡checking ¡access ¡control: ¡

  • Programma>cally ¡
  • Java ¡Annota>ons ¡& ¡AOP ¡
  • JSP/GSP/JSF ¡TagLibs ¡(web ¡support) ¡
slide-16
SLIDE 16

Programma,c ¡Authoriza,on ¡

//get the current Subject Subject currentUser = SecurityUtils.getSubject(); if (currentUser.hasRole(“administrator”)) { //show the ‘delete user’ button } else { //don’t show the button?) }

Role ¡Check ¡

slide-17
SLIDE 17

Programma,c ¡Authoriza,on ¡

String perm = “user:delete:jsmith”; if(currentUser.isPermitted(perm)){ //show the ‘delete user’ button } else { //don’t show the button? }

Permission ¡Check ¡(String-­‑based) ¡

slide-18
SLIDE 18

Annota,on ¡Authoriza,on ¡

@RequiresRoles( “teller” ) public void openAccount(Account a) { //do something in here that //only a ‘teller’ should do }

Role ¡Check ¡

slide-19
SLIDE 19

Annota,on ¡Authoriza,on ¡

@RequiresPermissions(“account:create”) public void openAccount(Account a) { //create the account }

Permission ¡Check ¡

slide-20
SLIDE 20

Enterprise ¡Session ¡Management ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Authoriza>on ¡ Authen>ca>on ¡ Cryptography ¡ Session ¡ Management ¡

slide-21
SLIDE 21

Session ¡Management ¡Defined ¡

Managing ¡the ¡lifecycle ¡of ¡Subject-­‑specific ¡ temporal ¡data ¡context ¡

slide-22
SLIDE 22

Session ¡Management ¡Features ¡

  • Heterogeneous ¡client ¡access ¡
  • POJO/JSE ¡based ¡(IoC ¡friendly) ¡
  • Event ¡listeners ¡
  • Host ¡address ¡reten>on ¡
  • Transparent ¡web ¡use ¡-­‑ ¡HFpSession ¡
  • Container-­‑Independent ¡Clustering! ¡
slide-23
SLIDE 23

Acquiring ¡and ¡Crea,ng ¡Sessions ¡

Subject currentUser = SecurityUtils.getSubject() //guarantee a session Session session = subject.getSession(); //get a session if it exists subject.getSession(false);

slide-24
SLIDE 24

Session ¡API ¡

getStartTimestamp() getLastAccessTime() getAttribute(key) setAttribute(key, value) get/setTimeout(long) touch() ...

slide-25
SLIDE 25

Cryptography ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Authoriza>on ¡ Authen>ca>on ¡ Session ¡ Management ¡ Cryptography ¡

slide-26
SLIDE 26

Cryptography ¡Defined ¡

Protec>ng ¡informa>on ¡from ¡undesired ¡access ¡by ¡ hiding ¡it ¡or ¡conver>ng ¡it ¡into ¡nonsense. ¡ ¡ Elements ¡of ¡Cryptography ¡

  • Ciphers ¡
  • Hashes ¡
slide-27
SLIDE 27

Cryptography ¡Features ¡

Simplicity ¡

  • Interface-­‑driven, ¡POJO ¡based ¡
  • Simplified ¡wrapper ¡over ¡JCE ¡infrastructure ¡
  • “Object ¡Orien>fies” ¡cryptography ¡concepts ¡
  • Easier ¡to ¡understand ¡API ¡
  • More ¡Secure ¡Defaults ¡than ¡the ¡JDK! ¡
slide-28
SLIDE 28

Example: ¡Plaintext ¡

(image ¡courtesy ¡WikiPedia) ¡

slide-29
SLIDE 29

Example: ¡ECB ¡Mode ¡(JDK ¡Default!) ¡

(image ¡courtesy ¡WikiPedia) ¡

slide-30
SLIDE 30

Example: ¡Shiro ¡Defaults ¡

(image ¡courtesy ¡WikiPedia) ¡

slide-31
SLIDE 31

CipherService ¡Example ¡

AesCipherService service = new AesCipherService(); service.setKeySize(256); byte[] key = service.generateNewKey() .getEncoded(); byte[] encrypted = service.encrypt(rawData,key);

slide-32
SLIDE 32

Hash ¡Features ¡

  • Default ¡interface ¡implementa>ons ¡

MD5, ¡SHA1, ¡SHA-­‑256, ¡et. ¡al. ¡

  • Built ¡in ¡Hex ¡& ¡Base64 ¡conversion ¡
  • Built-­‑in ¡support ¡for ¡Salts ¡and ¡repeated ¡hashing ¡
slide-33
SLIDE 33

Intui,ve ¡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 Sha512Hash(aPassword, salt, iterations).toBase64();

slide-34
SLIDE 34

Web ¡Support ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Cryptography ¡ Session ¡ Management ¡ Authoriza>on ¡ Authen>ca>on ¡

slide-35
SLIDE 35

Web ¡Support ¡Features ¡

  • Simple ¡ShiroFilter ¡web.xml ¡defini>on ¡
  • Protects ¡all ¡URLs ¡
  • Innova>ve ¡Filtering ¡(URL-­‑specific ¡chains) ¡
  • JSP ¡Tag ¡support ¡
  • Transparent ¡HFpSession ¡support ¡
slide-36
SLIDE 36

web.xml ¡

<listener> <listener-class>

  • rg.apache.shiro.web.env.EnvironmentLoaderListener

</listener-class> </listener> ... <filter> <filter-name>ShiroFilter</filter-name> <filter-class>org.apache.shiro.web.servlet.ShiroFilter </filter-class> </filter> <filter-mapping> <filter-name>ShiroFilter</filter-name>

<url-pattern>/*</url-pattern> </filter-mapping>

slide-37
SLIDE 37

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], …

slide-38
SLIDE 38

JSP ¡TagLib ¡Authoriza,on ¡

<%@ 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:lacksRole> </body> </html>

slide-39
SLIDE 39

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/>

slide-40
SLIDE 40

Auxiliary ¡Features ¡

Web ¡Support ¡ Auxiliary ¡Features ¡ Cryptography ¡ Session ¡ Management ¡ Authoriza>on ¡ Authen>ca>on ¡

slide-41
SLIDE 41

Auxiliary ¡Features ¡

  • Threading ¡& ¡Concurrency ¡

Callable/Runnable ¡& ¡Executor/ExecutorService ¡

  • “Run ¡As” ¡support ¡
  • Ad-­‑hoc ¡Subject ¡instance ¡crea>on ¡
  • Unit ¡Tes>ng ¡
  • Remembered ¡vs ¡Authen>cated ¡
slide-42
SLIDE 42

Logging ¡Out ¡

One ¡method: ¡

App-­‑specific ¡log-­‑out ¡logic: ¡

Before/A5er ¡the ¡call ¡ Listen ¡for ¡Authen>ca>on ¡or ¡StoppedSession ¡events. ¡

//Logs the user out, relinquishes account //data, and invalidates any Session SecurityUtils.getSubject().logout();

slide-43
SLIDE 43

First ¡Cloud ¡Iden,ty ¡Management ¡system ¡for ¡your ¡apps ¡ ¡

  • Features ¡

Authen>ca>on ¡& ¡Access ¡Control ¡ Directory ¡Support ¡ Pre-­‑Built ¡Secure ¡Workflows ¡ ¡

  • Sign-­‑up ¡for ¡Beta: ¡CloudDirectory.com ¡

¡