AnsweredAssumed Answered

use LockService.unlock(...) AccessDeniedException

Question asked by madracoon on Feb 7, 2014
Latest reply on Feb 11, 2014 by kaynezhang
I have some documents in Alfresco which were amended by the online edition.
These documents for some reason I do not know are locked.
I does not find function to unlock files even being administrator in share and Alfresco explorer.

So I made a webscript to force the unlocking files from noderef.

My webscript does not work and I have net.sf.acegisecurity.AccessDeniedException error - Access is denied.
when I use the method LockService.unlock(noderef);

Yet I'm authenticated with the admin account.
I test my webscript on my local Alfresco Enterprise 4.1.1.

Please help me


This is my java webscript bean.


public class NodeReleaseLockWebscript extends DeclarativeWebScript {

   private NodeService nodeService;
   private LockService lockService;


   @Override
   protected Map<String, Object> executeImpl(WebScriptRequest request,
         Status status) {

      Map<String, Object> model = new HashMap<String, Object>();
      
      NodeRef nodeRef = getNodeRef(request);

      String name = (String) nodeService.getProperty(nodeRef,ContentModel.PROP_NAME);
      lockService.unlock(nodeRef);
      lockService.getLockStatus(nodeRef);
      LockStatus lockStatus = lockService.getLockStatus(nodeRef);
      
      model.put("nbTotalDocument", 1);
      model.put("nameDocument", name);
      model.put("status", lockStatus.name());
      
      return model;
   }

   private NodeRef getNodeRef(WebScriptRequest request) {
      
      String node = request.getParameter("noderef");
      NodeRef nodeRef = new NodeRef(node);
      if (!nodeService.exists(nodeRef)) {
         throw new WebScriptException(Status.STATUS_BAD_REQUEST,
               "nodeRef provided does not exist");
      }
      return nodeRef;
      
   }
   


   public NodeService getNodeService() {
      return nodeService;
   }

   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

   public LockService getLockService() {
      return lockService;
   }

   public void setLockService(LockService lockService) {
      this.lockService = lockService;
   }


   

}



initiate.post


<webscript>
   <shortname>node lock</shortname>
   <description>node lock</description>
   <url>/nodereleaselock/initiate</url>
   <authentication>user</authentication>
   <transaction>none</transaction>
   <family>Node release lock</family>
  <cache>
    <never>true</never>
  </cache>
</webscript>




<!DOCTYPE html>
<html>
<head>


</head>
<body class="yui-skin-sam">

file unlock </br></br>
nombreTotalDocument : ${nbTotalDocument} </br>
nomDocument : ${nameDocument} </br>


</body>
</html>


ui.get

<webscript>
  <shortname>Node release lock</shortname>
  <description>Web Script that provides a simple UI for node release lock.</description>
  <url>/nodereleaselock</url>
  <format default="html"/>
  <authentication>user</authentication>
  <family>Node release lock</family>
  <cache>
    <never>true</never>
  </cache>
</webscript>



[#ftl]
<!DOCTYPE HTML>
<html>
  <head>
    <title>Node release lock</title>
    <link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">

    <!– YUI 3.x –>
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?3.3.0/build/widget/assets/skins/sam/widget.css&3.3.0/build/widget/assets/skins/sam/widget-stack.css&3.3.0/build/autocomplete/assets/skins/sam/autocomplete.css">
    <script type="text/javascript" src="http://yui.yahooapis.com/combo?3.3.0/build/yui/yui-min.js&3.3.0/build/intl/intl-min.js&3.3.0/build/autocomplete/lang/autocomplete.js&3.3.0/build/collection/array-extras-min.js&3.3.0/build/oop/oop-min.js&3.3.0/build/event-custom/event-custom-min.js&3.3.0/build/attribute/attribute-min.js&3.3.0/build/base/base-base-min.js&3.3.0/build/base/base-build-min.js&3.3.0/build/escape/escape-min.js&3.3.0/build/dom/dom-base-min.js&3.3.0/build/dom/selector-native-min.js&3.3.0/build/dom/selector-css2-min.js&3.3.0/build/event/event-base-min.js&3.3.0/build/node/node-base-min.js&3.3.0/build/event/event-base-ie-min.js&3.3.0/build/event/event-synthetic-min.js&3.3.0/build/event/event-focus-min.js&3.3.0/build/event-valuechange/event-valuechange-min.js&3.3.0/build/querystring/querystring-stringify-simple-min.js&3.3.0/build/io/io-base-min.js&3.3.0/build/json/json-parse-min.js&3.3.0/build/jsonp/jsonp-min.js&3.3.0/build/jsonp/jsonp-url-min.js&3.3.0/build/yql/yql-min.js&3.3.0/build/dom/selector-css3-min.js&3.3.0/build/pluginhost/pluginhost-min.js&3.3.0/build/base/base-pluginhost-min.js&3.3.0/build/dom/dom-style-min.js&3.3.0/build/dom/dom-style-ie-min.js&3.3.0/build/node/node-style-min.js&3.3.0/build/classnamemanager/classnamemanager-min.js&3.3.0/build/event/event-delegate-min.js&3.3.0/build/node/node-event-delegate-min.js&3.3.0/build/widget/widget-min.js&3.3.0/build/widget/widget-base-ie-min.js&3.3.0/build/dom/dom-screen-min.js&3.3.0/build/node/node-screen-min.js&3.3.0/build/widget/widget-position-min.js&3.3.0/build/widget/widget-position-align-min.js&3.3.0/build/widget/widget-stack-min.js&3.3.0/build/autocomplete/autocomplete-min.js&3.3.0/build/autocomplete/autocomplete-list-keys-min.js&3.3.0/build/autocomplete/autocomplete-list-keys-min.js"></script>
   
    <style type="text/css">
      .yui3-aclist-content {
        background-color   : white;
        border             : 1px solid darkgrey;
        box-shadow         : 3px 3px 4px lightgrey;
        -webkit-box-shadow : 3px 3px 4px lightgrey; /* Safari and Chrome */
       
       }
    </style>
   
    <!– Validation functions –>
    <script type="text/javascript">
      function validateRequired(field, errorMessageElement, errorMessage)
      {
        var result = true;

        if (field.value == null || field.value == "")
        {
          errorMessageElement.textContent = errorMessage;
          result = false;
        }
        else
        {
          errorMessageElement.textContent = "";
        }

        return result;
      }


      function validateForm(form)
      {
        var result = true;

        result = validateRequired(form.sourceDirectory, document.getElementById("noderefMessage"), "NodeRef is mandatory.");

        return result;
      }
    </script>
  </head>
  <body class="yui-skin-sam">
    <p>
      <img align="left" src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" />
      <strong>Node release lock</strong><br/>
      Alfresco ${server.edition} v${server.version}
    </p>
    <form action="${url.service}/initiate" method="post" enctype="multipart/form-data" charset="utf-8" onsubmit="return validateForm(this);">
      <table>
        <tr>
          <td>NodeRef:</td><td><input type="text" size="128" name="noderef" /></td><td id="noderefMessage" style="color:red"></td>
        </tr>
        <tr>
          <td colspan="3"><input type="submit" name="submit" value="Initiate release lock"></td>
        </tr>
      </table>
      <br/>
    </form>
  </body>
</html>



my stack trace


Exception:   net.sf.acegisecurity.AccessDeniedException - Access is denied.

net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:398)
net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy49.unlock(Unknown Source)
com.lacapitale.caap.alfresco.model.webscripts.NodeReleaseLockWebscript.executeImpl(NodeReleaseLockWebscript.java:46)
org.springframework.extensions.webscripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:235)
org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:365)
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:517)
org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:377)
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
java.lang.Thread.run(Unknown Source)

Outcomes