Linux Day2005

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Linux Day2005 - Presentation Transcript

    1. Web application sicure con Acegi Security System for Spring Roma, 26 Novembre 2005 Copyright © 2005 Emmanuele Bello - TorLUG
    2. Agenda • Introduzione • Fondamenti di sicurezza • Autenticazione • Autorizzazione • Codice – Info@TV • Conclusione Copyright © 2005 Emmanuele Bello - TorLUG 1
    3. Introduzione • Il framework Spring • Iniziare a lavorare sul vostro progetto con Acegi Security System • Sicurezza Enterprise: autenticazione, web- request, service security, Domain Object Security • Requisiti - Programmazione Java (Standard - Enterprise), Design Patterns, XML. Copyright © 2005 Emmanuele Bello - TorLUG 2
    4. Introduzione 2 • La sicurezza è un “aspetto” fondamentale... Privacy Web Object Security Data Security Copyright © 2005 Emmanuele Bello - TorLUG 3
    5. OWASP The Open Web Application Security Project http://www.owasp.org • Nasce per aiutare le aziende a valutare la sicurezza delle applicazioni e dei servizi web • La Top Ten ha lo scopo di: - sensibilizzare i programmatori sugli errori piu' frequenti; - delineare i perimetri di rischio all'aumentare dei servizi offerti; - dare dei parametri immediati per “correre ai ripari”. “Il codice della tua applicazione web è parte del tuo sistema di sicurezza!” Copyright © 2005 Emmanuele Bello - TorLUG 4
    6. OWASP The Open Web Application Security Project http://www.owasp.org OWASP TOP TEN A1 – Unvalidated Input A2 – Broken Access Control A3 – Broken Authentication and Session Management A4 – Cross Site Scripting (XSS) Flaws A5 – Buffer Overflows A6 – Injection Flaws A7 – Improper Error Handling A8 – Insecure Storage A9 – Denial of Service A10 – Insecure Configuration Management Copyright © 2005 Emmanuele Bello - TorLUG 5
    7. Fondamenti di Sicurezza Alcuni termini utili per il futuro... • Autenticazione (Authentication): - “Controllare se il richiedente è veramente chi dice di essere” • Autorizzazione (Authorization) o Access Control: - “Controllare cosa il richiedente, autenticato, puo' fare sull'applicazione o sul sistema” • Principal (username): - “Macchine o utenti unicamente identificati nel sistema” • Credentials (Password): - “Qualcosa che il Principal fornisce per provare che è veramente chi dice di essere” Copyright © 2005 Emmanuele Bello - TorLUG 6
    8. Spring Framework http://www.springframework.org • Creato da Rod Johnson - Interface21; versione corrente 1.2.5 • Perchè Spring? - http://www.theserverside.com/articles/content/RodJohnsonInterview/JohnsonChapter4.pdf - http://www.theserverside.com/resources/article.jsp?l=SpringFramework • Progetto Open Source: - Rendere le applicazioni J2EE facili e strutturate, grazie alla sua architettura interna; - Fornire un buon metodo di programmazione; - Possibilità di usare moduli in modo autonomo o aggregati. Copyright © 2005 Emmanuele Bello - TorLUG 7
    9. Spring Framework http://www.springframework.org • Overview Copyright © 2005 Emmanuele Bello - TorLUG 8
    10. Spring Framework http://www.springframework.org • Full-fledged Spring web application Copyright © 2005 Emmanuele Bello - TorLUG 9
    11. Spring Framework http://www.springframework.org • Caratteristiche - Il Core è disegnato per lavorare con i Java Beans; lo fa tramite BeanFactory. • IoC – Inversion of Control Pattern - Ogni oggetto espone le proprie dipendenze mediante una sorta di contratto invece che risolverle automaticamente; - Rende le applicazioni flessibili, robuste e riutilizzabili. Gli oggetti sono disaccoppiati e piu' gestibili. • Dependency Injection - Le dipendenze vengono “iniettate” nei componenti della applicazione da una entità esterna. Entità esterna: LightWeight container. Spring, Avalon, PicoContainer, Excalibur, HiveMind, Carbon,... Copyright © 2005 Emmanuele Bello - TorLUG 10
    12. Spring Framework http://www.springframework.org • Service Locator vs. Dependency Injection Service Locator Dependency Injection - Devo chiedere le dipendenze al Locator. - Le dipendenze mi vengono assegnate. - Dipendo in modo pesante dal Locator. - Non dipendo dal framework e tanto meno dal locator. - Accettabile se devo usare un Locator - Non intuitivo. fatto da me, ma se devo riusare... Tutte queste dipendenze (Setter Method, Constructor, Interface, Context) si configurano in un file XML, chiamato solitamente applicationContext-xyz.xml. Copyright © 2005 Emmanuele Bello - TorLUG 11
    13. Spring Framework http://www.springframework.org • Esempio di Dependency Injection usando la tecnica “Setter Methods” <bean id=”exampleBean” class=”examples.ExampleBean”> <property name=”beanOne”><ref bean=”anotherBean”/></property> <propetry name=”beanTwo”><ref bean=”someBean” /></propery> <property name="integerProperty">1</property> </bean> <bean id=”anotherBean” class=”examples.AnotherBean” /> <bean id=”someBean” class=”examples.someBean” /> public class ExampleBean { /* Variabili di istanza */ private AnotherBean beanOne;    private someBean beanTwo; Plain private int i; Old Java public void setBeanOne(AnotherBean beanOne) { this.beanOne = beanOne; } public void setBeanTwo(SomeBean beanTwo ) { this.beanTwo = beanTwo; } Object public void setIntegerProperty(int i ) { this.i = i; } } Copyright © 2005 Emmanuele Bello - TorLUG 12
    14. Acegi Security System http://acegisecurity.sourceforge.net/ • Creato da Ben Alex; versione corrente 0.9.0; pienamente appoggiato dagli autori di Spring • Obiettivi del progetto: - Fornire un layer di sicurezza per le applicazioni “Spring oriented”. - Puo' essere usato fuori del contesto di Spring. http://acegisecurity.sourceforge.net/standalone.html • Mailing list ufficiale del progetto: http://acegisecurity.sourceforge.net/mail-lists.html ...scrivete Acegi Security System!!! Copyright © 2005 Emmanuele Bello - TorLUG 13
    15. Acegi Security System http://acegisecurity.sourceforge.net/ • Fondamenti Richieste web Security = Interceptor Authentication Access Decision Run-as Manager Manager Manager Copyright © 2005 Emmanuele Bello - TorLUG 14
    16. Acegi Security System http://acegisecurity.sourceforge.net/ • Security Interceptor - Pensato come una serratura, per sbloccarla dovete darle qualche cosa, tipicamente username e password (Principal&Credentials) per accedere al sistema. • Authentication Manager - E' responsabile nel determinare chi è il richiedente, ovviamente lo fa valutando ID e PWD. Se lo avete convinto ora il sistema sa con chi ha a che fare! • Access Decision Manager - E il responsabile delle autorizzazioni concesse a chi risulta autenticato. Autorizza in base alle credenziali, e ad informazioni di sicurezza (ad esempio il Ruolo “ROLE_”). • Run-As Manager - Pensato per restringere maggiormente la zona sicura di accesso per un utente. Puo' essere usato per sostituire “Authentication” e dargli +/- potere. Copyright © 2005 Emmanuele Bello - TorLUG 15
    17. Acegi Security System http://acegisecurity.sourceforge.net/ • Autenticazione - Determinare in modo univoco l'identità di un utente. - Chi si preoccupa di stabilire l'identità è: net.sf.acegisecurity.AuthenticationManager public interface AuthenticationManager { public Authentication authenticate(Authentication authentication) throws AuthenticationException; } Principal authenticate (...) Authentication Authentication Credentials ...facile no? Ma devo scrivere una mia classe? Se voglio... ma di default ci pensa Acegi Security System, vediamo come... Copyright © 2005 Emmanuele Bello - TorLUG 16
    18. Acegi Security System http://acegisecurity.sourceforge.net/ • ProviderManager implements AuthenticationManager - Delega la responsabilità di autenticarsi ai provider. Provider Manager Dao Jass Password Dao Cas Remote Authentication Authentication Authentication Authentication Authentication Provider Provider Provider Manager Provider <bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager"> <property name="providers"> <list> <ref bean="daoAuthenticationProvider"/> <ref bean="passwordDaoProvider"/> </list> </property> </bean> Copyright © 2005 Emmanuele Bello - TorLUG 17
    19. Acegi Security System http://acegisecurity.sourceforge.net/ • Autenticazione su DataBase esempio - Posso usare due providers, quali: * DaoAuthenticationProvider – il DAO esegue la vera autenticazione; * PasswordDaoAuthenticationProvider – la responsabilità è esterna al DAO (es. Ligthweight Directory Access Protocol). Authentication authenticate () Dao loadByUsername() Authentication Manager Authentication Dao Provider <bean id="authenticationProvider” class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider"> <property name="authenticationDao"> <ref bean="authenticationDao"/> </property> </bean> User Database ...magari customizzato (InfoTvAuthenticationDao.java) Copyright © 2005 Emmanuele Bello - TorLUG 18
    20. Acegi Security System http://acegisecurity.sourceforge.net/ • Password Encryption - OWASP (A3): Broken authentication/session management - Di default il DaoAuthenticationProvider assume che la passowrd è in chiaro. * PlainTextPasswordEncoder – (defualt) nessuna codifica; * Md5PasswordEncoder – usa Md5 per la codifica; * ShaPasswordEncoder – usa Secure Hash Algorithm per la codifica. - Modifcate il DaoAuthenticationProvider, aggiungendo la proprietà... <property name="passwordEncoder"> <bean class="net.sf.acegisecurity.providers.encoding.Md5PasswordEncoder"/> </property> - Possiamo dare anche un po' di “sale” alla password: * ReflectionSaltSource – usa una proprietà dell'oggetto User; * SystemWideSaltSource – usa la stessa proprietà per tutti gli utenti; <property name="saltSource"> <bean class="net.sf.acegisecurity.providers.dao.salt.ReflectionSaltSource"/> </property> Copyright © 2005 Emmanuele Bello - TorLUG 19
    21. Acegi Security System http://acegisecurity.sourceforge.net/ • Caching - Potrebbe essere utile avere le informazioni di un utente autenticato senza dovere fare continuamente query sul DB. - Il DaoAuthenticationProvider supporta il caching, implementando net.sf.acegisecurity.providers.dao.UserCache public interface UserCache { public UserDetails getUserFromCache (String username); public void putUserInCache (UserDetails user); public void removeUserFromCache (String username); } - Acegi Security System fornisce due comode implementazioni, quali: * net.sf.acegisecurity.providers.dao.cache.NullUserCache * net.sf.acegisecurity.providers.dao.cache.EhCacheBasedUserCache - Cache Open Source in Java. http://ehcache.sourceforge.net/ Copyright © 2005 Emmanuele Bello - TorLUG 20
    22. Acegi Security System http://acegisecurity.sourceforge.net/ • Controllo degli accessi - Dopo essersi autenticati occorre avere il permesso di accedere alle risorse del sistema. AccessDecisionManager. net.sf.acegisecurity.AccessDecisonManager public interface AccessDecisionManager { public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config) throws AccessDeniedException; public boolean supports(ConfigAttribute attribute); public boolean supports(Class clazz); } - Acegi Security System fornisce tre implementazioni, quali: * net.sf.acegisecurity.vote.AffirmativeBased – permette l'accesso se almeno uno vota a favore; * net.sf.acegisecurity.vote.ConsensusBased – permette l'accesso se tutti votano a favore; * net.sf.acegisecurity.vote.UnanimousBased – permette l'accesso se nessuno lo nega (alcuni possono pure astenersi). ...come configurarlo lo avete imparato :-) Copyright © 2005 Emmanuele Bello - TorLUG 21
    23. Acegi Security System http://acegisecurity.sourceforge.net/ • Controllo degli accessi (2) - Definito il manager servono i Voters, ovvero gli net.sf.acegisecurity.vote.AccessDecisionVoter public interface AccessDecisionVoter { public static final int ACCESS_GRANTED = 1; public static final int ACCESS_ABSTAIN = 0; public static final int ACCESS_DENIED = -1; public boolean supports(ConfigAttribute attribute); public boolean supports(Class clazz); public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config); } - Acegi Security System fornisce: net.sf.acegisecurity.vote.RoleVoter <bean id="roleVoter"class="net.sf.acegisecurity.vote.RoleVoter"/> ...sentirete la necessità di customizzare il vostro RoleVoter! Copyright © 2005 Emmanuele Bello - TorLUG 22
    24. Acegi Security System http://acegisecurity.sourceforge.net/ • ...ricordate la serratura? - La sicurezza web è basata su filtri servlet. Intercettano le richieste web e applicano un certo processo sicuro. Richiesta web Servlet filters Copyright © 2005 Emmanuele Bello - TorLUG 23
    25. Acegi Security System http://acegisecurity.sourceforge.net/ • ...ricordate la serratura? - I filtri servlet di Acegi Security System * Channel-processing filter – assicura le redirect su canale protetto (HTTPS ad esempio); * Authentication-processing filter – accetta le richieste di autenticazione e le invia all'authenticatioon manager; * CAS-processing filter – accetta tickets per le Central AuthenticaionService; * HTTP Basic authorization filter – processa autenticazioni basate su HTTP base; * Integration filter – gestisce il contenitore di oggetti authentication attraverso le request; * Security enforcement filter – assicura che l'utente dopo essere autenticato possa accedere alle risosrse web. Copyright © 2005 Emmanuele Bello - TorLUG 23-b
    26. Acegi Security System http://acegisecurity.sourceforge.net/ • ...quindi... Request Channel-Processing Filter (opzionale) Authentication-Processing Filter Integration Filter Security Enforcement Filter ...trovate la sequenza sulla guida! Copyright © 2005 Emmanuele Bello - TorLUG 24
    27. Acegi Security System http://acegisecurity.sourceforge.net/ • ...ancora qualche concetto ... - I filtri nel descrittore di deployment (web.xml) li vediamo dal vivo... - SecurityEnforcementFilter capisce se la richiesta e di autenticazione o di autorizzazione e quindi delega ai manager. manager <bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter"> <property name="securityInterceptor"> <ref bean="securityInterceptor"/> </property> <property name="authenticationEntryPoint"> <ref bean="authenticationEntryPoint"/> </property> </bean> Copyright © 2005 Emmanuele Bello - TorLUG 25
    28. Acegi Security System http://acegisecurity.sourceforge.net/ - FilterSecurityInterceptor <bean id="securityInterceptor" class="net.sf.acegisecurity. intercept.web.FilterSecurityInterceptor"> <property name="authenticationManager"> <ref bean="authenticationManager"/> </property> <property name="accessDecisionManager"> <ref bean="accessDecisionManager"/> </property> <property name="objectDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON A/admin/.*Z=ROLE_ADMIN A/student/.*Z=ROLE_STUDENT,ROLE_ALUMNI A/instruct/.*Z=ROLE_INSTRUCTOR </value> </property> </bean> Copyright © 2005 Emmanuele Bello - TorLUG 26
    29. Acegi Security System http://acegisecurity.sourceforge.net/ - AuthenticationEntryPoint <bean id="authenticationEntryPoint" class="net.sf.acegisecurity. ui.webapp.AuthenticationProcessingFilterEntryPoint"> <property name="loginFormUrl"> <value>/jsp/login.jsp</value> </property> <property name="forceHttps"><value>true</value></property> </bean> Sulla pagina: <form method="POST" action="j_acegi_security_check"> <input type="text" name="j_username"><br> <input type="password" name="j_password"><br> <input type="submit"> </form> Copyright © 2005 Emmanuele Bello - TorLUG 27
    30. Acegi Security System http://acegisecurity.sourceforge.net/ - AuthenticationProcessingFilter <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter"> <property name="filterProcessesUrl"> <value>/j_acegi_security_check</value> </property> <property name="authenticationFailureUrl"> <value>/jsp/login.jsp?failed=true</value> </property> <property name="defaultTargetUrl"> <value>/</value> </property> <property name="authenticationManager"> <ref bean="authenticationManager"/> </property> </bean> Copyright © 2005 Emmanuele Bello - TorLUG 28
    31. Acegi Security System http://acegisecurity.sourceforge.net/ - Authorization-Related Tag Libraries - authz.tld Rendono piu' facile la scrittura di pagine JSP. Quali sono: AuthorizeTag, AuthenticationTag, AclTag. Nel web.xml <taglib> <taglib-uri>http://acegisecurity.sf.net/authz</taglib-uri> <taglib-location>/WEB-INF/authz.tld</taglib-location> </taglib> Nelle JSP <authz:authorize ifAllGranted="ROLE_SUPERVISOR"> ... JSP Page ... </authz:authorize> Copyright © 2005 Emmanuele Bello - TorLUG 29
    32. Acegi Security System http://acegisecurity.sourceforge.net/ • Alcune features interessanti... - Acegi Security System Events Usati dalla classe AuthenticationProvider per informare il sistema di cio' che accade; Catturarli è semplice... ... import org.springframework.context.ApplicationListener; ... public MioListener implements ApplicationListener { public void onApplicationEvent(ApplicationEvent event) { if (event instanceof AuthenticationFailureUsernameNotFoundEvent) { ... } } } Logger, UserLocker, etc. Copyright © 2005 Emmanuele Bello - TorLUG 30
    33. Acegi Security System http://acegisecurity.sourceforge.net/ • Alcune features interessanti... - Access Control List (ACL) Security Molto interessanti per grandi applicazioni Authentication ACL MethodInvocation DomainObject net.sf.acegisecurity.acl Default maschera Unix-like (rwx) Copyright © 2005 Emmanuele Bello - TorLUG 31
    34. Acegi Security System http://acegisecurity.sourceforge.net/ • Alcune features interessanti... - Aspect Oriented Programming (AOP) http://aopalliance.sourceforge.net./ Method Security Interceptor AspectJSecurityInterceptor Copyright © 2005 Emmanuele Bello - TorLUG 32
    35. Links & co. - Starting point https://appfuse.dev.java.net/ http://oness.sourceforge.net/ - Papers Acegi Security System reference: http://acegisecurity.sourceforge.net/docbook/acegi.html “Spring in Action” Craig Walls, Ryan Breidenbach - Manning - Forum & ML Forum Spring: http://forum.springframework.org/ Spring Mailing List: https://lists.sourceforge.net/lists/listinfo/springframework-developer Copyright © 2005 Emmanuele Bello - TorLUG 33
    36. Acegi Security System http://acegisecurity.sourceforge.net/ • ...vediamo il codice... Copyright © 2005 Emmanuele Bello - TorLUG 34
    37. Domande Copyright © 2005 Emmanuele Bello - TorLUG 35
    38. GRAZIE... Emmanuele Bello emmanuele.bello@torlug.org http://www.torlug.org info@torlug.org Copyright © 2005 Emmanuele Bello - TorLUG
    SlideShare Zeitgeist 2009

    + mannobugmannobug Nominate

    custom

    47 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 47
      • 47 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 1
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories