Changeset 5341
- Timestamp:
- 09/04/10 22:05:44 (17 months ago)
- Location:
- branches/release-0.13.x/pfixcore
- Files:
-
- 7 added
- 10 modified
-
pom.xml (modified) (1 diff)
-
projects/core/schema/context-xml-service-config.xsd (modified) (3 diffs)
-
res/META-INF/org/pustefixframework/config/context-xml-service/parser/context-xml-service-config.xml (modified) (3 diffs)
-
src/de/schlund/pfixcore/auth/AuthConstraint.java (modified) (3 diffs)
-
src/de/schlund/pfixcore/auth/AuthConstraintImpl.java (modified) (4 diffs)
-
src/de/schlund/pfixcore/auth/conditions/NavigationCase.java (added)
-
src/de/schlund/pfixcore/util/TransformerCallback.java (modified) (1 diff)
-
src/de/schlund/pfixcore/workflow/context/RequestContextImpl.java (modified) (3 diffs)
-
src/org/pustefixframework/config/contextxmlservice/parser/AuthConstraintParsingHandler.java (modified) (1 diff)
-
src/org/pustefixframework/config/contextxmlservice/parser/ConditionParsingHandler.java (modified) (7 diffs)
-
src/org/pustefixframework/config/contextxmlservice/parser/internal/ContextConfigImpl.java (modified) (2 diffs)
-
tests/junit/de/schlund/pfixcore/auth (added)
-
tests/junit/de/schlund/pfixcore/auth/AuthConstraintImplTest.java (added)
-
tests/junit/de/schlund/pfixcore/auth/conditions (added)
-
tests/junit/de/schlund/pfixcore/auth/conditions/BooleanCondition.java (added)
-
tests/junit/de/schlund/pfixcore/auth/conditions/BooleanConditionTest.java (added)
-
tests/junit/de/schlund/pfixcore/auth/conditions/NavigationCaseTest.java (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-0.13.x/pfixcore/pom.xml
r5322 r5341 5 5 <artifactId>pfixcore</artifactId> 6 6 <name>pfixcore</name> 7 <version>0.13.2 3</version>7 <version>0.13.24-SNAPSHOT</version> 8 8 <dependencies> 9 9 <dependency> -
branches/release-0.13.x/pfixcore/projects/core/schema/context-xml-service-config.xsd
r5339 r5341 140 140 141 141 <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> 146 149 <xs:attribute name="id" type="xs:ID" use="required"/> 147 150 <xs:attribute name="authpage" type="xs:string" use="optional"/> … … 205 208 </xs:complexType> 206 209 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 207 223 <xs:element name="condition" type="prop:conditionTopLevelType"/> 208 224 … … 324 340 <xs:complexType name="implementsType"> 325 341 <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"/> 326 345 </xs:complexType> 327 346 <!-- </context> --> -
branches/release-0.13.x/pfixcore/res/META-INF/org/pustefixframework/config/context-xml-service/parser/context-xml-service-config.xml
r4967 r5341 79 79 <match>/c:context-xml-service-config/c:authconstraint//c:authconstraint</match> 80 80 <match>/c:context-xml-service-config/c:authconstraint//c:hasrole</match> 81 <match>/c:context-xml-service-config/c:authconstraint//c:navigateTo</match> 81 82 <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:and</match> 82 83 <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:or</match> … … 85 86 <match>/c:context-xml-service-config/c:pagerequest/c:authconstraint//c:authconstraint</match> 86 87 <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> 87 89 <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:and</match> 88 90 <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:or</match> … … 91 93 <match>/c:context-xml-service-config/c:pagerequest/*[self::default or self::variant]/c:authconstraint//c:authconstraint</match> 92 94 <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> 93 96 </handler> 94 97 -
branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/auth/AuthConstraint.java
r3553 r5341 18 18 package de.schlund.pfixcore.auth; 19 19 20 import java.util.List; 21 22 import de.schlund.pfixcore.auth.conditions.NavigationCase; 20 23 import de.schlund.pfixcore.workflow.Context; 21 24 … … 30 33 31 34 public Condition getCondition(); 35 36 public List<NavigationCase> getNavigation(); 32 37 33 38 public void setCondition(Condition condition); … … 35 40 public String getId(); 36 41 37 public String getAuthPage(); 42 public String getAuthPage(Context context); 43 44 public String getDefaultAuthPage(); 38 45 39 46 } -
branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/auth/AuthConstraintImpl.java
r3553 r5341 18 18 package de.schlund.pfixcore.auth; 19 19 20 import java.util.LinkedList; 21 import java.util.List; 22 23 import de.schlund.pfixcore.auth.conditions.NavigationCase; 20 24 import de.schlund.pfixcore.workflow.Context; 21 25 … … 28 32 29 33 private Condition condition; 30 private String authPage;34 private String defaultAuthPage; 31 35 private String id; 36 37 private List<NavigationCase> navigation = new LinkedList<NavigationCase>(); 32 38 33 39 public AuthConstraintImpl(String id) { 34 40 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; 35 49 } 36 50 … … 47 61 } 48 62 49 public void setAuthPage(String authPage) {50 this.authPage = authPage;63 public String getDefaultAuthPage() { 64 return defaultAuthPage; 51 65 } 52 66 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; 55 78 } 56 79 … … 72 95 sb.append("{"); 73 96 sb.append("id=" + id); 74 sb.append(",authpage=" + authPage);97 sb.append(",authpage=" + defaultAuthPage); 75 98 sb.append("}"); 76 99 sb.append("["); -
branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/util/TransformerCallback.java
r5306 r5341 347 347 if(authConst != null) { 348 348 if(authConst.isAuthorized(context)) result = 1; 349 else if(authConst.getAuthPage( )!=null) result = 2;349 else if(authConst.getAuthPage(context)!=null) result = 2; 350 350 else result = 3; 351 351 } -
branches/release-0.13.x/pfixcore/src/de/schlund/pfixcore/workflow/context/RequestContextImpl.java
r5138 r5341 374 374 authConst = getParentContext().getContextConfig().getDefaultAuthConstraint(); 375 375 if (authConst != null) { 376 String authPageName = authConst.getAuthPage( );376 String authPageName = authConst.getAuthPage(parentcontext); 377 377 if (authPageName != null) { 378 378 currentpagerequest = createPageRequest(authPageName); … … 742 742 AuthConstraint authConstraint = pageConfig.getAuthConstraint(); 743 743 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; 745 745 } 746 746 return true; … … 771 771 authConstraint = parentcontext.getContextConfig().getDefaultAuthConstraint(); 772 772 if (authConstraint != null) { 773 String authPageName = authConstraint.getAuthPage( );773 String authPageName = authConstraint.getAuthPage(parentcontext); 774 774 if (authPageName != null) 775 775 localAuthPage = createPageRequest(authPageName); -
branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/AuthConstraintParsingHandler.java
r3822 r5341 78 78 } 79 79 String authPage = element.getAttribute("authpage").trim(); 80 if (!authPage.equals("")) constraint.setAuthPage(authPage); 81 80 if (!authPage.equals("")) constraint.setDefaultAuthPage(authPage); 82 81 } 83 82 -
branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/ConditionParsingHandler.java
r3822 r5341 38 38 import de.schlund.pfixcore.auth.conditions.ConditionGroup; 39 39 import de.schlund.pfixcore.auth.conditions.HasRole; 40 import de.schlund.pfixcore.auth.conditions.NavigationCase; 40 41 import de.schlund.pfixcore.auth.conditions.Not; 41 42 import de.schlund.pfixcore.auth.conditions.Or; … … 47 48 */ 48 49 public 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) { 57 52 Iterator<Condition> parentConditions = context.getObjectTreeElement().getObjectsOfTypeFromTopTree(Condition.class).iterator(); 58 53 Condition parentCondition = null; 59 54 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; 65 95 if (name.equals("or")) { 66 96 condition = new Or(); … … 70 100 condition = new Not(); 71 101 } else if (name.equals("hasrole")) { 102 ContextXMLServletConfigImpl config = getConfig(context); 72 103 String roleName = element.getAttribute("name").trim(); 73 104 if(roleName.equals("")) throw new ParserException("Element 'hasrole' requires 'name' attribute value."); … … 76 107 if (role == null) throw new ParserException("Condition hasrole references unknown role: " + roleName); 77 108 } else if (name.equals("condition")) { 78 if ( !inCondition) {109 if (findParentCondition(context) == null) { 79 110 String id = element.getAttribute("id").trim(); 80 111 condition = createCondition(element); 112 ContextXMLServletConfigImpl config = getConfig(context); 81 113 config.getContextConfig().addCondition(id, condition); 82 114 } else { 83 115 String ref = element.getAttribute("ref").trim(); 84 116 if (ref != null) { 117 ContextXMLServletConfigImpl config = ParsingUtils.getSingleTopObject(ContextXMLServletConfigImpl.class, context); 85 118 condition = config.getContextConfig().getCondition(ref); 86 119 if (condition == null) throw new ParserException("Condition reference not found: " + ref); … … 92 125 String ref = element.getAttribute("ref").trim(); 93 126 if(ref.equals("")) throw new ParserException("Nested authconstraint requires 'ref' attribute."); 94 if(inPageRequest) { 127 if(isInPageRequest(element)) { 128 ContextXMLServletConfigImpl config = getConfig(context); 95 129 AuthConstraint constraint = config.getContextConfig().getAuthConstraint(ref); 96 130 if(constraint == null) throw new ParserException("Referenced authconstraint not found: "+ref); … … 99 133 condition = new AuthConstraintRef(ref); 100 134 } 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); 111 144 } 112 145 113 146 PropertyParsingUtils.setProperties(condition, element); 114 115 context.getObjectTreeElement().addObject(condition);147 148 return condition; 116 149 } 117 150 118 151 private Condition createCondition(Element element) throws ParserException { 119 152 String className = element.getAttribute("class").trim(); … … 128 161 } 129 162 } 130 163 131 164 private boolean isInPageRequest(Element element) { 132 165 Node parent = element.getParentNode(); -
branches/release-0.13.x/pfixcore/src/org/pustefixframework/config/contextxmlservice/parser/internal/ContextConfigImpl.java
r5138 r5341 45 45 import de.schlund.pfixcore.auth.conditions.ConditionGroup; 46 46 import de.schlund.pfixcore.auth.conditions.HasRole; 47 import de.schlund.pfixcore.auth.conditions.NavigationCase; 47 48 import de.schlund.pfixcore.auth.conditions.Not; 48 49 import de.schlund.pfixcore.workflow.ContextInterceptor; … … 468 469 469 470 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()); 486 479 } 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 491 533 }
