Changeset 5341

Show
Ignore:
Timestamp:
09/04/10 22:05:44 (17 months ago)
Author:
ffray
Message:

Added navigateTo-elements to auth-constraints allowing to create
conditional navigation-cases.

Location:
branches/release-0.13.x/pfixcore
Files:
7 added
10 modified

Legend:

Unmodified
Added
Removed
  • branches/release-0.13.x/pfixcore/pom.xml

    r5322 r5341  
    55  <artifactId>pfixcore</artifactId> 
    66  <name>pfixcore</name> 
    7   <version>0.13.23</version> 
     7  <version>0.13.24-SNAPSHOT</version> 
    88  <dependencies> 
    99    <dependency> 
  • branches/release-0.13.x/pfixcore/projects/core/schema/context-xml-service-config.xsd

    r5339 r5341  
    140140 
    141141  <xs:complexType name="authconstraintTopLevelType"> 
    142     <xs:choice minOccurs="0"> 
    143       <xs:element ref="prop:abstractcondition" minOccurs="0"/> 
    144       <xs:element name="authconstraint" type="prop:authconstraintRefType"/> 
    145     </xs:choice> 
     142    <xs:sequence> 
     143      <xs:choice minOccurs="0"> 
     144        <xs:element ref="prop:abstractcondition" minOccurs="0"/> 
     145        <xs:element name="authconstraint" type="prop:authconstraintRefType"/> 
     146      </xs:choice> 
     147      <xs:element ref="prop:navigateTo" minOccurs="0" maxOccurs="unbounded"/> 
     148    </xs:sequence> 
    146149    <xs:attribute name="id" type="xs:ID" use="required"/> 
    147150    <xs:attribute name="authpage" type="xs:string" use="optional"/> 
     
    205208  </xs:complexType> 
    206209   
     210  <xs:element name="navigateTo" type="prop:navigateToType" /> 
     211  <xs:complexType name="navigateToType"> 
     212    <xs:complexContent> 
     213      <xs:extension base="prop:abstractconditionType"> 
     214        <xs:choice maxOccurs="unbounded"> 
     215          <xs:element ref="prop:abstractcondition"/> 
     216          <xs:element name="condition" type="prop:conditionType"/> 
     217        </xs:choice> 
     218        <xs:attribute name="page" type="xs:string" use="required" /> 
     219      </xs:extension> 
     220    </xs:complexContent> 
     221  </xs:complexType> 
     222   
    207223  <xs:element name="condition" type="prop:conditionTopLevelType"/> 
    208224   
     
    324340  <xs:complexType name="implementsType"> 
    325341    <xs:attribute name="class" use="required"/> 
     342    <xs:attribute name="bean-name" use="optional" /> 
     343    <xs:attribute name="scope" use="optional" /> 
     344    <xs:attribute name="parent-bean-ref" use="optional"/> 
    326345  </xs:complexType> 
    327346  <!-- </context> --> 
  • branches/release-0.13.x/pfixcore/res/META-INF/org/pustefixframework/config/context-xml-service/parser/context-xml-service-config.xml

    r4967 r5341  
    7979    <match>/c:context-xml-service-config/c:authconstraint//c:authconstraint</match> 
    8080    <match>/c:context-xml-service-config/c:authconstraint//c:hasrole</match> 
     81    <match>/c:context-xml-service-config/c:authconstraint//c:navigateTo</match> 
    8182    <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:and</match> 
    8283    <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:or</match> 
     
    8586    <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:authconstraint</match> 
    8687    <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:hasrole</match> 
     88    <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:navigateTo</match> 
    8789    <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:and</match> 
    8890    <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:or</match> 
     
    9193    <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:authconstraint</match> 
    9294    <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:hasrole</match> 
     95    <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:navigateTo</match> 
    9396  </handler> 
    9497  
  • branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/auth/AuthConstraint.java

    r3553 r5341  
    1818package de.schlund.pfixcore.auth; 
    1919 
     20import java.util.List; 
     21 
     22import de.schlund.pfixcore.auth.conditions.NavigationCase; 
    2023import de.schlund.pfixcore.workflow.Context; 
    2124 
     
    3033 
    3134    public Condition getCondition(); 
     35     
     36    public List<NavigationCase> getNavigation(); 
    3237 
    3338    public void setCondition(Condition condition); 
     
    3540    public String getId(); 
    3641 
    37     public String getAuthPage(); 
     42    public String getAuthPage(Context context); 
     43     
     44    public String getDefaultAuthPage(); 
    3845 
    3946} 
  • branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/auth/AuthConstraintImpl.java

    r3553 r5341  
    1818package de.schlund.pfixcore.auth; 
    1919 
     20import java.util.LinkedList; 
     21import java.util.List; 
     22 
     23import de.schlund.pfixcore.auth.conditions.NavigationCase; 
    2024import de.schlund.pfixcore.workflow.Context; 
    2125 
     
    2832 
    2933    private Condition condition; 
    30     private String authPage; 
     34    private String defaultAuthPage; 
    3135    private String id; 
     36 
     37    private List<NavigationCase> navigation = new LinkedList<NavigationCase>(); 
    3238 
    3339    public AuthConstraintImpl(String id) { 
    3440        this.id = id; 
     41    } 
     42     
     43    public void addNavigationCase(NavigationCase navigationCase) { 
     44        navigation.add(navigationCase); 
     45    } 
     46 
     47    public List<NavigationCase> getNavigation() { 
     48        return navigation; 
    3549    } 
    3650 
     
    4761    } 
    4862 
    49     public void setAuthPage(String authPage) { 
    50         this.authPage = authPage; 
     63    public String getDefaultAuthPage() { 
     64        return defaultAuthPage; 
    5165    } 
    5266 
    53     public String getAuthPage() { 
    54         return authPage; 
     67    public void setDefaultAuthPage(String authPage) { 
     68        this.defaultAuthPage = authPage; 
     69    } 
     70 
     71    public String getAuthPage(Context context) { 
     72        for (NavigationCase navcase : navigation) { 
     73            if (navcase.evaluate(context)) { 
     74                return navcase.getPage(); 
     75            } 
     76        } 
     77        return defaultAuthPage; 
    5578    } 
    5679 
     
    7295        sb.append("{"); 
    7396        sb.append("id=" + id); 
    74         sb.append(",authpage=" + authPage); 
     97        sb.append(",authpage=" + defaultAuthPage); 
    7598        sb.append("}"); 
    7699        sb.append("["); 
  • branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/util/TransformerCallback.java

    r5306 r5341  
    347347                if(authConst != null) { 
    348348                    if(authConst.isAuthorized(context)) result = 1; 
    349                     else if(authConst.getAuthPage()!=null) result = 2; 
     349                    else if(authConst.getAuthPage(context)!=null) result = 2; 
    350350                    else result = 3; 
    351351                } 
  • branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/workflow/context/RequestContextImpl.java

    r5138 r5341  
    374374                authConst = getParentContext().getContextConfig().getDefaultAuthConstraint(); 
    375375            if (authConst != null) { 
    376                 String authPageName = authConst.getAuthPage(); 
     376                String authPageName = authConst.getAuthPage(parentcontext); 
    377377                if (authPageName != null) { 
    378378                    currentpagerequest = createPageRequest(authPageName); 
     
    742742            AuthConstraint authConstraint = pageConfig.getAuthConstraint(); 
    743743            if (authConstraint == null) authConstraint = parentcontext.getContextConfig().getDefaultAuthConstraint(); 
    744             if (authConstraint != null && !authConstraint.isAuthorized(parentcontext) && authConstraint.getAuthPage()==null) return false; 
     744            if (authConstraint != null && !authConstraint.isAuthorized(parentcontext) && authConstraint.getAuthPage(parentcontext)==null) return false; 
    745745        } 
    746746        return true; 
     
    771771                authConstraint = parentcontext.getContextConfig().getDefaultAuthConstraint(); 
    772772            if (authConstraint != null) { 
    773                 String authPageName = authConstraint.getAuthPage(); 
     773                String authPageName = authConstraint.getAuthPage(parentcontext); 
    774774                if (authPageName != null) 
    775775                    localAuthPage = createPageRequest(authPageName); 
  • branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/AuthConstraintParsingHandler.java

    r3822 r5341  
    7878        } 
    7979        String authPage = element.getAttribute("authpage").trim(); 
    80         if (!authPage.equals("")) constraint.setAuthPage(authPage); 
    81          
     80        if (!authPage.equals("")) constraint.setDefaultAuthPage(authPage); 
    8281    } 
    8382 
  • branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/ConditionParsingHandler.java

    r3822 r5341  
    3838import de.schlund.pfixcore.auth.conditions.ConditionGroup; 
    3939import de.schlund.pfixcore.auth.conditions.HasRole; 
     40import de.schlund.pfixcore.auth.conditions.NavigationCase; 
    4041import de.schlund.pfixcore.auth.conditions.Not; 
    4142import de.schlund.pfixcore.auth.conditions.Or; 
     
    4748 */ 
    4849public class ConditionParsingHandler implements ParsingHandler { 
    49  
    50     public void handleNode(HandlerContext context) throws ParserException { 
    51  
    52         Element element = (Element)context.getNode(); 
    53         ParsingUtils.checkAttributes(element, null, new String[] {"name", "class", "ref", "id"}); 
    54          
    55         ContextXMLServletConfigImpl config = ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 
    56          
     50     
     51    private Condition findParentCondition(HandlerContext context) { 
    5752        Iterator<Condition> parentConditions = context.getObjectTreeElement().getObjectsOfTypeFromTopTree(Condition.class).iterator(); 
    5853        Condition parentCondition = null; 
    5954        if(parentConditions.hasNext()) parentCondition = parentConditions.next(); 
    60         boolean inCondition = ( parentCondition != null); 
    61         boolean inPageRequest = isInPageRequest(element); 
    62          
    63         String name = element.getNodeName(); 
    64         Condition condition = null; 
     55        return parentCondition; 
     56    } 
     57 
     58    public void handleNode(HandlerContext context) throws ParserException { 
     59        Condition condition = parseCondition(context); 
     60 
     61        //assemble the parent element by setting or adding the parsed condition 
     62        Condition parentCondition = findParentCondition(context); 
     63        if(parentCondition != null) { 
     64            if (parentCondition instanceof NavigationCase) { 
     65                ((NavigationCase) parentCondition).setCondition(condition); 
     66            } else if (parentCondition instanceof AuthConstraint) { 
     67                AuthConstraintImpl authConstraint = (AuthConstraintImpl) parentCondition; 
     68                if (condition instanceof NavigationCase) { 
     69                    authConstraint.addNavigationCase(((NavigationCase) condition)); 
     70                } else { 
     71                    authConstraint.setCondition(condition); 
     72                } 
     73            } else if (parentCondition instanceof ConditionGroup) { 
     74                ((ConditionGroup) parentCondition).add(condition); 
     75            } else if (parentCondition instanceof Not) { 
     76                ((Not) parentCondition).set(condition); 
     77            } else throw new ParserException("Illegal object: " + parentCondition.getClass().getName()); 
     78        } 
     79 
     80        context.getObjectTreeElement().addObject(condition); 
     81    } 
     82 
     83    private ContextXMLServletConfigImpl getConfig(HandlerContext context) throws ParserException { 
     84        return ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 
     85    } 
     86 
     87    private Condition parseCondition(HandlerContext context) throws ParserException { 
     88 
     89        Element element = (Element)context.getNode(); 
     90        ParsingUtils.checkAttributes(element, null, new String[] {"page", "name", "class", "ref", "id"}); 
     91 
     92        String name = element.getTagName(); 
     93 
     94        Condition condition; 
    6595        if (name.equals("or")) { 
    6696            condition = new Or(); 
     
    70100            condition = new Not(); 
    71101        } else if (name.equals("hasrole")) { 
     102            ContextXMLServletConfigImpl config = getConfig(context); 
    72103            String roleName = element.getAttribute("name").trim(); 
    73104            if(roleName.equals("")) throw new ParserException("Element 'hasrole' requires 'name' attribute value."); 
     
    76107            if (role == null) throw new ParserException("Condition hasrole references unknown role: " + roleName); 
    77108        } else if (name.equals("condition")) { 
    78             if (!inCondition) { 
     109            if (findParentCondition(context) == null) { 
    79110                String id = element.getAttribute("id").trim(); 
    80111                condition = createCondition(element); 
     112                ContextXMLServletConfigImpl config = getConfig(context); 
    81113                config.getContextConfig().addCondition(id, condition); 
    82114            } else { 
    83115                String ref = element.getAttribute("ref").trim(); 
    84116                if (ref != null) { 
     117                    ContextXMLServletConfigImpl config = ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 
    85118                    condition = config.getContextConfig().getCondition(ref); 
    86119                    if (condition == null) throw new ParserException("Condition reference not found: " + ref); 
     
    92125            String ref = element.getAttribute("ref").trim(); 
    93126            if(ref.equals("")) throw new ParserException("Nested authconstraint requires 'ref' attribute."); 
    94             if(inPageRequest) { 
     127            if(isInPageRequest(element)) { 
     128                ContextXMLServletConfigImpl config = getConfig(context); 
    95129                AuthConstraint constraint = config.getContextConfig().getAuthConstraint(ref); 
    96130                if(constraint == null) throw new ParserException("Referenced authconstraint not found: "+ref); 
     
    99133                condition = new AuthConstraintRef(ref); 
    100134            } 
    101         } else throw new ParserException("Unsupported condition: " + name); 
    102        
    103         if(inCondition) { 
    104             if (parentCondition instanceof AuthConstraint) { 
    105                 ((AuthConstraintImpl) parentCondition).setCondition(condition); 
    106             } else if (parentCondition instanceof ConditionGroup) { 
    107                 ((ConditionGroup) parentCondition).add(condition); 
    108             } else if (parentCondition instanceof Not) { 
    109                 ((Not) parentCondition).set(condition); 
    110             } else throw new ParserException("Illegal object: " + parentCondition.getClass().getName()); 
     135        } else if (name.equals("navigateTo")) { 
     136            String page = element.getAttribute("page").trim(); 
     137            if (page.equals("")) { 
     138                throw new ParserException("Element navigation requires 'page' attribute."); 
     139            } 
     140            NavigationCase navigationCase = new NavigationCase(page); 
     141            condition = navigationCase; 
     142        } else { 
     143            throw new ParserException("Unsupported condition: " + name); 
    111144        } 
    112          
     145 
    113146        PropertyParsingUtils.setProperties(condition, element); 
    114          
    115         context.getObjectTreeElement().addObject(condition); 
     147 
     148        return condition; 
    116149    } 
    117      
     150 
    118151    private Condition createCondition(Element element) throws ParserException { 
    119152        String className = element.getAttribute("class").trim(); 
     
    128161        } 
    129162    } 
    130      
     163 
    131164    private boolean isInPageRequest(Element element) { 
    132165        Node parent = element.getParentNode(); 
  • branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/internal/ContextConfigImpl.java

    r5138 r5341  
    4545import de.schlund.pfixcore.auth.conditions.ConditionGroup; 
    4646import de.schlund.pfixcore.auth.conditions.HasRole; 
     47import de.schlund.pfixcore.auth.conditions.NavigationCase; 
    4748import de.schlund.pfixcore.auth.conditions.Not; 
    4849import de.schlund.pfixcore.workflow.ContextInterceptor; 
     
    468469     
    469470    private void checkAuthConstraint(AuthConstraint authConstraint, Set<String> authPages, String lastAuthPage) throws Exception { 
    470         String authPage = authConstraint.getAuthPage(); 
    471         if (authPage != null && !authPage.equals(lastAuthPage)) { 
    472             if (authPages.contains(authPage)) { 
    473                 StringBuilder sb = new StringBuilder(); 
    474                 for (String s : authPages) 
    475                     sb.append(s + " -> "); 
    476                 sb.append(authPage); 
    477                 throw new Exception("Circular authconstraint@authpage reference: " + sb.toString()); 
    478             } 
    479             PageRequestConfigImpl cfg = getPageRequestConfig(authPage); 
    480             if (cfg != null) { 
    481                 AuthConstraint ac = cfg.getAuthConstraint(); 
    482                 if (ac == null) ac = getDefaultAuthConstraint(); 
    483                 if (ac != null) { 
    484                     authPages.add(authPage); 
    485                     checkAuthConstraint(ac, authPages, authPage); 
     471        for (String authPage : traverseAuthPages(authConstraint)) { 
     472            if (authPage != null && !authPage.equals(lastAuthPage)) { 
     473                if (authPages.contains(authPage)) { 
     474                    StringBuilder sb = new StringBuilder(); 
     475                    for (String s : authPages) 
     476                        sb.append(s + " -> "); 
     477                    sb.append(authPage); 
     478                    throw new Exception("Circular authconstraint@authpage reference: " + sb.toString()); 
    486479                } 
    487             } else throw new Exception("Authpage not configured: " + authPage); 
    488         } 
    489     } 
    490      
     480                PageRequestConfigImpl cfg = getPageRequestConfig(authPage); 
     481                if (cfg != null) { 
     482                    AuthConstraint ac = cfg.getAuthConstraint(); 
     483                    if (ac == null) ac = getDefaultAuthConstraint(); 
     484                    if (ac != null) { 
     485                        authPages.add(authPage); 
     486                        checkAuthConstraint(ac, authPages, authPage); 
     487                    } 
     488                } else throw new Exception("Authpage not configured: " + authPage); 
     489            } 
     490        } 
     491    } 
     492 
     493    private Iterable<String> traverseAuthPages(final AuthConstraint authConstraint) { 
     494        return new Iterable<String>() { 
     495            @Override 
     496            public Iterator<String> iterator() { 
     497                return new Iterator<String>() { 
     498 
     499                    private Iterator<NavigationCase> navCases = 
     500                        authConstraint.getNavigation().iterator(); 
     501 
     502                    private boolean visitedDefaultAuthPage; 
     503 
     504                    private boolean isDefaultPageVisitable() { 
     505                        return !visitedDefaultAuthPage && authConstraint.getDefaultAuthPage() != null; 
     506                    } 
     507 
     508                    @Override 
     509                    public boolean hasNext() { 
     510                        return isDefaultPageVisitable() || 
     511                               navCases.hasNext(); 
     512                    } 
     513 
     514                    @Override 
     515                    public String next() { 
     516                        if (isDefaultPageVisitable()) { 
     517                            String result = authConstraint.getDefaultAuthPage(); 
     518                            visitedDefaultAuthPage = true; 
     519                            return result; 
     520                        } 
     521                        return navCases.next().getPage(); 
     522                    } 
     523 
     524                    @Override 
     525                    public void remove() { 
     526                        throw new UnsupportedOperationException();  
     527                    } 
     528                }; 
     529            } 
     530        }; 
     531    } 
     532 
    491533}