Changeset 1544


Ignore:
Timestamp:
2010-06-07 07:03:25 (3 years ago)
Author:
jgou
Message:

Ensure that the RepresentationFilter? is also executed (when representations are active) before the SecurityFilter? clears the SecurityContext?.
This fixes #233 . Thanks Bruno for the valuable feedback.

Location:
trunk
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/kauri-runtime-rapi/src/main/java/org/kauriproject/runtime/rapi/FilterFactory.java

    r1327 r1544  
    1919 
    2020public interface FilterFactory { 
     21    String getID(); 
    2122    Filter createFilter(); 
    2223} 
  • trunk/core/kauri-runtime-rapi/src/main/java/org/kauriproject/runtime/rapi/KauriModule.java

    r1523 r1544  
    1616package org.kauriproject.runtime.rapi; 
    1717 
     18import java.util.List; 
     19 
     20import org.restlet.Application; 
     21import org.restlet.Context; 
     22import org.restlet.Request; 
    1823import org.restlet.Response; 
    19 import org.restlet.Request; 
    20 import org.restlet.Context; 
    21 import org.restlet.Application; 
    2224import org.springframework.context.ApplicationContext; 
    23  
    24 import java.util.List; 
    2525 
    2626public interface KauriModule { 
     
    8484     */ 
    8585    void addFilter(FilterFactory filterFactory); 
     86     
     87    /** 
     88     * Duplicates the first occurence of the specified filter (if one is already registered). 
     89     */ 
     90    void duplicateFilter(String filterFactoryID); 
    8691 
    8792    /** 
     
    8994     */ 
    9095    void addRootFilter(FilterFactory filterFactory); 
    91  
     96     
    9297    Context getRestletContext(); 
    9398 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/module/restservice/RestserviceFacet.java

    r1523 r1544  
    2020import java.util.Date; 
    2121import java.util.HashMap; 
     22import java.util.Iterator; 
    2223import java.util.List; 
    2324import java.util.Map; 
     
    231232    public synchronized void addRestserviceFilter(FilterFactory filterFactory) { 
    232233        this.restserviceFilterFactories.add(filterFactory); 
    233  
    234234        for (RestserviceRegistryEntry entry : restserviceRegistry.values()) { 
    235235            FilterChain filterChain = entry.getHandle().getFilterChain(); 
    236236            if (filterChain != null) 
    237237                filterChain.rebuild(restserviceFilterFactories); 
     238        } 
     239    } 
     240     
     241    /** 
     242     * Duplicates an already registered filter which will be executed before delegating a call to a restservice. 
     243     * If multiple occurences of this filter are registered (e.g. with different configurations), only the first one  
     244     * is duplicated. 
     245     */ 
     246    public synchronized void duplicateFilter(final String filterFactoryID) { 
     247        FilterFactory duplicate = null; 
     248        Iterator<FilterFactory> iter = this.restserviceFilterFactories.iterator(); 
     249        while(iter.hasNext()) { 
     250            FilterFactory factory = iter.next(); 
     251            // skip last factory, no use in duplicating the last entry 
     252            if(iter.hasNext() && factory.getID().equals(filterFactoryID)) { 
     253                duplicate = factory; 
     254                break; 
     255            } 
     256        } 
     257        if(duplicate != null) { 
     258            this.addRestserviceFilter(duplicate); 
    238259        } 
    239260    } 
  • trunk/core/kauri-runtime/src/main/java/org/kauriproject/runtime/rapi_impl/KauriModuleImpl.java

    r1523 r1544  
    102102        module.getRestserviceFacet().addRestserviceFilter(filterFactory); 
    103103    } 
     104     
     105    public void duplicateFilter(String filterFactoryID) { 
     106        module.getRestserviceFacet().duplicateFilter(filterFactoryID); 
     107    } 
    104108 
    105109    public void addRootFilter(FilterFactory filterFactory) { 
  • trunk/modules/kauri-i18n/kauri-i18n-impl/src/main/java/org/kauriproject/i18n/impl/I18nFilterFactory.java

    r1526 r1544  
    2424 
    2525public class I18nFilterFactory implements FilterFactory { 
     26     
     27    public static final String ID = "org.kauriproject.i18n.impl.I18nFilterFactory"; 
     28     
    2629    private I18nManager i18nManager; 
    2730 
     
    3033    } 
    3134 
     35    public String getID() { 
     36        return ID; 
     37    } 
     38     
    3239    public Filter createFilter() { 
    3340        return new I18nFilter(); 
    3441    } 
    35  
     42     
    3643    private class I18nFilter extends Filter { 
    3744        @Override 
  • trunk/modules/kauri-locale-assignment/src/main/java/org/kauriproject/i18n/locale_assignment/LocaleAssigner.java

    r1407 r1544  
    5757 
    5858    private static class LocaleAssignmentFilterFactory implements FilterFactory { 
     59        public static final String ID = "org.kauriproject.i18n.locale_assignment.LocaleAssignmentFilterFactory"; 
    5960         
    6061        private boolean ignoreClientInfo; 
     
    7071            return new LocaleAssignmentFilter(ignoreClientInfo, defaultLocale, defaultTimeZoneId); 
    7172        } 
     73         
     74        public String getID() { 
     75            return ID; 
     76        } 
    7277    } 
    7378     
  • trunk/modules/kauri-representation/kauri-representationbuilder-impl/src/main/java/org/kauriproject/representation/build/impl/RepresentationFilterFactory.java

    r1537 r1544  
    5454 */ 
    5555public class RepresentationFilterFactory implements FilterFactory { 
     56     
     57    public static final String ID = "org.kauriproject.representation.build.impl.RepresentationFilterFactory"; 
     58     
    5659    RepresentationResolver resolver; 
    5760 
     
    5962        this.resolver = resolver; 
    6063    } 
    61  
     64     
     65    public String getID() { 
     66        return ID; 
     67    } 
     68     
    6269    public Filter createFilter() { 
    6370        return new RepresentationFilter(resolver); 
     
    100107            if (throwable == null) { 
    101108                Representation representation = response.getEntity(); 
     109                 
    102110                String media = getMedia(request); 
    103111                if (response.getStatus() != null && response.getStatus().isError() && 
  • trunk/modules/kauri-representation/kauri-representationbuilder-impl/src/test/java/org/kauriproject/representation/test/BuilderTest.java

    r1526 r1544  
    100100            public void addFilter(FilterFactory filterFactory) { 
    101101            } 
     102             
     103            public void duplicateFilter(String filterFactoryID) { 
     104            } 
    102105 
    103106            public void addRootFilter(FilterFactory filterFactory) { 
    104107            } 
    105  
     108             
    106109            public Context getRestletContext() { 
    107110                return restletContext; 
  • trunk/modules/kauri-security/kauri-security-impl/pom.xml

    r1522 r1544  
    3030      <artifactId>kauri-restlet-util</artifactId> 
    3131    </dependency> 
    32         <dependency> 
    33             <groupId>org.restlet.jse</groupId> 
    34             <artifactId>org.restlet.ext.crypto</artifactId> 
    35         </dependency>    
     32    <dependency> 
     33      <groupId>org.restlet.jse</groupId> 
     34      <artifactId>org.restlet.ext.crypto</artifactId> 
     35    </dependency>    
    3636    <dependency> 
    3737      <groupId>commons-logging</groupId> 
  • trunk/modules/kauri-security/kauri-security-impl/src/main/java/org/kauriproject/security/infrastructure/SecuritySetup.java

    r1533 r1544  
    3939                        return new SecurityFilter(module.getRestletContext(), module, finalRealms); 
    4040                    } 
     41                    public String getID() { 
     42                        return "org.kauriproject.security.infrastructure.FilterFactory"; 
     43                    } 
    4144                }; 
     45                 
     46                // add SecurityFilter 
    4247                module.addFilter(ff); 
     48                 
     49                // Ensure that the RepresentationFilter is also executed (when representations are active) before 
     50                // the SecurityFilter clears the SecurityContext. 
     51                // Note: keep argument below in sync with RepresentationFilterFactory.ID ! 
     52                module.duplicateFilter("org.kauriproject.representation.build.impl.RepresentationFilterFactory"); 
    4353            } 
    4454        } 
  • trunk/samples/kauri-security-sample/conf/security/auth.xml

    r1139 r1544  
    4141        <!-- example of regex path matching --> 
    4242        <protect path="/roleSensitive(JaxRs)?Resource" type="regex" access="ROLE_USER,ROLE_ADMIN"/> 
     43        <protect path="/roleSensitiveJaxRsResource/representation" access="ROLE_USER,ROLE_ADMIN"/> 
    4344        <protect path="/securepage.html" access="ROLE_USER,ROLE_ADMIN"/> 
    4445        <protect path="/authenticated.html" access="IS_AUTHENTICATED_REMEMBERED"/> 
  • trunk/samples/kauri-security-sample/src/main/java/org/kauriproject/samples/security/RoleSensitiveJaxRsResource.java

    r1107 r1544  
    11package org.kauriproject.samples.security; 
     2 
     3import java.util.HashMap; 
    24 
    35import javax.ws.rs.Path; 
     
    68import javax.ws.rs.core.SecurityContext; 
    79import javax.ws.rs.core.Context; 
     10 
     11import org.kauriproject.representation.build.KauriRepresentation; 
    812 
    913@Path("roleSensitiveJaxRsResource") 
     
    2428        } 
    2529    } 
     30     
     31    @GET 
     32    @Path("representation") 
     33    public KauriRepresentation getRepresentation() { 
     34        return new KauriRepresentation("securetemplate", new HashMap<String, Object>()); 
     35    } 
    2636 
    2737} 
  • trunk/samples/kauri-security-sample/src/main/kauri/pages/index.html.xml

    r1139 r1544  
    5353        on what role you have</a></li> 
    5454      <li><a href="securepage.html">Template using the &lt;t:protect> instruction.</a></li> 
     55      <li><a href="roleSensitiveJaxRsResource/representation">Template using the &lt;t:protect> instruction called by the representation builder.</a></li> 
    5556      <li><a href="authenticated.html">Page accessible by everyone (having any role), as long as you're 
    5657        authenticated.</a></li> 
Note: See TracChangeset for help on using the changeset viewer.