You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchivaDavResource.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. package org.apache.archiva.webdav;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.admin.model.beans.ManagedRepository;
  21. import org.apache.archiva.metadata.model.facets.AuditEvent;
  22. import org.apache.archiva.repository.events.AuditListener;
  23. import org.apache.archiva.common.filelock.FileLockException;
  24. import org.apache.archiva.common.filelock.FileLockManager;
  25. import org.apache.archiva.common.filelock.FileLockTimeoutException;
  26. import org.apache.archiva.common.filelock.Lock;
  27. import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
  28. import org.apache.archiva.scheduler.ArchivaTaskScheduler;
  29. import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler;
  30. import org.apache.archiva.scheduler.repository.model.RepositoryTask;
  31. import org.apache.archiva.webdav.util.IndexWriter;
  32. import org.apache.archiva.webdav.util.MimeTypes;
  33. import org.apache.commons.io.FileUtils;
  34. import org.apache.commons.io.IOUtils;
  35. import org.apache.jackrabbit.util.Text;
  36. import org.apache.jackrabbit.webdav.DavConstants;
  37. import org.apache.jackrabbit.webdav.DavException;
  38. import org.apache.jackrabbit.webdav.DavResource;
  39. import org.apache.jackrabbit.webdav.DavResourceFactory;
  40. import org.apache.jackrabbit.webdav.DavResourceIterator;
  41. import org.apache.jackrabbit.webdav.DavResourceIteratorImpl;
  42. import org.apache.jackrabbit.webdav.DavResourceLocator;
  43. import org.apache.jackrabbit.webdav.DavServletResponse;
  44. import org.apache.jackrabbit.webdav.DavSession;
  45. import org.apache.jackrabbit.webdav.MultiStatusResponse;
  46. import org.apache.jackrabbit.webdav.io.InputContext;
  47. import org.apache.jackrabbit.webdav.io.OutputContext;
  48. import org.apache.jackrabbit.webdav.lock.ActiveLock;
  49. import org.apache.jackrabbit.webdav.lock.LockInfo;
  50. import org.apache.jackrabbit.webdav.lock.LockManager;
  51. import org.apache.jackrabbit.webdav.lock.Scope;
  52. import org.apache.jackrabbit.webdav.lock.Type;
  53. import org.apache.jackrabbit.webdav.property.DavProperty;
  54. import org.apache.jackrabbit.webdav.property.DavPropertyName;
  55. import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
  56. import org.apache.jackrabbit.webdav.property.DavPropertySet;
  57. import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
  58. import org.apache.jackrabbit.webdav.property.ResourceType;
  59. import org.joda.time.DateTime;
  60. import org.joda.time.format.DateTimeFormatter;
  61. import org.joda.time.format.ISODateTimeFormat;
  62. import org.slf4j.Logger;
  63. import org.slf4j.LoggerFactory;
  64. import javax.servlet.http.HttpServletResponse;
  65. import java.io.File;
  66. import java.io.IOException;
  67. import java.io.InputStream;
  68. import java.io.OutputStream;
  69. import java.nio.file.Files;
  70. import java.util.ArrayList;
  71. import java.util.List;
  72. /**
  73. */
  74. public class ArchivaDavResource
  75. implements DavResource
  76. {
  77. public static final String HIDDEN_PATH_PREFIX = ".";
  78. private final ArchivaDavResourceLocator locator;
  79. private final DavResourceFactory factory;
  80. private final File localResource;
  81. private final String logicalResource;
  82. private DavPropertySet properties = null;
  83. private LockManager lockManager;
  84. private final DavSession session;
  85. private String remoteAddr;
  86. private final ManagedRepository repository;
  87. private final MimeTypes mimeTypes;
  88. private List<AuditListener> auditListeners;
  89. private String principal;
  90. public static final String COMPLIANCE_CLASS = "1, 2";
  91. private final ArchivaTaskScheduler scheduler;
  92. private final FileLockManager fileLockManager;
  93. private Logger log = LoggerFactory.getLogger( ArchivaDavResource.class );
  94. public ArchivaDavResource( String localResource, String logicalResource, ManagedRepository repository,
  95. DavSession session, ArchivaDavResourceLocator locator, DavResourceFactory factory,
  96. MimeTypes mimeTypes, List<AuditListener> auditListeners,
  97. RepositoryArchivaTaskScheduler scheduler, FileLockManager fileLockManager )
  98. {
  99. this.localResource = new File( localResource );
  100. this.logicalResource = logicalResource;
  101. this.locator = locator;
  102. this.factory = factory;
  103. this.session = session;
  104. // TODO: push into locator as well as moving any references out of the resource factory
  105. this.repository = repository;
  106. // TODO: these should be pushed into the repository layer, along with the physical file operations in this class
  107. this.mimeTypes = mimeTypes;
  108. this.auditListeners = auditListeners;
  109. this.scheduler = scheduler;
  110. this.fileLockManager = fileLockManager;
  111. }
  112. public ArchivaDavResource( String localResource, String logicalResource, ManagedRepository repository,
  113. String remoteAddr, String principal, DavSession session,
  114. ArchivaDavResourceLocator locator, DavResourceFactory factory, MimeTypes mimeTypes,
  115. List<AuditListener> auditListeners, RepositoryArchivaTaskScheduler scheduler,
  116. FileLockManager fileLockManager )
  117. {
  118. this( localResource, logicalResource, repository, session, locator, factory, mimeTypes, auditListeners,
  119. scheduler, fileLockManager );
  120. this.remoteAddr = remoteAddr;
  121. this.principal = principal;
  122. }
  123. @Override
  124. public String getComplianceClass()
  125. {
  126. return COMPLIANCE_CLASS;
  127. }
  128. @Override
  129. public String getSupportedMethods()
  130. {
  131. return METHODS;
  132. }
  133. @Override
  134. public boolean exists()
  135. {
  136. return localResource.exists();
  137. }
  138. @Override
  139. public boolean isCollection()
  140. {
  141. return localResource.isDirectory();
  142. }
  143. @Override
  144. public String getDisplayName()
  145. {
  146. String resPath = getResourcePath();
  147. return ( resPath != null ) ? Text.getName( resPath ) : resPath;
  148. }
  149. @Override
  150. public DavResourceLocator getLocator()
  151. {
  152. return locator;
  153. }
  154. public File getLocalResource()
  155. {
  156. return localResource;
  157. }
  158. @Override
  159. public String getResourcePath()
  160. {
  161. return locator.getResourcePath();
  162. }
  163. @Override
  164. public String getHref()
  165. {
  166. return locator.getHref( isCollection() );
  167. }
  168. @Override
  169. public long getModificationTime()
  170. {
  171. return localResource.lastModified();
  172. }
  173. @Override
  174. public void spool( OutputContext outputContext )
  175. throws IOException
  176. {
  177. if ( !isCollection() )
  178. {
  179. outputContext.setContentLength( localResource.length() );
  180. outputContext.setContentType( mimeTypes.getMimeType( localResource.getName() ) );
  181. }
  182. try
  183. {
  184. if ( !isCollection() && outputContext.hasStream() )
  185. {
  186. Lock lock = fileLockManager.readFileLock( localResource );
  187. try (InputStream is = Files.newInputStream( lock.getFile().toPath() ))
  188. {
  189. IOUtils.copy( is, outputContext.getOutputStream() );
  190. }
  191. }
  192. else if ( outputContext.hasStream() )
  193. {
  194. IndexWriter writer = new IndexWriter( this, localResource, logicalResource );
  195. writer.write( outputContext );
  196. }
  197. }
  198. catch ( FileLockException e )
  199. {
  200. throw new IOException( e.getMessage(), e );
  201. }
  202. catch ( FileLockTimeoutException e )
  203. {
  204. throw new IOException( e.getMessage(), e );
  205. }
  206. }
  207. @Override
  208. public DavPropertyName[] getPropertyNames()
  209. {
  210. return getProperties().getPropertyNames();
  211. }
  212. @Override
  213. public DavProperty getProperty( DavPropertyName name )
  214. {
  215. return getProperties().get( name );
  216. }
  217. @Override
  218. public DavPropertySet getProperties()
  219. {
  220. return initProperties();
  221. }
  222. @Override
  223. public void setProperty( DavProperty property )
  224. throws DavException
  225. {
  226. }
  227. @Override
  228. public void removeProperty( DavPropertyName propertyName )
  229. throws DavException
  230. {
  231. }
  232. public MultiStatusResponse alterProperties( DavPropertySet setProperties, DavPropertyNameSet removePropertyNames )
  233. throws DavException
  234. {
  235. return null;
  236. }
  237. @SuppressWarnings("unchecked")
  238. @Override
  239. public MultiStatusResponse alterProperties( List changeList )
  240. throws DavException
  241. {
  242. return null;
  243. }
  244. @Override
  245. public DavResource getCollection()
  246. {
  247. DavResource parent = null;
  248. if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
  249. {
  250. String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
  251. if ( parentPath.equals( "" ) )
  252. {
  253. parentPath = "/";
  254. }
  255. DavResourceLocator parentloc =
  256. locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
  257. try
  258. {
  259. parent = factory.createResource( parentloc, session );
  260. }
  261. catch ( DavException e )
  262. {
  263. // should not occur
  264. }
  265. }
  266. return parent;
  267. }
  268. @Override
  269. public void addMember( DavResource resource, InputContext inputContext )
  270. throws DavException
  271. {
  272. File localFile = new File( localResource, resource.getDisplayName() );
  273. boolean exists = localFile.exists();
  274. if ( isCollection() && inputContext.hasStream() ) // New File
  275. {
  276. try (OutputStream stream = Files.newOutputStream( localFile.toPath() ))
  277. {
  278. IOUtils.copy( inputContext.getInputStream(), stream );
  279. }
  280. catch ( IOException e )
  281. {
  282. throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
  283. }
  284. // TODO: a bad deployment shouldn't delete an existing file - do we need to write to a temporary location first?
  285. long expectedContentLength = inputContext.getContentLength();
  286. long actualContentLength = localFile.length();
  287. // length of -1 is given for a chunked request or unknown length, in which case we accept what was uploaded
  288. if ( expectedContentLength >= 0 && expectedContentLength != actualContentLength )
  289. {
  290. String msg = "Content Header length was " + expectedContentLength + " but was " + actualContentLength;
  291. log.debug( "Upload failed: {}", msg );
  292. FileUtils.deleteQuietly( localFile );
  293. throw new DavException( HttpServletResponse.SC_BAD_REQUEST, msg );
  294. }
  295. queueRepositoryTask( localFile );
  296. log.debug( "File '{}{}(current user '{}')", resource.getDisplayName(),
  297. ( exists ? "' modified " : "' created " ), this.principal );
  298. triggerAuditEvent( resource, exists ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE );
  299. }
  300. else if ( !inputContext.hasStream() && isCollection() ) // New directory
  301. {
  302. localFile.mkdir();
  303. log.debug( "Directory '{}' (current user '{}')", resource.getDisplayName(), this.principal );
  304. triggerAuditEvent( resource, AuditEvent.CREATE_DIR );
  305. }
  306. else
  307. {
  308. String msg = "Could not write member " + resource.getResourcePath() + " at " + getResourcePath()
  309. + " as this is not a DAV collection";
  310. log.debug( msg );
  311. throw new DavException( HttpServletResponse.SC_BAD_REQUEST, msg );
  312. }
  313. }
  314. @Override
  315. public DavResourceIterator getMembers()
  316. {
  317. List<DavResource> list = new ArrayList<>();
  318. if ( exists() && isCollection() )
  319. {
  320. for ( String item : localResource.list() )
  321. {
  322. try
  323. {
  324. if ( !item.startsWith( HIDDEN_PATH_PREFIX ) )
  325. {
  326. String path = locator.getResourcePath() + '/' + item;
  327. DavResourceLocator resourceLocator =
  328. locator.getFactory().createResourceLocator( locator.getPrefix(), path );
  329. DavResource resource = factory.createResource( resourceLocator, session );
  330. if ( resource != null )
  331. {
  332. list.add( resource );
  333. }
  334. log.debug( "Resource '{}' retrieved by '{}'", item, this.principal );
  335. }
  336. }
  337. catch ( DavException e )
  338. {
  339. // Should not occur
  340. }
  341. }
  342. }
  343. return new DavResourceIteratorImpl( list );
  344. }
  345. @Override
  346. public void removeMember( DavResource member )
  347. throws DavException
  348. {
  349. File resource = checkDavResourceIsArchivaDavResource( member ).getLocalResource();
  350. if ( resource.exists() )
  351. {
  352. try
  353. {
  354. if ( resource.isDirectory() )
  355. {
  356. if ( !FileUtils.deleteQuietly( resource ) )
  357. {
  358. throw new IOException( "Could not remove directory" );
  359. }
  360. triggerAuditEvent( member, AuditEvent.REMOVE_DIR );
  361. }
  362. else
  363. {
  364. if ( !resource.delete() )
  365. {
  366. throw new IOException( "Could not remove file" );
  367. }
  368. triggerAuditEvent( member, AuditEvent.REMOVE_FILE );
  369. }
  370. log.debug( "{}{}' removed (current user '{}')", ( resource.isDirectory() ? "Directory '" : "File '" ),
  371. member.getDisplayName(), this.principal );
  372. }
  373. catch ( IOException e )
  374. {
  375. throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
  376. }
  377. }
  378. else
  379. {
  380. throw new DavException( HttpServletResponse.SC_NOT_FOUND );
  381. }
  382. }
  383. private void triggerAuditEvent( DavResource member, String event )
  384. throws DavException
  385. {
  386. String path = logicalResource + "/" + member.getDisplayName();
  387. ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( member );
  388. AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, event );
  389. auditEvent.setRemoteIP( resource.remoteAddr );
  390. for ( AuditListener listener : auditListeners )
  391. {
  392. listener.auditEvent( auditEvent );
  393. }
  394. }
  395. @Override
  396. public void move( DavResource destination )
  397. throws DavException
  398. {
  399. if ( !exists() )
  400. {
  401. throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." );
  402. }
  403. try
  404. {
  405. ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( destination );
  406. if ( isCollection() )
  407. {
  408. FileUtils.moveDirectory( getLocalResource(), resource.getLocalResource() );
  409. triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_DIRECTORY );
  410. }
  411. else
  412. {
  413. FileUtils.moveFile( getLocalResource(), resource.getLocalResource() );
  414. triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_FILE );
  415. }
  416. log.debug( "{}{}' moved to '{}' (current user '{}')", ( isCollection() ? "Directory '" : "File '" ),
  417. getLocalResource().getName(), destination, this.principal );
  418. }
  419. catch ( IOException e )
  420. {
  421. throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
  422. }
  423. }
  424. @Override
  425. public void copy( DavResource destination, boolean shallow )
  426. throws DavException
  427. {
  428. if ( !exists() )
  429. {
  430. throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." );
  431. }
  432. if ( shallow && isCollection() )
  433. {
  434. throw new DavException( DavServletResponse.SC_FORBIDDEN, "Unable to perform shallow copy for collection" );
  435. }
  436. try
  437. {
  438. ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( destination );
  439. if ( isCollection() )
  440. {
  441. FileUtils.copyDirectory( getLocalResource(), resource.getLocalResource() );
  442. triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_DIRECTORY );
  443. }
  444. else
  445. {
  446. FileUtils.copyFile( getLocalResource(), resource.getLocalResource() );
  447. triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_FILE );
  448. }
  449. log.debug( "{}{}' copied to '{}' (current user '{)')", ( isCollection() ? "Directory '" : "File '" ),
  450. getLocalResource().getName(), destination, this.principal );
  451. }
  452. catch ( IOException e )
  453. {
  454. throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
  455. }
  456. }
  457. @Override
  458. public boolean isLockable( Type type, Scope scope )
  459. {
  460. return Type.WRITE.equals( type ) && Scope.EXCLUSIVE.equals( scope );
  461. }
  462. @Override
  463. public boolean hasLock( Type type, Scope scope )
  464. {
  465. return getLock( type, scope ) != null;
  466. }
  467. @Override
  468. public ActiveLock getLock( Type type, Scope scope )
  469. {
  470. ActiveLock lock = null;
  471. if ( exists() && Type.WRITE.equals( type ) && Scope.EXCLUSIVE.equals( scope ) )
  472. {
  473. lock = lockManager.getLock( type, scope, this );
  474. }
  475. return lock;
  476. }
  477. @Override
  478. public ActiveLock[] getLocks()
  479. {
  480. ActiveLock writeLock = getLock( Type.WRITE, Scope.EXCLUSIVE );
  481. return ( writeLock != null ) ? new ActiveLock[]{ writeLock } : new ActiveLock[0];
  482. }
  483. @Override
  484. public ActiveLock lock( LockInfo lockInfo )
  485. throws DavException
  486. {
  487. ActiveLock lock = null;
  488. if ( isLockable( lockInfo.getType(), lockInfo.getScope() ) )
  489. {
  490. lock = lockManager.createLock( lockInfo, this );
  491. }
  492. else
  493. {
  494. throw new DavException( DavServletResponse.SC_PRECONDITION_FAILED, "Unsupported lock type or scope." );
  495. }
  496. return lock;
  497. }
  498. @Override
  499. public ActiveLock refreshLock( LockInfo lockInfo, String lockToken )
  500. throws DavException
  501. {
  502. if ( !exists() )
  503. {
  504. throw new DavException( DavServletResponse.SC_NOT_FOUND );
  505. }
  506. ActiveLock lock = getLock( lockInfo.getType(), lockInfo.getScope() );
  507. if ( lock == null )
  508. {
  509. throw new DavException( DavServletResponse.SC_PRECONDITION_FAILED,
  510. "No lock with the given type/scope present on resource " + getResourcePath() );
  511. }
  512. lock = lockManager.refreshLock( lockInfo, lockToken, this );
  513. return lock;
  514. }
  515. @Override
  516. public void unlock( String lockToken )
  517. throws DavException
  518. {
  519. ActiveLock lock = getLock( Type.WRITE, Scope.EXCLUSIVE );
  520. if ( lock == null )
  521. {
  522. throw new DavException( HttpServletResponse.SC_PRECONDITION_FAILED );
  523. }
  524. else if ( lock.isLockedByToken( lockToken ) )
  525. {
  526. lockManager.releaseLock( lockToken, this );
  527. }
  528. else
  529. {
  530. throw new DavException( DavServletResponse.SC_LOCKED );
  531. }
  532. }
  533. @Override
  534. public void addLockManager( LockManager lockManager )
  535. {
  536. this.lockManager = lockManager;
  537. }
  538. @Override
  539. public DavResourceFactory getFactory()
  540. {
  541. return factory;
  542. }
  543. @Override
  544. public DavSession getSession()
  545. {
  546. return session;
  547. }
  548. /**
  549. * Fill the set of properties
  550. */
  551. protected DavPropertySet initProperties()
  552. {
  553. if ( !exists() )
  554. {
  555. properties = new DavPropertySet();
  556. }
  557. if ( properties != null )
  558. {
  559. return properties;
  560. }
  561. DavPropertySet properties = new DavPropertySet();
  562. // set (or reset) fundamental properties
  563. if ( getDisplayName() != null )
  564. {
  565. properties.add( new DefaultDavProperty( DavPropertyName.DISPLAYNAME, getDisplayName() ) );
  566. }
  567. if ( isCollection() )
  568. {
  569. properties.add( new ResourceType( ResourceType.COLLECTION ) );
  570. // Windows XP support
  571. properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "1" ) );
  572. }
  573. else
  574. {
  575. properties.add( new ResourceType( ResourceType.DEFAULT_RESOURCE ) );
  576. // Windows XP support
  577. properties.add( new DefaultDavProperty( DavPropertyName.ISCOLLECTION, "0" ) );
  578. }
  579. // Need to get the ISO8601 date for properties
  580. DateTime dt = new DateTime( localResource.lastModified() );
  581. DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
  582. String modifiedDate = fmt.print( dt );
  583. properties.add( new DefaultDavProperty( DavPropertyName.GETLASTMODIFIED, modifiedDate ) );
  584. properties.add( new DefaultDavProperty( DavPropertyName.CREATIONDATE, modifiedDate ) );
  585. properties.add( new DefaultDavProperty( DavPropertyName.GETCONTENTLENGTH, localResource.length() ) );
  586. this.properties = properties;
  587. return properties;
  588. }
  589. private ArchivaDavResource checkDavResourceIsArchivaDavResource( DavResource resource )
  590. throws DavException
  591. {
  592. if ( !( resource instanceof ArchivaDavResource ) )
  593. {
  594. throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
  595. "DavResource is not instance of ArchivaDavResource" );
  596. }
  597. return (ArchivaDavResource) resource;
  598. }
  599. private void triggerAuditEvent( String remoteIP, String repositoryId, String resource, String action )
  600. {
  601. AuditEvent event = new AuditEvent( repositoryId, principal, resource, action );
  602. event.setRemoteIP( remoteIP );
  603. for ( AuditListener listener : auditListeners )
  604. {
  605. listener.auditEvent( event );
  606. }
  607. }
  608. private void queueRepositoryTask( File localFile )
  609. {
  610. RepositoryTask task = new RepositoryTask();
  611. task.setRepositoryId( repository.getId() );
  612. task.setResourceFile( localFile );
  613. task.setUpdateRelatedArtifacts( false );
  614. task.setScanAll( false );
  615. try
  616. {
  617. scheduler.queueTask( task );
  618. }
  619. catch ( TaskQueueException e )
  620. {
  621. log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName()
  622. + "']." );
  623. }
  624. }
  625. }