1 23 24 package org.apache.slide.webdav.util; 25 import java.io.IOException ; 26 import java.io.StringReader ; 27 import java.util.ArrayList ; 28 import java.util.Collections ; 29 import java.util.Date ; 30 import java.util.Enumeration ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Set ; 36 37 import org.apache.commons.codec.digest.DigestUtils; 38 import org.apache.slide.authenticate.CredentialsToken; 39 import org.apache.slide.common.Domain; 40 import org.apache.slide.common.NamespaceAccessToken; 41 import org.apache.slide.common.NamespaceConfig; 42 import org.apache.slide.common.ServiceAccessException; 43 import org.apache.slide.common.SlideException; 44 import org.apache.slide.common.SlideToken; 45 import org.apache.slide.common.Uri; 46 import org.apache.slide.common.UriPath; 47 import org.apache.slide.content.Content; 48 import org.apache.slide.content.NodeProperty; 49 import org.apache.slide.content.NodeRevisionDescriptor; 50 import org.apache.slide.content.NodeRevisionDescriptors; 51 import org.apache.slide.content.NodeRevisionNumber; 52 import org.apache.slide.content.RevisionDescriptorNotFoundException; 53 import org.apache.slide.content.NodeProperty.NamespaceCache; 54 import org.apache.slide.event.VetoException; 55 import org.apache.slide.lock.Lock; 56 import org.apache.slide.lock.LockTokenNotFoundException; 57 import org.apache.slide.lock.NodeLock; 58 import org.apache.slide.lock.ObjectLockedException; 59 import org.apache.slide.search.RequestedResource; 60 import org.apache.slide.search.Search; 61 import org.apache.slide.search.SearchQuery; 62 import org.apache.slide.search.SearchQueryResult; 63 import org.apache.slide.security.ACLSecurityImpl; 64 import org.apache.slide.security.AccessDeniedException; 65 import org.apache.slide.security.NodePermission; 66 import org.apache.slide.security.Security; 67 import org.apache.slide.security.SecurityImpl; 68 import org.apache.slide.structure.ActionNode; 69 import org.apache.slide.structure.LinkedObjectNotFoundException; 70 import org.apache.slide.structure.ObjectNode; 71 import org.apache.slide.structure.ObjectNotFoundException; 72 import org.apache.slide.structure.Structure; 73 import org.apache.slide.structure.SubjectNode; 74 import org.apache.slide.util.Configuration; 75 import org.apache.slide.util.XMLValue; 76 import org.apache.slide.webdav.WebdavServletConfig; 77 import org.apache.slide.webdav.method.LockMethod; 78 import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind; 79 import org.apache.slide.webdav.util.resourcekind.Activity; 80 import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled; 81 import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled; 82 import org.apache.slide.webdav.util.resourcekind.DeltavCompliantCollection; 83 import org.apache.slide.webdav.util.resourcekind.ResourceKind; 84 import org.apache.slide.webdav.util.resourcekind.Version; 85 import org.apache.slide.webdav.util.resourcekind.VersionHistory; 86 import org.apache.slide.webdav.util.resourcekind.Workspace; 87 import org.jdom.Attribute; 88 import org.jdom.CDATA; 89 import org.jdom.Document; 90 import org.jdom.Element; 91 import org.jdom.JDOMException; 92 import org.jdom.Namespace; 93 import org.jdom.Text; 94 import org.jdom.input.SAXBuilder; 95 96 97 98 102 103 public class PropertyHelper extends AbstractWebdavHelper implements WebdavConstants, DeltavConstants, AclConstants, DaslConstants, BindConstants { 104 105 public final static String LOCKDISCOVERY_INCL_PRINCIPAL = 106 "lockdiscoveryIncludesPrincipalURL"; 107 108 public final static String PRIVILEGE_NAMESPACE = "privilege-namespace"; 109 110 private boolean lockdiscoveryIncludesPrincipalURL = true; 111 112 116 protected Element checkoutSetQueryElement = null; 117 118 122 protected Element checkoutSetQueryLiteralElement = null; 123 124 128 protected Element workspaceCheckoutSetQueryElement = null; 129 130 134 protected Element workspaceCheckoutSetQueryHrefElement = null; 135 136 private WebdavServletConfig sConf = null; 137 138 139 140 144 149 152 public static PropertyHelper 153 getPropertyHelper( SlideToken sToken, NamespaceAccessToken nsaToken, WebdavServletConfig sConf ) { 154 return new PropertyHelper( sToken, nsaToken, sConf ); 155 } 156 157 158 161 protected PropertyHelper( SlideToken sToken, NamespaceAccessToken nsaToken, WebdavServletConfig sConf ) { 162 super( sToken, nsaToken ); 163 this.sConf = sConf; 164 if( sConf != null ) 165 lockdiscoveryIncludesPrincipalURL = 166 !("false".equalsIgnoreCase(sConf.getInitParameter(LOCKDISCOVERY_INCL_PRINCIPAL))); 167 } 168 169 176 public List createInitialProperties( ResourceKind resourceKind, String resourcePath ) { 177 178 Set sp = resourceKind.getSupportedLiveProperties(); 179 List result = null; 180 181 if( sp == null ) 182 result = Collections.EMPTY_LIST; 183 else { 184 result = new ArrayList (); 185 Iterator i = sp.iterator(); 186 while( i.hasNext() ) { 187 String propName = (String )i.next(); 188 if( AbstractResourceKind.isComputedProperty(propName) ) 189 continue; 190 Object pvalue = createDefaultValue( propName, resourceKind, resourcePath ); 191 if (pvalue != null) { 192 result.add( new NodeProperty(propName, pvalue) ); 193 } 194 } 195 } 196 return result; 197 } 198 199 203 Object createDefaultValue( String propName, ResourceKind resourceKind, String resourcePath ) { 204 205 String autoVersion = 206 Domain.getParameter(I_AUTO_VERSION, 207 I_AUTO_VERSION_DEFAULT, 208 nsaToken.getUri(sToken, resourcePath).getStore()); 209 210 String checkoutFork = 211 Domain.getParameter(I_CHECKOUT_FORK, 212 I_CHECKOUT_FORK_DEFAULT, 213 nsaToken.getUri(sToken, resourcePath).getStore()); 214 215 String checkinFork = 216 Domain.getParameter(I_CHECKIN_FORK, 217 I_CHECKIN_FORK_DEFAULT, 218 nsaToken.getUri(sToken, resourcePath).getStore()); 219 220 String result = null; 221 222 if( P_RESOURCETYPE.equals(propName) ) { 223 StringBuffer rtvv = new StringBuffer (); 224 try { 225 if( resourceKind instanceof VersionHistory ) { 226 rtvv.append( 227 xmlOut.outputString(new Element(E_VERSION_HISTORY, DNSP)) ); 228 rtvv.append( 229 xmlOut.outputString(new Element(E_COLLECTION, DNSP)) ); 230 } 231 if( resourceKind instanceof DeltavCompliantCollection ) { 232 rtvv.append( 233 xmlOut.outputString(new Element(E_COLLECTION, DNSP)) ); 234 } 235 if( resourceKind instanceof Activity ) { 236 rtvv.append( 237 xmlOut.outputString(new Element(E_ACTIVITY, DNSP)) ); 238 } 239 } 240 catch( Exception x ) { 241 x.printStackTrace(); 242 } 243 result = rtvv.toString(); 244 } 245 else if( P_SUPPORTED_METHOD_SET.equals(propName) ) { 246 Iterator i = resourceKind.getSupportedMethods().iterator(); 247 StringBuffer smsv = new StringBuffer (); 248 while( i.hasNext() ) { 249 String m = (String ) i.next(); 250 Element sm = new Element( E_SUPPORTED_METHOD, DNSP ); 251 Attribute na = new Attribute( A_NAME, m, DNSP ); 252 sm.setAttribute( na ); 253 try { 254 smsv.append( xmlOut.outputString(sm) ); 255 } 256 catch( Exception x ) { x.printStackTrace(); } 257 } 258 result = smsv.toString(); 259 } 260 else if( P_SUPPORTED_LIVE_PROPERTY_SET.equals(propName) ) { 261 Iterator i = resourceKind.getSupportedLiveProperties().iterator(); 262 StringBuffer spsv = new StringBuffer (); 263 while( i.hasNext() ) { 264 String p = (String ) i.next(); 265 Element sp = new Element( E_SUPPORTED_LIVE_PROPERTY, DNSP ); 266 Element na = new Element( E_NAME, DNSP ); 267 na.addContent( p ); 268 sp.addContent( na ); 269 try { 270 spsv.append( xmlOut.outputString(sp) ); 271 } 272 catch( Exception x ) { x.printStackTrace(); } 273 } 274 result = spsv.toString(); 275 } 276 else if( P_SUPPORTED_REPORT_SET.equals(propName) ) { 277 Iterator i = resourceKind.getSupportedReports().iterator(); 278 StringBuffer srsv = new StringBuffer (); 279 while( i.hasNext() ) { 280 String r = (String ) i.next(); 281 Element sr = new Element( E_SUPPORTED_REPORT, DNSP ); 282 Element na = new Element( E_NAME, DNSP ); 283 na.addContent( r ); 284 sr.addContent( na ); 285 try { 286 srsv.append( xmlOut.outputString(sr) ); 287 } 288 catch( Exception x ) { x.printStackTrace(); } 289 } 290 result = srsv.toString(); 291 } 292 else if( P_AUTO_VERSION.equals(propName) ) { 293 294 XMLValue xmlValue = new XMLValue(); 295 296 if (autoVersion.length() > 0) { 297 xmlValue.add(new Element(autoVersion, DNSP)); 298 } 299 300 if( ! resourceKind.isSupportedPropertyValue(P_AUTO_VERSION, xmlValue) ) { 301 Domain.warn( "Auto-version not configured properly; using " 302 +E_CHECKOUT_CHECKIN ); 303 xmlValue = new XMLValue(new Element(E_CHECKOUT_CHECKIN, DNSP)); 304 } 305 306 result = xmlValue.toString(); 307 } 308 else if( P_CHECKOUT_FORK.equals(propName) ) { 309 310 XMLValue xmlValue = new XMLValue(); 311 312 if (checkoutFork.length() > 0) { 313 xmlValue.add(new Element(checkoutFork, DNSP)); 314 } 315 316 if( ! resourceKind.isSupportedPropertyValue(P_CHECKOUT_FORK, xmlValue) ) { 317 Domain.warn( "Checkout-fork not configured properly; using " 318 +E_FORBIDDEN ); 319 xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP)); 320 } 321 322 result = xmlValue.toString(); 323 } 324 else if( P_CHECKIN_FORK.equals(propName) ) { 325 326 XMLValue xmlValue = new XMLValue(); 327 328 if (checkinFork.length() > 0) { 329 xmlValue.add(new Element(checkinFork, DNSP)); 330 } 331 332 if( ! resourceKind.isSupportedPropertyValue(P_CHECKIN_FORK, xmlValue) ) { 333 Domain.warn( "Checkin-fork not configured properly; using " 334 +E_FORBIDDEN ); 335 xmlValue = new XMLValue(new Element(E_FORBIDDEN, DNSP)); 336 } 337 338 result = xmlValue.toString(); 339 } 340 else if( P_GETCONTENTLANGUAGE.equals(propName) ) { 341 result = "en"; 342 } 343 else if( P_CREATOR_DISPLAYNAME.equals(propName) ) { 344 if( sToken != null ) { 345 CredentialsToken credToken = sToken.getCredentialsToken(); 346 if( credToken != null ) { 347 result = credToken.getPublicCredentials(); 348 if (result == null || result.equals("") || result.equals("/")) { 349 result = SubjectNode.UNAUTHENTICATED_URI; 350 } 351 } 352 } 353 } 354 else if( P_PREDECESSOR_SET.equals(propName) ) { 356 result = ""; 357 } 358 else if( P_CHECKOUT_SET.equals(propName) ) { 359 result = ""; 360 } 361 else if( P_COMMENT.equals(propName) ) { 362 result = ""; 363 } 364 else if( P_LABEL_NAME_SET.equals(propName) ) { 365 result = ""; 366 } 367 return result; 368 } 369 370 373 public Object createCdataValue( String text ) { 374 StringBuffer b = new StringBuffer (); 375 if( text == null ) 376 text = ""; 377 b.append( "![CDATA[" ).append( text ).append( "]]" ); 378 return b.toString(); 379 } 380 381 384 public Object createHrefValue( String uri ) { 385 String result = ""; 386 387 Element href = new Element( E_HREF, DNSP ); 388 href.addContent( uri ); 389 try { 390 result = xmlOut.outputString( href ); 391 } 392 catch( Exception x ) { 393 x.printStackTrace(); 394 } 395 396 return result; 397 } 398 399 402 public Object createHrefSetValue( List uriList ) { 403 StringBuffer b = new StringBuffer (); 404 Iterator i = uriList.iterator(); 405 while( i.hasNext() ) 406 b.append( createHrefValue((String )i.next()) ); 407 return b.toString(); 408 } 409 410 413 public Object createHrefSetValue( String rootElement, List uriList ) { 414 String result = ""; 415 416 Element root = new Element( rootElement, DNSP ); 417 Iterator i = uriList.iterator(); 418 419 while( i.hasNext() ) { 420 Element href = new Element( E_HREF, DNSP ); 421 href.addContent( (String )i.next() ); 422 root.addContent( href ); 423 } 424 try { 425 result = xmlOut.outputString( root ); 426 } 427 catch( Exception x ) { 428 x.printStackTrace(); 429 } 430 431 return result; 432 } 433 434 437 public Element parsePropertyValue( String propValue ) throws JDOMException, IOException { 438 Document d = xmlBuilder.build( new StringReader (propValue) ); 439 return d.getRootElement(); 440 } 441 442 455 public NodeProperty getProperty(String propertyName, String resourcePath) throws SlideException, JDOMException { 456 return getProperty(propertyName, resourcePath, null); 457 } 458 459 473 public NodeProperty getProperty(String propertyName, String resourcePath, String slideContextPath) throws SlideException, JDOMException { 474 475 UriHandler uriHandler = UriHandler.getUriHandler(resourcePath); 476 String uri = null; 477 NodeRevisionDescriptors revisionDescriptors = null; 478 NodeRevisionDescriptor revisionDescriptor = null; 479 Content contentHelper = nsaToken.getContentHelper(); 480 481 if (uriHandler.isVersionUri()) { 482 uri = uriHandler.getAssociatedHistoryUri(); 483 NodeRevisionNumber revisionNumber = new NodeRevisionNumber(uriHandler.getVersionName()); 484 revisionDescriptors = contentHelper.retrieve(sToken, uri); 485 revisionDescriptor = contentHelper.retrieve(sToken, revisionDescriptors, revisionNumber); 486 } 487 else if (uriHandler.isHistoryUri()) { 488 uri = uriHandler.getAssociatedHistoryUri(); 489 NodeRevisionNumber revisionNumber = new NodeRevisionNumber("0.0"); 490 revisionDescriptors = contentHelper.retrieve(sToken, uri); 491 revisionDescriptor = contentHelper.retrieve(sToken, revisionDescriptors, revisionNumber); 492 } 493 else { 494 uri = resourcePath; 495 revisionDescriptors = contentHelper.retrieve(sToken, uri); 496 revisionDescriptor = contentHelper.retrieve(sToken, revisionDescriptors); 497 } 498 return getProperty(propertyName, revisionDescriptors, revisionDescriptor, slideContextPath); 499 } 500 501 515 public NodeProperty getProperty(String propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws SlideException, JDOMException { 516 return getProperty(propertyName, revisionDescriptors, revisionDescriptor, null); 517 } 518 519 534 public NodeProperty getProperty(String propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws SlideException, JDOMException { 535 536 NodeProperty property = revisionDescriptor.getProperty( propertyName ); 537 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 538 if (resourceKind.isSupportedLiveProperty(propertyName)) { 539 if (AbstractResourceKind.isComputedProperty(propertyName)) { 540 property = computeProperty(propertyName, revisionDescriptors, revisionDescriptor, slideContextPath); 541 } 542 } 543 544 return property; 545 } 546 547 561 public NodeProperty computeProperty(String propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws SlideException, JDOMException { 562 563 NodeProperty property = null; 564 if (P_SUCCESSOR_SET.equals(propertyName)) { 565 property = new NodeProperty(propertyName, computeSuccessorSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 566 } 567 else if (P_VERSION_HISTORY.equals(propertyName)) { 568 property = new NodeProperty(propertyName, computeVersionHistory(revisionDescriptors, revisionDescriptor, slideContextPath)); 569 } 570 else if (P_ROOT_VERSION.equals(propertyName)) { 571 property = new NodeProperty(propertyName, computeRootVersion(revisionDescriptors, revisionDescriptor, slideContextPath)); 572 } 573 else if (P_SUPPORTED_METHOD_SET.equals(propertyName)) { 574 property = new NodeProperty(propertyName, computeSupportedMethodSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 575 } 576 else if (P_SUPPORTED_LIVE_PROPERTY_SET.equals(propertyName)) { 577 property = new NodeProperty(propertyName, computeSupportedLivePropertySet(revisionDescriptors, revisionDescriptor, slideContextPath)); 578 } 579 else if (P_SUPPORTED_REPORT_SET.equals(propertyName)) { 580 property = new NodeProperty(propertyName, computeSupportedReportSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 581 } 582 else if (P_CHECKOUT_SET.equals(propertyName)) { 583 property = new NodeProperty(propertyName, computeCheckoutSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 584 } 585 else if (P_WORKSPACE_CHECKOUT_SET.equals(propertyName)) { 586 property = new NodeProperty(propertyName, computeWorkspaceCheckoutSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 587 } 588 else if (P_WORKSPACE.equals(propertyName)) { 589 XMLValue ws = null; 590 if (Configuration.useBinding(nsaToken.getUri(sToken, revisionDescriptors.getUri()).getStore())) { 591 ws = computeWorkspace(revisionDescriptors, revisionDescriptor, slideContextPath); 592 } 593 else { 594 ws = computeWorkspaceNoBinding(revisionDescriptors, revisionDescriptor, slideContextPath); 595 } 596 if (ws != null) { 597 property = new NodeProperty(propertyName, ws); 598 } 599 } 600 601 else if (P_LOCKDISCOVERY.equals(propertyName)) { 602 property = new NodeProperty(propertyName, computeLockDiscovery(revisionDescriptors, revisionDescriptor, slideContextPath)); 603 } 604 else if (P_SUPPORTEDLOCK.equals(propertyName)) { 605 property = new NodeProperty(propertyName, computeSupportedlock(revisionDescriptors, revisionDescriptor, slideContextPath)); 606 } 607 else if (P_SUPPORTED_PRIVILEGE_SET.equals(propertyName)) { 608 property = new NodeProperty(propertyName, computeSupportedPrivilegeSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 609 } 610 else if (P_CURRENT_USER_PRIVILEGE_SET.equals(propertyName)) { 611 property = new NodeProperty(propertyName, computeCurrentuserPrivilegeSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 612 } 613 else if (P_ACL.equals(propertyName)) { 614 property = new NodeProperty(propertyName, computeAcl(revisionDescriptors, revisionDescriptor, slideContextPath)); 615 } 616 else if (P_PRINCIPAL_COLLECTION_SET.equals(propertyName)) { 617 property = new NodeProperty(propertyName, computePrincipalCollectionSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 618 } 619 else if (P_PRIVILEGE_COLLECTION_SET.equals(propertyName)) { 620 property = new NodeProperty(propertyName, computePrivilegeCollectionSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 621 } 622 else if (P_OWNER.equals(propertyName)) { 623 property = new NodeProperty(propertyName, computeOwner(revisionDescriptors, revisionDescriptor, slideContextPath)); 624 } 625 else if (P_CREATIONUSER.equals(propertyName)) { 626 property = new NodeProperty(propertyName, computeCreationUser(revisionDescriptors, revisionDescriptor, slideContextPath)); 627 } 628 else if (P_MODIFICATIONUSER.equals(propertyName)) { 629 property = new NodeProperty(propertyName, computeModificationUser(revisionDescriptors, revisionDescriptor, slideContextPath)); 630 } 631 else if (P_INHERITED_ACL_SET.equals(propertyName)) { 632 property = new NodeProperty(propertyName, computeInheritedAclSet(revisionDescriptors, revisionDescriptor, slideContextPath)); 633 } 634 else if (P_ACL_RESTRICTIONS.equals(propertyName)) { 635 property = new NodeProperty(propertyName, computeAclRestrictions(revisionDescriptors, revisionDescriptor, slideContextPath)); 636 } 637 else if (P_GROUP_MEMBERSHIP.equals(propertyName)) { 638 property = new NodeProperty(propertyName, computeGroupMembership(revisionDescriptors, revisionDescriptor, slideContextPath)); 639 } 640 641 return property; 642 } 643 644 666 public XMLValue computeSuccessorSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException { 667 668 XMLValue xmlValue = new XMLValue(); 669 Element hrefElement = new Element(E_HREF, DNSP); 670 NodeRevisionNumber successorRevisionNumber = null; 672 Enumeration successorEnum = revisionDescriptors.getSuccessors(revisionDescriptor.getRevisionNumber()); 673 674 if (successorEnum != null) { 675 while (successorEnum.hasMoreElements()) { 676 successorRevisionNumber = (NodeRevisionNumber)successorEnum.nextElement(); 677 hrefElement = (Element)hrefElement.clone(); 678 StringBuffer buffer = new StringBuffer (revisionDescriptors.getUri()); 679 if ( ! revisionDescriptors.getUri().endsWith("/") ) { 680 buffer.append("/"); 681 } 682 buffer.append(successorRevisionNumber.toString()); 683 684 hrefElement.setText(WebdavUtils.getAbsolutePath ( 685 buffer.toString(), 686 slideContextPath, sConf)); 687 688 xmlValue.add(hrefElement); 689 } 690 } 691 return xmlValue; 692 } 693 694 714 public XMLValue computeVersionHistory(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, JDOMException { 715 716 XMLValue xmlValue = new XMLValue(); 717 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 718 if (resourceKind instanceof Version) { 719 Element element = new Element(E_HREF, DNSP); 720 721 element.setText(WebdavUtils.getAbsolutePath ( 722 revisionDescriptors.getUri(), slideContextPath, 723 sConf)); 724 725 xmlValue.add(element); 726 } 727 else if (resourceKind instanceof CheckedInVersionControlled) { 728 Element element = new Element(E_HREF, DNSP); 729 String checkedInHref = revisionDescriptor.getProperty(P_CHECKED_IN).getValue().toString(); 730 String checkedInUri = ((Element)new XMLValue(checkedInHref).iterator().next()).getText(); 731 UriHandler uriHandler = UriHandler.getUriHandler(checkedInUri); 732 733 element.setText (WebdavUtils.getAbsolutePath ( 734 uriHandler.getAssociatedHistoryUri(), 735 slideContextPath, sConf)); 736 737 xmlValue.add(element); 738 } 739 else if (resourceKind instanceof CheckedOutVersionControlled) { 740 Element element = new Element(E_HREF, DNSP); 741 String checkedOutHref = revisionDescriptor.getProperty(P_CHECKED_OUT).getValue().toString(); 742 String checkedOutUri = ((Element)new XMLValue(checkedOutHref).iterator().next()).getText(); 743 UriHandler uriHandler = UriHandler.getUriHandler(checkedOutUri); 744 745 element.setText(WebdavUtils.getAbsolutePath ( 746 uriHandler.getAssociatedHistoryUri(), 747 slideContextPath, sConf)); 748 749 xmlValue.add(element); 750 } 751 752 return xmlValue; 753 } 754 755 774 public XMLValue computeRootVersion(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException { 775 776 XMLValue xmlValue = new XMLValue(); 777 778 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 779 if (resourceKind instanceof VersionHistory) { 780 Element element = new Element(E_HREF, DNSP); 781 StringBuffer buffer = new StringBuffer (revisionDescriptors.getUri()); 782 if ( ! revisionDescriptors.getUri().endsWith("/") ) { 783 buffer.append("/"); 784 } 785 buffer.append(revisionDescriptors.getInitialRevision().toString()); 786 787 element.setText(WebdavUtils.getAbsolutePath ( 788 buffer.toString(), 789 slideContextPath, sConf)); 790 791 xmlValue.add(element); 792 } 793 794 return xmlValue; 795 } 796 797 822 public XMLValue computeSupportedMethodSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException { 823 824 XMLValue xmlValue = new XMLValue(); 825 826 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 827 Set supportedMethodNames = resourceKind.getSupportedMethods(); 828 Iterator iterator = supportedMethodNames.iterator(); 829 Element supportedMethod = null; 830 while (iterator.hasNext()) { 831 supportedMethod = new Element(E_SUPPORTED_METHOD, DNSP); 832 supportedMethod.setAttribute(new Attribute(E_NAME, (String )iterator.next())); 833 xmlValue.add(supportedMethod); 834 } 835 836 return xmlValue; 837 } 838 839 865 public XMLValue computeSupportedLivePropertySet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException { 866 867 XMLValue xmlValue = new XMLValue(); 868 869 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 870 Set supportedLivePropertyNames = resourceKind.getSupportedLiveProperties(); 871 Iterator iterator = supportedLivePropertyNames.iterator(); 872 Element supportedLivePropertyElement = null; 873 Element propElement = null; 874 Element propertyElement = null; 875 while (iterator.hasNext()) { 876 877 supportedLivePropertyElement = new Element(E_SUPPORTED_LIVE_PROPERTY, DNSP); 878 propElement = new Element(E_PROP, DNSP); 879 supportedLivePropertyElement.addContent(propElement); 880 propertyElement = new Element((String )iterator.next(), DNSP); 881 propElement.addContent(propertyElement); 882 xmlValue.add(supportedLivePropertyElement); 883 } 884 885 return xmlValue; 886 } 887 888 914 public XMLValue computeSupportedReportSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException { 915 916 XMLValue xmlValue = new XMLValue(); 917 918 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 919 Set supportedReportNames = resourceKind.getSupportedReports(); 920 Iterator iterator = supportedReportNames.iterator(); 921 Element supportedReportElement = null; 922 Element reportElement = null; 923 Element propertyElement = null; 924 while (iterator.hasNext()) { 925 926 supportedReportElement = new Element(E_SUPPORTED_REPORT, DNSP); 927 reportElement = new Element(E_REPORT, DNSP); 928 supportedReportElement.addContent(reportElement); 929 propertyElement = new Element((String )iterator.next(), DNSP); 930 reportElement.addContent(propertyElement); 931 xmlValue.add(supportedReportElement); 932 } 933 934 return xmlValue; 935 } 936 937 957 public XMLValue computeCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) throws SlideException, JDOMException { 958 return computeCheckoutSet(revisionDescriptors, revisionDescriptor, null); 959 } 960 961 977 public XMLValue computeCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws SlideException, JDOMException { 978 979 XMLValue xmlValue = new XMLValue(); 980 981 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 982 if (resourceKind instanceof Version) { 983 984 String resourcePath = VersioningHelper.getUri(nsaToken, 985 sToken, 986 nsaToken.getContentHelper(), 987 revisionDescriptors, 988 revisionDescriptor); 989 990 Element basicSearch = getCheckoutSetQueryElement(resourcePath); 991 992 String grammarNamespace = basicSearch.getNamespaceURI(); 993 Search searchHelper = nsaToken.getSearchHelper(); 994 SearchQuery searchQuery = searchHelper.createSearchQuery(grammarNamespace, 996 basicSearch, 997 sToken, 998 Integer.MAX_VALUE, 999 slideContextPath); 1000 1001 SearchQueryResult queryResult = searchHelper.search(sToken, searchQuery); 1002 Iterator queryResultIterator = queryResult.iterator(); 1003 RequestedResource requestedResource = null; 1004 Element href = null; 1005 while (queryResultIterator.hasNext()) { 1006 requestedResource = (RequestedResource)queryResultIterator.next(); 1007 href = new Element(E_HREF, DNSP); 1008 1009 href.setText (WebdavUtils.getAbsolutePath ( 1010 requestedResource.getUri(), slideContextPath, sConf)); 1011 1012 xmlValue.add(href); 1013 } 1014 } 1015 1016 return xmlValue; 1017 } 1018 1019 1028 protected Element getCheckoutSetQueryElement(String resourcePath) throws SlideException { 1029 1030 if (checkoutSetQueryElement == null) { 1031 1032 checkoutSetQueryElement = new Element(DaslConstants.E_BASICSEARCH, DNSP); 1033 1034 Element select = new Element(DaslConstants.E_SELECT, DNSP); 1035 checkoutSetQueryElement.addContent(select); 1036 Element prop = new Element(E_PROP, DNSP); 1037 select.addContent(prop); 1038 Element checkedOut = new Element(P_CHECKED_OUT, DNSP); 1039 prop.addContent(checkedOut); 1040 1041 Element from = new Element(DaslConstants.E_FROM, DNSP); 1042 checkoutSetQueryElement.addContent(from); 1043 Element scope = new Element(DaslConstants.E_SCOPE, DNSP); 1044 from.addContent(scope); 1045 Element href = new Element(E_HREF, DNSP); 1046 scope.addContent(href); 1047 href.setText(""); 1048 Iterator excludeIterator = getNonVcrPathExcludeList().iterator(); 1049 while (excludeIterator.hasNext()) { 1050 scope.addContent((Element)excludeIterator.next()); 1051 } 1052 1053 Element where = new Element(DaslConstants.E_WHERE, DNSP); 1054 checkoutSetQueryElement.addContent(where); 1055 Element propcontains = new Element(DaslConstants.E_PROPCONTAINS, NamespaceCache.SLIDE_NAMESPACE); 1056 where.addContent(propcontains); 1057 propcontains.addContent((Element)prop.clone()); 1058 checkoutSetQueryLiteralElement = new Element(DaslConstants.E_LITERAL, DNSP); 1059 propcontains.addContent(checkoutSetQueryLiteralElement); 1060 } 1061 checkoutSetQueryLiteralElement.setText(resourcePath); 1062 1063 return checkoutSetQueryElement; 1064 } 1065 1066 1076 public List getNonVcrPathExcludeList() { 1077 1078 List excludeList = new ArrayList (); 1079 1080 String usersPath = truncateLeadingSlash(nsaToken.getNamespaceConfig().getUsersPath()); 1081 addExcludeElement(usersPath, excludeList); 1082 1083 String groupsPath = truncateLeadingSlash(nsaToken.getNamespaceConfig().getGroupsPath()); 1084 addExcludeElement(groupsPath, excludeList); 1085 1086 String rolesPath = truncateLeadingSlash(nsaToken.getNamespaceConfig().getRolesPath()); 1087 addExcludeElement(rolesPath, excludeList); 1088 1089 Iterator historyPathIterator = HistoryPathHandler.getHistoryPathHandler().getResolvedHistoryPaths().iterator(); 1090 while (historyPathIterator.hasNext()) { 1091 String path = truncateLeadingSlash(historyPathIterator.next().toString()); 1092 addExcludeElement(path, excludeList); 1093 } 1094 1095 return excludeList; 1096 } 1097 1098 private void addExcludeElement(String path, List excludeList) { 1099 if (path != null && path.length() > 0) { 1100 Element excludeElement = new Element(DaslConstants.E_EXCLUDE, NamespaceCache.SLIDE_NAMESPACE); 1101 excludeElement.setText(path); 1102 excludeList.add(excludeElement); 1103 } 1104 } 1105 1106 1122 public XMLValue computeWorkspaceNoBinding(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws SlideException, JDOMException { 1123 XMLValue result = null; 1124 UriHandler hrUh = UriHandler.getUriHandler(revisionDescriptors, revisionDescriptor); 1125 String associatedWsUri = hrUh.getAssociatedWorkspaceUri(); 1126 if (associatedWsUri != null) { 1127 result = new XMLValue(); 1128 Element hrElm = new Element(E_HREF, DNSP); 1129 hrElm.setText(associatedWsUri); 1130 result.add(hrElm); 1131 } 1132 return result; 1133 } 1134 1135 1151 public XMLValue computeWorkspace(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws SlideException, JDOMException { 1152 XMLValue result = null; 1153 1154 UriHandler rUh = new UriHandler(revisionDescriptors.getUri()); 1155 if (rUh.getAssociatedWorkspaceUri() != null) { 1156 result = new XMLValue(); 1157 Element hrElm = new Element(E_HREF, DNSP); 1158 hrElm.setText(rUh.getAssociatedWorkspaceUri()); 1159 result.add(hrElm); 1160 return result; 1161 } 1162 1163 NodeProperty psProp = revisionDescriptor.getProperty(P_PARENT_SET); 1164 if (psProp == null) { 1165 return new XMLValue(); 1166 } 1167 1168 List psUris = new ArrayList (); 1169 XMLValue xv = new XMLValue(String.valueOf(psProp.getValue())); 1170 Iterator i = xv.getList().iterator(); 1171 while (i.hasNext()) { 1172 Element pElm = (Element)i.next(); 1173 UriHandler hrUh = new UriHandler(pElm.getChild(E_HREF, DNSP).getText()); 1174 if (hrUh.getAssociatedWorkspaceUri() != null) { 1175 result = new XMLValue(); 1176 Element hrElm = new Element(E_HREF, DNSP); 1177 hrElm.setText(hrUh.getAssociatedWorkspaceUri()); 1178 result.add(hrElm); 1179 break; 1180 } 1181 else if (!hrUh.isRootUri()) { 1182 psUris.add(hrUh); 1183 } 1184 } 1185 1186 if (result == null) { 1187 i = psUris.iterator(); 1188 while (i.hasNext()) { 1189 NodeRevisionDescriptors nrds = 1190 nsaToken.getContentHelper().retrieve(sToken, ((UriHandler)i.next()).getUri()); 1191 NodeRevisionDescriptor nrd = 1192 nsaToken.getContentHelper().retrieve(sToken, nrds); 1193 result = computeWorkspace(nrds, nrd, slideContextPath); 1194 if (result != null) { 1195 break; 1196 } 1197 } 1198 } 1199 1200 return result; 1201 } 1202 1203 1219 public XMLValue computeWorkspaceCheckoutSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws SlideException, JDOMException { 1220 1221 XMLValue xmlValue = new XMLValue(); 1222 1223 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor); 1224 if (resourceKind instanceof Workspace) { 1225 1226 Element basicSearch = getWorkspaceCheckoutSetQueryElement(revisionDescriptors.getUri()); 1227 String grammarNamespace = basicSearch.getNamespaceURI(); 1228 Search searchHelper = nsaToken.getSearchHelper(); 1229 SearchQuery searchQuery = searchHelper.createSearchQuery(grammarNamespace, 1230 basicSearch, 1231 sToken, 1232 Integer.MAX_VALUE, 1233 slideContextPath); 1234 SearchQueryResult queryResult = searchHelper.search(sToken, searchQuery); 1235 Iterator queryResultIterator = queryResult.iterator(); 1236 RequestedResource requestedResource = null; 1237 Element hrefElement = null; 1238 while (queryResultIterator.hasNext()) { 1239 requestedResource = (RequestedResource)queryResultIterator.next(); 1240 hrefElement = new Element(E_HREF, DNSP); 1241 1242 1243 hrefElement.setText (WebdavUtils.getAbsolutePath ( 1244 requestedResource.getUri(), 1245 slideContextPath, sConf)); 1246 1247 xmlValue.add(hrefElement); 1248 } 1249 } 1250 1251 return xmlValue; 1252 } 1253 1254 1262 protected Element getWorkspaceCheckoutSetQueryElement(String scopePath) { 1263 1264 if (workspaceCheckoutSetQueryElement == null) { 1265 1266 workspaceCheckoutSetQueryElement = new Element(DaslConstants.E_BASICSEARCH, DNSP); 1267 1268 Element select = new Element(DaslConstants.E_SELECT, DNSP); 1269 workspaceCheckoutSetQueryElement.addContent(select); 1270 Element prop = new Element(E_PROP, DNSP); 1271 select.addContent(prop); 1272 Element checkedOut = new Element(P_CHECKED_OUT, DNSP); 1273 prop.addContent(checkedOut); 1274 1275 Element from = new Element(DaslConstants.E_FROM, DNSP); 1276 workspaceCheckoutSetQueryElement.addContent(from); 1277 Element scope = new Element(DaslConstants.E_SCOPE, DNSP); 1278 from.addContent(scope); 1279 workspaceCheckoutSetQueryHrefElement = new Element(E_HREF, DNSP); 1280 scope.addContent(workspaceCheckoutSetQueryHrefElement); 1281 1282 Element where = new Element(DaslConstants.E_WHERE, DNSP); 1283 workspaceCheckoutSetQueryElement.addContent(where); 1284 Element isdefined = new Element(DaslConstants.E_ISDEFINED, DNSP); 1285 where.addContent(isdefined); 1286 isdefined.addContent((Element)prop.clone()); 1287 } 1288 workspaceCheckoutSetQueryHrefElement.setText(truncateLeadingSlash(scopePath)); 1289 1290 return workspaceCheckoutSetQueryElement; 1291 } 1292 1293 1308 private XMLValue computeLockDiscovery(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ServiceAccessException, LinkedObjectNotFoundException, ObjectNotFoundException, LockTokenNotFoundException { 1309 1310 XMLValue xmlValue = new XMLValue(); 1311 Lock lock = nsaToken.getLockHelper(); 1312 NodeLock objectLockToken = null; 1313 Enumeration lockTokens = lock.enumerateLocks(sToken, revisionDescriptors.getUri(), true); 1314 Set addedLockIDs = new HashSet (); 1315 while (lockTokens.hasMoreElements()) { 1316 objectLockToken = (NodeLock) lockTokens.nextElement(); 1317 if (revisionDescriptors.getUri().equals(objectLockToken.getObjectUri()) || 1318 objectLockToken.isInheritable() 1319 ) { 1320 1321 if (!addedLockIDs.contains(objectLockToken.getLockId())) { 1322 Element activelock = createActiveLockElement(objectLockToken, 1323 slideContextPath); 1324 if (activelock != null) { 1325 xmlValue.add(activelock); 1326 addedLockIDs.add(objectLockToken.getLockId()); 1327 } 1328 } 1329 } 1330 } 1331 1332 return xmlValue; 1333 } 1334 1335 1346 public XMLValue computeLockDiscovery(NodeLock objectLockToken, String slideContextPath) { 1347 1348 XMLValue xmlValue = new XMLValue(); 1349 Element activelock = createActiveLockElement(objectLockToken, slideContextPath); 1350 1351 if (activelock != null) { 1352 xmlValue.add(activelock); 1353 } 1354 return xmlValue; 1355 } 1356 1357 1369 private Element createActiveLockElement(NodeLock objectLockToken, String slideContextPath) { 1370 1371 Element activelock = null; 1372 1374 if (objectLockToken != null) { 1375 1376 activelock = new Element(E_ACTIVELOCK, DNSP); 1377 Element locktype = new Element(E_LOCKTYPE, DNSP); 1378 activelock.addContent(locktype); 1379 if (objectLockToken.isLocal()) { 1380 Element transaction = new Element(E_TRANSACTION, DNSP); 1381 Element groupoperation = new Element(E_GROUPOPERATION, DNSP); 1382 transaction.addContent(groupoperation); 1383 locktype.addContent(transaction); 1384 } else { 1385 Element write = new Element(E_WRITE, DNSP); 1386 locktype.addContent(write); 1387 } 1388 Element lockscope = new Element(E_LOCKSCOPE, DNSP); 1389 activelock.addContent(lockscope); 1390 Element lockscopeValue = null; 1391 if (objectLockToken.isExclusive()) { 1392 lockscopeValue = new Element(E_EXCLUSIVE, DNSP); 1393 } else if (objectLockToken.isShared()) { 1394 lockscopeValue = new Element(E_SHARED, DNSP); 1395 } else if (objectLockToken.isLocal()) { 1396 lockscopeValue = new Element(E_LOCAL, DNSP); 1397 } 1398 lockscope.addContent(lockscopeValue); 1399 Element depth = new Element(E_DEPTH, DNSP); 1400 activelock.addContent(depth); 1401 if (objectLockToken.isInheritable()) { 1402 depth.setText("infinity"); 1403 } else { 1404 depth.setText("0"); 1405 } 1406 Element owner = new Element(E_OWNER, DNSP); 1407 activelock.addContent(owner); 1408 1413 if( objectLockToken.getOwnerInfo() != null && 1414 !objectLockToken.getOwnerInfo().equals(LockMethod.DEFAULT_LOCK_OWNER) ) { 1415 1416 try { 1418 Document d = 1419 new SAXBuilder().build( new StringReader (objectLockToken.getOwnerInfo()) ); 1420 owner.addContent(d.detachRootElement()); 1421 } 1422 catch( Throwable e ) { 1423 owner.addContent(new CDATA(objectLockToken.getOwnerInfo())); 1424 } 1425 } 1426 1427 Element timeout = new Element(E_TIMEOUT, DNSP); 1428 activelock.addContent(timeout); 1429 long seconds = (new Long ((objectLockToken.getExpirationDate().getTime() 1430 - (new Date ()).getTime())/1000)).longValue(); 1431 if (seconds > 0.75 * Integer.MAX_VALUE) { 1432 timeout.setText("Infinite"); 1433 } 1434 else { 1435 timeout.setText("Second-"+seconds); 1436 } 1437 Element locktoken = new Element(E_LOCKTOKEN, DNSP); 1438 activelock.addContent(locktoken); 1439 Element href = new Element(E_HREF, DNSP); 1440 locktoken.addContent(href); 1441 href.setText(S_LOCK_TOKEN+objectLockToken.getLockId()); 1442 1443 if( lockdiscoveryIncludesPrincipalURL ) { 1446 Element principalUrl = new Element( E_PRINCIPAL_URL, DNSP); 1447 activelock.addContent(principalUrl); 1448 SubjectNode snode = 1449 SubjectNode.getSubjectNode(objectLockToken.getSubjectUri()); 1450 String subjectUri = objectLockToken.getSubjectUri(); 1451 if (snode.equals(SubjectNode.UNAUTHENTICATED)) { 1452 String userspath = nsaToken.getNamespaceConfig().getUsersPath(); 1453 subjectUri = userspath+"/"+snode.toString(); 1454 } 1455 Element puhref = new Element(E_HREF, DNSP); 1456 principalUrl.addContent(puhref); 1457 1458 puhref.setText( 1459 WebdavUtils.getAbsolutePath(subjectUri, slideContextPath, sConf)); 1460 } 1461 } 1463 return activelock; 1464 } 1465 1466 1485 public XMLValue computeSupportedlock(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1486 1487 XMLValue xmlValue = new XMLValue(); 1488 1489 Element lockentry = new Element(E_LOCKENTRY, DNSP); 1490 Element lockscope = new Element(E_LOCKSCOPE, DNSP); 1491 lockentry.addContent(lockscope); 1492 Element exclusive = new Element(E_EXCLUSIVE, DNSP); 1493 lockscope.addContent(exclusive); 1494 Element locktype = new Element(E_LOCKTYPE, DNSP); 1495 lockentry.addContent(locktype); 1496 Element write = new Element(E_WRITE, DNSP); 1497 locktype.addContent(write); 1498 xmlValue.add(lockentry); 1499 1500 lockentry = new Element(E_LOCKENTRY, DNSP); 1501 lockscope = new Element(E_LOCKSCOPE, DNSP); 1502 lockentry.addContent(lockscope); 1503 Element shared = new Element(E_SHARED, DNSP); 1504 lockscope.addContent(shared); 1505 locktype = new Element(E_LOCKTYPE, DNSP); 1506 lockentry.addContent(locktype); 1507 write = new Element(E_WRITE, DNSP); 1508 locktype.addContent(write); 1509 xmlValue.add(lockentry); 1510 1511 return xmlValue; 1512 } 1513 1514 1515 1534 public XMLValue computeSupportedPrivilegeSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1535 Map actionAggregation = ((SecurityImpl)nsaToken.getSecurityHelper()).getActionAggregation(sToken); 1536 Set rootSet = new HashSet (actionAggregation.keySet()); 1537 Iterator actions = actionAggregation.keySet().iterator(); 1538 while (actions.hasNext()) { 1539 ActionNode a = (ActionNode)actions.next(); 1540 Iterator aggregates = ((Set )actionAggregation.get(a)).iterator(); 1541 while (aggregates.hasNext()) { 1542 ActionNode c = (ActionNode)aggregates.next(); 1543 rootSet.remove(c); 1544 } 1545 } 1546 Element rootSp = new Element(E_SUPPORTED_PRIVILEGE, DNSP); 1547 Element p = new Element(E_PRIVILEGE, DNSP); 1548 p.addContent(new Element(E_ALL, DNSP)); 1549 rootSp.addContent(p); 1550 Iterator roots = rootSet.iterator(); 1551 addElementsForAggregatedActions(rootSp, roots, actionAggregation); 1552 return new XMLValue(rootSp); 1553 } 1554 1555 1567 private void addElementsForAggregatedActions(Element parentActionElement, Iterator aggregatedActions, Map actionAggregation) { 1568 while (aggregatedActions.hasNext()) { 1569 ActionNode a = (ActionNode)aggregatedActions.next(); 1570 Element sp = new Element(E_SUPPORTED_PRIVILEGE, DNSP); 1571 Element p = new Element(E_PRIVILEGE, DNSP); 1572 Namespace actionNamespace = a.getNamespace(); 1573 if (actionNamespace == null) { 1574 actionNamespace = DNSP; 1575 } 1576 p.addContent(new Element(a.getPath().lastSegment(), actionNamespace)); 1577 addElementsForAggregatedActions(p, ((Set )actionAggregation.get(a)).iterator(), actionAggregation); 1578 sp.addContent(p); 1579 parentActionElement.addContent(sp); 1580 } 1581 } 1582 1583 1584 1594 private Element createPrivilege(ActionNode privilege, Uri privilegeUri) throws RevisionDescriptorNotFoundException, ServiceAccessException { 1595 return createPrivilege(privilege, true, privilegeUri); 1596 } 1597 1598 1611 private Element createPrivilege(ActionNode privilege, boolean useDavNamespace, Uri privilegeUri) throws RevisionDescriptorNotFoundException, ServiceAccessException { 1612 NodeRevisionNumber latestRevisionNumber = privilegeUri.getStore().retrieveRevisionDescriptors(privilegeUri).getLatestRevision(); 1613 NodeProperty privilegeNamespaceProperty = privilegeUri.getStore().retrieveRevisionDescriptor(privilegeUri, latestRevisionNumber).getProperty(PRIVILEGE_NAMESPACE, WebdavConstants.S_DAV); 1614 Namespace privilegeNamespace = null; 1615 if (privilegeNamespaceProperty != null && privilegeNamespaceProperty.getValue() instanceof String ) { 1616 privilegeNamespace = Namespace.getNamespace((String ) privilegeNamespaceProperty.getValue()); 1617 } else { 1618 privilegeNamespace = DNSP; 1619 if ( ! useDavNamespace ) { 1620 privilegeNamespace = NamespaceCache.SLIDE_NAMESPACE; 1621 } 1622 } 1623 Element privilegeElement = new Element(E_PRIVILEGE, DNSP); 1624 Element privilegeNameElement = new Element(privilege.getPath().lastSegment(), privilegeNamespace); 1625 privilegeElement.addContent(privilegeNameElement); 1626 return privilegeElement; 1627 } 1628 1629 1648 public XMLValue computeCurrentuserPrivilegeSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1649 XMLValue xmlValue = new XMLValue(); 1650 1651 try { 1652 NamespaceConfig config = nsaToken.getNamespaceConfig(); 1653 Structure structure = nsaToken.getStructureHelper(); 1654 ObjectNode object = structure.retrieve(sToken, revisionDescriptors.getUri()); 1655 1656 Security security = nsaToken.getSecurityHelper(); 1658 security.checkCredentials(sToken, object, config.getReadOwnPermissionsAction()); 1659 1660 String actionsPath = config.getActionsPath(); 1661 Uri actionsPathUri = nsaToken.getUri(sToken, actionsPath); 1662 ObjectNode actionsPathNode = actionsPathUri.getStore().retrieveObject(actionsPathUri); 1663 Enumeration actions = actionsPathNode.enumerateChildren(); 1664 addGrantedActionsToPrivilegeSet(xmlValue, object, actions); 1665 } 1666 catch (ServiceAccessException e) { 1667 throw e; 1668 } 1669 catch (SlideException e) { 1670 return xmlValue; 1671 } 1672 return xmlValue; 1673 } 1674 1675 1688 private void addGrantedActionsToPrivilegeSet(XMLValue xmlValue, ObjectNode object, Enumeration actions) throws ServiceAccessException, ObjectNotFoundException, RevisionDescriptorNotFoundException { 1689 while (actions.hasMoreElements()) { 1690 Uri aNodeUri = nsaToken.getUri(sToken, (String )actions.nextElement()); 1691 ObjectNode oNode = aNodeUri.getStore().retrieveObject(aNodeUri); 1692 if (oNode.hasChildren()) { 1693 addGrantedActionsToPrivilegeSet(xmlValue, object, oNode.enumerateChildren()); 1694 } else { 1695 ActionNode aNode = ActionNode.getActionNode(oNode.getUri()); 1696 if (nsaToken.getSecurityHelper().hasPermission(sToken, object, aNode)) { 1697 xmlValue.add(createPrivilege(aNode, aNodeUri)); 1698 } 1699 } 1700 } 1701 } 1702 1703 1704 1723 public XMLValue computeAcl(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException, VetoException { 1725 XMLValue xmlValue = new XMLValue(); 1727 1728 NamespaceConfig config = nsaToken.getNamespaceConfig(); 1729 Structure structure = nsaToken.getStructureHelper(); 1730 ObjectNode objectNode = structure.retrieve(sToken, revisionDescriptors.getUri()); 1731 1732 Security security = nsaToken.getSecurityHelper(); 1734 security.checkCredentials(sToken, objectNode, config.getReadPermissionsAction()); 1735 1736 String currentSubjectUri = ""; 1737 boolean currentNegative = false; 1738 String currentInheritedFrom = ""; 1739 Element currentAceElm = null; 1740 Element currentGrantDenyElm = null; 1741 Enumeration permissions = security.enumeratePermissions(sToken, objectNode, true); 1742 while (permissions.hasMoreElements()) { 1743 NodePermission perm = (NodePermission)permissions.nextElement(); 1744 if (!perm.getSubjectUri().equals(currentSubjectUri) 1745 || (perm.isNegative() && !currentNegative || !perm.isNegative() && currentNegative) 1746 || (!currentInheritedFrom.equals(perm.getInheritedFrom()))) { 1747 1748 if (currentAceElm != null) { 1750 xmlValue.add(currentAceElm); 1751 } 1752 1753 currentAceElm = new Element(E_ACE, DNSP); 1755 1756 if (perm.isInvert()) { 1758 Element invertElm = new Element(E_INVERT, DNSP); 1759 invertElm.addContent(createPrincipalElement(perm.getSubjectUri())); 1760 currentAceElm.addContent(invertElm); 1761 } 1762 else { 1763 currentAceElm.addContent(createPrincipalElement(perm.getSubjectUri())); 1764 } 1765 1766 currentGrantDenyElm = perm.isNegative() 1768 ? new Element(E_DENY, DNSP) 1769 : new Element(E_GRANT, DNSP); 1770 currentAceElm.addContent(currentGrantDenyElm); 1771 1772 String inheritedFrom = perm.getInheritedFrom(); 1774 if (inheritedFrom != null && inheritedFrom.length() > 0) { 1775 currentAceElm.addContent(createInheritedElement(inheritedFrom)); 1776 } 1777 1778 if (perm.isProtected()) { 1780 currentAceElm.addContent(new Element(E_PROTECTED, DNSP)); 1781 } 1782 1783 currentSubjectUri = perm.getSubjectUri(); 1784 currentNegative = perm.isNegative(); 1785 currentInheritedFrom = inheritedFrom != null ? inheritedFrom : ""; 1786 } 1787 currentGrantDenyElm.addContent(createPrivilegeElement(perm.getActionUri())); 1788 } 1789 1790 if (currentAceElm != null) { 1792 xmlValue.add(currentAceElm); 1793 } 1794 1795 return xmlValue; 1796 } 1797 1798 private Element createInheritedElement(String inheritedFrom) { 1799 Element inheritedElm = new Element(E_INHERITED, DNSP); 1800 Element hrefElm = new Element(E_HREF, DNSP); 1801 hrefElm.addContent(new Text(inheritedFrom)); 1802 inheritedElm.addContent(hrefElm); 1803 return inheritedElm; 1804 } 1805 1806 private Element createPrincipalElement(String subjectUri) { 1807 Element principalElm = new Element(E_PRINCIPAL, DNSP); 1808 if (subjectUri.equals(SubjectNode.ALL_URI)) { 1809 Element allElm = new Element(E_ALL, DNSP); 1810 principalElm.addContent(allElm); 1811 } 1812 else if (subjectUri.equals(SubjectNode.AUTHENTICATED_URI)) { 1813 Element authenticatedElm = new Element(E_AUTHENTICATED, DNSP); 1814 principalElm.addContent(authenticatedElm); 1815 } 1816 else if (subjectUri.equals(SubjectNode.UNAUTHENTICATED_URI)) { 1817 Element unauthenticatedElm = new Element(E_UNAUTHENTICATED, DNSP); 1818 principalElm.addContent(unauthenticatedElm); 1819 } 1820 else if (subjectUri.equals(SubjectNode.OWNER_URI)) { 1821 Element propertyElm = new Element(E_PROPERTY, DNSP); 1822 propertyElm.addContent(new Element(P_OWNER, DNSP)); 1823 principalElm.addContent(propertyElm); 1824 } 1825 else if (subjectUri.equals(SubjectNode.SELF_URI)) { 1826 Element selfElm = new Element(E_SELF, DNSP); 1827 principalElm.addContent(selfElm); 1828 } 1829 else { 1830 Element hrefElm = new Element(E_HREF, DNSP); 1831 hrefElm.addContent(new Text(subjectUri)); 1832 principalElm.addContent(hrefElm); 1833 } 1834 return principalElm; 1835 } 1836 1837 private Element createPrivilegeElement(String actionUriAsString) throws RevisionDescriptorNotFoundException, ServiceAccessException { 1838 Element privilegeElm = new Element(E_PRIVILEGE, DNSP); 1839 if (actionUriAsString.equals(ActionNode.ALL_URI)) { 1840 Element allElm = new Element(E_ALL, DNSP); 1841 privilegeElm.addContent(allElm); 1842 } 1843 else { 1844 Uri actionUri = nsaToken.getUri(sToken, actionUriAsString); 1845 NodeRevisionNumber latestRevisionNumber = actionUri.getStore().retrieveRevisionDescriptors(actionUri).getLatestRevision(); 1846 NodeProperty privilegeNamespace = actionUri.getStore().retrieveRevisionDescriptor(actionUri, latestRevisionNumber).getProperty(PRIVILEGE_NAMESPACE, WebdavConstants.S_DAV); 1847 Namespace actionNamespace = null; 1848 if (privilegeNamespace != null && privilegeNamespace.getValue() instanceof String ) { 1849 actionNamespace = Namespace.getNamespace((String ) privilegeNamespace.getValue()); 1850 } 1851 else { 1852 actionNamespace = DNSP; 1853 } 1854 1855 Element actionElm = new Element(new UriPath(actionUriAsString).lastSegment(), actionNamespace); 1856 privilegeElm.addContent(actionElm); 1857 } 1858 return privilegeElm; 1859 } 1860 1861 1880 public XMLValue computePrincipalCollectionSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1881 XMLValue xmlValue = new XMLValue(); 1882 NamespaceConfig namespaceConfig = nsaToken.getNamespaceConfig(); 1883 1884 xmlValue.addHref(WebdavUtils.getAbsolutePath (namespaceConfig.getUsersPath(), 1885 slideContextPath, sConf)); 1886 1887 if (namespaceConfig.getGroupsPath() != null) { 1888 1889 xmlValue.addHref(WebdavUtils.getAbsolutePath (namespaceConfig.getGroupsPath(), 1890 slideContextPath, sConf)); 1891 } 1892 if (namespaceConfig.getRolesPath() != null) { 1893 xmlValue.addHref(WebdavUtils.getAbsolutePath (namespaceConfig.getRolesPath(), 1894 slideContextPath, sConf)); 1895 } 1896 return xmlValue; 1897 } 1898 1899 1900 public XMLValue computePrivilegeCollectionSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1901 XMLValue xmlValue = new XMLValue(); 1902 NamespaceConfig namespaceConfig = nsaToken.getNamespaceConfig(); 1903 1904 String absUri = WebdavUtils.getAbsolutePath (namespaceConfig.getActionsPath(), 1905 slideContextPath, sConf); 1906 1907 xmlValue.addHref(absUri); 1908 return xmlValue; 1909 } 1910 1911 1912 1933 public XMLValue computeOwner(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1934 1935 NodeProperty ownerProperty = revisionDescriptor.getProperty(P_OWNER, 1936 NodeProperty.DEFAULT_NAMESPACE); 1937 1938 XMLValue xmlValue = createUserPath(ownerProperty, slideContextPath); 1939 1940 return xmlValue; 1941 } 1942 1943 public XMLValue computeCreationUser(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1944 1945 NodeProperty creationUserProperty = revisionDescriptor.getProperty(P_CREATIONUSER, 1946 NodeProperty.DEFAULT_NAMESPACE); 1947 XMLValue xmlValue = createUserPath(creationUserProperty, slideContextPath); 1948 1949 return xmlValue; 1950 } 1951 1952 public XMLValue computeModificationUser(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1953 1954 NodeProperty modificationUserProperty = revisionDescriptor.getProperty(P_MODIFICATIONUSER, 1955 NodeProperty.DEFAULT_NAMESPACE); 1956 1957 XMLValue xmlValue = createUserPath(modificationUserProperty, slideContextPath); 1958 1959 return xmlValue; 1960 } 1961 1962 public XMLValue computeInheritedAclSet(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1963 if (revisionDescriptor.getProperty(P_INHERITED_ACL_SET) != null) { 1965 Object v = revisionDescriptor.getProperty(P_INHERITED_ACL_SET).getValue(); 1966 return (v instanceof XMLValue) 1967 ? (XMLValue)v 1968 : new XMLValue((String )v); 1969 } 1970 else { 1971 return new XMLValue(); 1972 } 1973 } 1974 1975 public XMLValue computeAclRestrictions(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1976 if (revisionDescriptor.getProperty(P_ACL_RESTRICTIONS) != null) { 1978 Object v = revisionDescriptor.getProperty(P_ACL_RESTRICTIONS).getValue(); 1979 return (v instanceof XMLValue) 1980 ? (XMLValue)v 1981 : new XMLValue((String )v); 1982 } 1983 else { 1984 return new XMLValue(); 1985 } 1986 } 1987 1988 public XMLValue computeGroupMembership(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String slideContextPath) throws ObjectLockedException, RevisionDescriptorNotFoundException, ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, LockTokenNotFoundException, JDOMException { 1989 if (revisionDescriptor.getProperty(P_GROUP_MEMBERSHIP) != null) { 1990 Object v = revisionDescriptor.getProperty(P_GROUP_MEMBERSHIP).getValue(); 1991 return (v instanceof XMLValue) 1992 ? (XMLValue)v 1993 : new XMLValue((String )v); 1994 } 1995 else { 1996 XMLValue xmlValue = new XMLValue(); 1997 Uri principalUri = nsaToken.getUri(sToken, revisionDescriptors.getUri()); 1998 SubjectNode principalNode = (SubjectNode)principalUri.getStore().retrieveObject(principalUri); 1999 Enumeration roles = ((ACLSecurityImpl)nsaToken.getSecurityHelper()).getGroupMembership(sToken, principalNode); 2000 while (roles.hasMoreElements()) { 2001 String rolePath = (String )roles.nextElement(); 2002 String roleHref = slideContextPath+rolePath; 2003 xmlValue.addHref(roleHref); 2004 } 2005 return xmlValue; 2006 } 2007 } 2008 2009 private XMLValue createUserPath(NodeProperty userProperty, String slideContextPath) 2010 throws IllegalArgumentException 2011 { 2012 XMLValue xmlValue = new XMLValue(); 2013 String userHref = ""; 2014 NamespaceConfig config = nsaToken.getNamespaceConfig(); 2015 if ((userProperty != null) && (userProperty.getValue()!=null) && 2016 (!"".equals(userProperty.getValue().toString()))) { 2017 2018 userHref = slideContextPath + config.getUsersPath() 2019 + "/" + userProperty.getValue().toString(); 2020 xmlValue.addHref(userHref); 2021 } 2022 else { 2023 xmlValue.add(new Element(E_UNAUTHENTICATED, DNSP)); 2024 } 2025 return xmlValue; 2026 } 2027 2028 2029 2044 public static String getAbsoluteURL(String serverURL, String contextPath, String uri) { 2045 StringBuffer buffer = new StringBuffer (); 2047 String lastAppended = null; 2048 if (contextPath != null) { 2053 if ( (lastAppended != null) && !lastAppended.endsWith("/") && !contextPath.startsWith("/") ) { 2054 buffer.append("/"); 2055 } 2056 buffer.append(contextPath); 2057 lastAppended = buffer.toString(); 2058 } 2059 if (uri != null) { 2060 if ( (lastAppended != null) && !lastAppended.endsWith("/") && !uri.startsWith("/") ) { 2061 buffer.append("/"); 2062 } 2063 buffer.append(uri); 2064 } 2065 2066 return WebdavUtils.encodeURL(buffer.toString()); 2067 } 2068 2069 2077 public static boolean isAbsoluteURL(String servletContextPath, String uri) { 2078 if (uri.startsWith(S_RESOURCE_ID)) { 2079 return true; 2080 } 2081 if (uri.startsWith(S_LOCK_TOKEN)) { 2082 return true; 2083 } 2084 if (!uri.startsWith("/")) { 2085 uri = "/" + uri; 2086 } 2087 return uri.startsWith(servletContextPath); 2088 } 2089 2090 2103 public static boolean addHrefToProperty(NodeRevisionDescriptor revisionDescriptor, String propertyName, String uri) throws JDOMException { 2104 return addElementToProperty(revisionDescriptor, propertyName, E_HREF, uri); 2105 } 2106 2107 2121 public static boolean addElementToProperty(NodeRevisionDescriptor revisionDescriptor, String propertyName, String elementName, String elementValue) throws JDOMException { 2122 2123 NodeProperty property = revisionDescriptor.getProperty(propertyName); 2124 if (property == null) { 2125 property = new NodeProperty(propertyName, null); 2126 } 2127 XMLValue xmlValue = new XMLValue((String )property.getValue()); 2128 Iterator iterator = xmlValue.iterator(); 2129 boolean alreadyContained = false; 2130 Element element = null; 2131 while (iterator.hasNext() && !alreadyContained) { 2132 element = (Element)iterator.next(); 2133 if (element.getName().equals(elementName) && element.getText().equals(elementValue)) { 2134 alreadyContained = true; 2135 } 2136 } 2137 if (!alreadyContained) { 2138 element = new Element(elementName); 2139 element.setText(elementValue); 2140 xmlValue.add(element); 2141 } 2142 revisionDescriptor.setProperty(propertyName, xmlValue.toString()); 2143 return !alreadyContained; 2144 } 2145 2146 2160 public static boolean removeHrefFromProperty(NodeRevisionDescriptor revisionDescriptor, String propertyName, String uri) throws JDOMException { 2161 return removeElementFromProperty(revisionDescriptor, propertyName, E_HREF, uri); 2162 } 2163 2164 2179 public static boolean removeElementFromProperty(NodeRevisionDescriptor revisionDescriptor, String propertyName, String elementName, String elementValue) throws JDOMException { 2180 2181 NodeProperty property = revisionDescriptor.getProperty(propertyName); 2182 boolean found = false; 2183 if (property != null) { 2184 2185 XMLValue xmlValue = new XMLValue((String )property.getValue()); 2186 Iterator iterator = xmlValue.iterator(); 2187 Element element = null; 2188 while (iterator.hasNext() && !found) { 2189 element = (Element)iterator.next(); 2190 if (element.getName().equals(elementName) && element.getText().equals(elementValue)) { 2191 found = true; 2192 iterator.remove(); 2193 } 2194 } 2195 if (found) { 2196 revisionDescriptor.setProperty(propertyName, xmlValue.toString()); 2197 } 2198 } 2199 return found; 2200 } 2201 2202 2209 public static String truncateLeadingSlash(String uri) { 2210 2211 if (uri == null) { 2212 return uri; 2213 } 2214 2215 while (uri.startsWith("/")) { 2216 uri = uri.substring(1); 2217 } 2218 return uri; 2219 } 2220 2221 2228 public static String computeEtag(String uri, NodeRevisionDescriptor nrd) { 2229 StringBuffer sb = new StringBuffer (); 2230 sb.append(System.currentTimeMillis()).append('_') 2231 .append(uri.hashCode()).append('_') 2232 .append(nrd.getLastModified()).append('_') 2233 .append(nrd.getContentLength()); 2234 return new String (DigestUtils.md5Hex(sb.toString())); 2235 } 2236 2237 2238} 2239 2240 2241 2242 | Popular Tags |