cancel
Showing results for 
Search instead for 
Did you mean: 

How to do runas admin in webscript

cperez
Champ in-the-making
Champ in-the-making
I try to run my webscript as admin permissions like is described in http://docs.alfresco.com/3.4/references/api-ws-runas.html, but my alfresco version is 3.0 Labs and I can't do that.

My web script run a script placed in "Data Dictionary/Scripts" that remove one file where the user haven't got the 'remove' permission.

My "doAct.get.desc.xml" is:
‍‍


If I refresh my webscript I get the next error message:
Alfresco Web Scripts MaintenanceMaintenance CompletedReset Web Scripts Registry; registered 284 Web Scripts. Previously, there were 285.Warning: found 1 broken Web Scripts. Previously, there were 0.Broken Web ScriptsFailed to parse web script description document doAct/doAct.get.desc.xml ; runas user declared for script in insecure store (workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts/doAct/doAct.get.desc.xml)List Web Scripts‍‍‍‍‍‍‍‍‍‍‍‍


And If I run the web script I get the next error:
Web Script Status 404 - Not FoundThe Web Script /alfresco/service/doAct has responded with a status of 404 - Not Found.404 Description:   Requested resource is not available. Message:   Script url /doAct does not map to a Web Script.    Exception:   org.alfresco.web.scripts.WebScriptException - Script url /doAct does not map to a Web Script.       org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:106)   org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:116)   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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)   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:286)   org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)   org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)   org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)   org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)   org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)   java.lang.Thread.run(Thread.java:662)    Server:   Alfresco Labs v3.0.0 (Stable 1526) schema 1,002Time:   Sep 22, 2014 1:34:43 PM‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


This happens if my webscript is in "Data Dictionary/Web Scripts" and in "Data Dictionary/Web Scripts Extensions".

How I can solve it?? Where is the secure store??

thanks in advance
13 REPLIES 13

kaynezhang
World-Class Innovator
World-Class Innovator
If you want to  use
<authentication runas="admin">user</authentication>‍
element in your web script descriptor,you should place the webscript in classpath instead of repository.

cperez
Champ in-the-making
Champ in-the-making
thanks. I will try it later and check if it is my solution.

But now I have one question. Let me explain:

I want to import a script located in "Company Home/Data Dictionary/Scripts/modify_metadata.js" within the webscript "doAct.get.js" and I use the next four options with errors in all of then:
//<import resource="/Company Home/Data Dictionary/Scripts/modify_metadata.js">//<import resource="workspace://SpacesStore/7c409e0f-0861-4d10-b9a1-e694b48bc445">//<import resource="/Company Home/Data Dictionary/Scripts/modify_metadata.js">;<import resource="workspace://SpacesStore/7c409e0f-0861-4d10-b9a1-e694b48bc445">;‍‍‍‍‍‍


And this is the error:
If I comment the import lines the error doesn't appear.
With the import line I get an error with "status.code = 404;" (work if the import resource line is commented)
If I comment the line with status code, I get the error in the "model.fichero=fichero;" (It also works if the import resource is commented)
Alfresco    Web Script Status 500 - Internal ErrorThe Web Script /planinicial/service/doAct has responded with a status of 500 - Internal Error.500 Description:   An error inside the HTTP server which prevented it from fulfilling the request. Message:   Wrapped Exception (with status template): Failed to execute script '/doAct/doAct.get.js (in repository store workspace://SpacesStore/Company Home/dictionary/Web Scripts Extensions)': syntax error (AlfrescoScript#20)    Exception:   org.mozilla.javascript.EvaluatorException - syntax error (AlfrescoScript#20)       org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)   org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)   org.mozilla.javascript.Parser.addError(Parser.java:140)   org.mozilla.javascript.Parser.reportError(Parser.java:154)   org.mozilla.javascript.Parser.mustMatchToken(Parser.java:240)   org.mozilla.javascript.Parser.xmlInitializer(Parser.java:1634)   org.mozilla.javascript.Parser.unaryExpr(Parser.java:1584)   org.mozilla.javascript.Parser.mulExpr(Parser.java:1519)   org.mozilla.javascript.Parser.addExpr(Parser.java:1500)   org.mozilla.javascript.Parser.shiftExpr(Parser.java:1480)   org.mozilla.javascript.Parser.relExpr(Parser.java:1454)   org.mozilla.javascript.Parser.eqExpr(Parser.java:1410)   org.mozilla.javascript.Parser.bitAndExpr(Parser.java:1399)   org.mozilla.javascript.Parser.bitXorExpr(Parser.java:1388)   org.mozilla.javascript.Parser.bitOrExpr(Parser.java:1377)   org.mozilla.javascript.Parser.andExpr(Parser.java:1365)   org.mozilla.javascript.Parser.orExpr(Parser.java:1353)   org.mozilla.javascript.Parser.condExpr(Parser.java:1336)   org.mozilla.javascript.Parser.assignExpr(Parser.java:1321)   org.mozilla.javascript.Parser.expr(Parser.java:1308)   org.mozilla.javascript.Parser.statementHelper(Parser.java:1205)   org.mozilla.javascript.Parser.statement(Parser.java:655)   org.mozilla.javascript.Parser.parse(Parser.java:377)   org.mozilla.javascript.Parser.parse(Parser.java:315)   org.mozilla.javascript.Context.compileImpl(Context.java:2320)   org.mozilla.javascript.Context.compileString(Context.java:1348)   org.mozilla.javascript.Context.compileString(Context.java:1337)   org.mozilla.javascript.Context.evaluateString(Context.java:1193)   org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:390)   org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:122)   org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:263)   org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:108)   org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:800)   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:90)   org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:319)   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320)   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227)   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:368)   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:390)   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:273)   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:261)   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)   org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:116)   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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)   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:286)   org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)   org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)   org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)   org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)   org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)   java.lang.Thread.run(Thread.java:662)    Exception:   org.alfresco.error.AlfrescoRuntimeException - syntax error (AlfrescoScript#20)       org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:406)    Exception:   org.alfresco.scripts.ScriptException - Failed to execute script '/doAct/doAct.get.js (in repository store workspace://SpacesStore/Company Home/dictionary/Web Scripts Extensions)': syntax error (AlfrescoScript#20)       org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:126)    Exception:   org.alfresco.web.scripts.WebScriptException - Wrapped Exception (with status template): Failed to execute script '/doAct/doAct.get.js (in repository store workspace://SpacesStore/Company Home/dictionary/Web Scripts Extensions)': syntax error (AlfrescoScript#20)       org.alfresco.web.scripts.AbstractWebScript.createStatusException(AbstractWebScript.java:595)    Server:   Alfresco Labs v3.0.0 (Stable 1526) schema 1.002Time:   23-sep-2014 12:16:35    Diagnostics:   Inspect Web Script (doAct/doAct.get)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


And this is my "doAct.get.js":
//<import resource="/Company Home/Data Dictionary/Scripts/actions.js">//<import resource="/Company Home/Data Dictionary/Scripts/modify_metadata.js"><import resource="workspace://SpacesStore/7c409e0f-0861-4d10-b9a1-e694b48bc445">//______________________//______________________// var fichero = null;var fichero = getDoc(args.nId);var periodoAbierto;var mensaje="";// if (fichero == null){   status.code = 404;   status.message = "File not found.";   status.redirect = true;} else {   model.fichero = fichero;   // Obtener si el mes al que pertenece el fichero está abierto   periodoAbierto = getPeriodoAbierto(fichero);   if (!periodoAbierto){      status.code = 404;      status.message = "El periodo al que pertenece la factura ya est&aacute; cerrado y no se pueden realizar operaciones.";      status.redirect = true;   } else {      if(args.act=="supr"){         try{         var nombre = fichero.properties.name;         if(remove_node(fichero)){               mensaje = "Factura  '" + nombre + "' eliminada Correctamente.";            } else {               mensaje = "No se ha podido eliminar la factura '" + nombre + "'.";            }         } catch(err) {            status.code = 403;            status.message = "El usuario no tiene permisos para borrar el fichero.";            status.redirect = true;         }      } else if(args.act=="edit"){         // Comprobar que la factura está Aprobada         var estadoFichero = getEstado(fichero);         // Mostrar error si el período está cerrado         if (!estadoFichero){            status.code = 404;            status.message = "La factura no est&aacute; aprobada.";            status.redirect = true;         } else {            mensaje = cambiarMetadatos(url.args, args, fichero);         }      } else {         status.code = 404;         status.message = "La operaci&oacute;n especificada '" + args.act + "' no es correcta.";         status.redirect = true;      }   }}model.mensaje=mensaje;model.nId = args.nId;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


The error happens with all the "status.*" and "model.*" lines when the import tag is not commented, but i must import that file.

Have you got any idea about the solution??

Thanks a lot!

kaynezhang
World-Class Innovator
World-Class Innovator
The import lines must always be first in the file - <strong>even before any comments,and without ending ";"</strong>
So your doAct.get.js should be like this
<import resource="workspace://SpacesStore/7c409e0f-0861-4d10-b9a1-e694b48bc445">//______________________//______________________// var fichero = null;var fichero = getDoc(args.nId);var periodoAbierto;var mensaje="";….‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

or like this
<import resource="/Company Home/Data Dictionary/Scripts/modify_metadata.js">//______________________//______________________// var fichero = null;var fichero = getDoc(args.nId);var periodoAbierto;var mensaje="";….‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

cperez
Champ in-the-making
Champ in-the-making
I did the same you mention but it still showing error on the same lines as before.

After that, I emptied the imported script in case there were some error in the file but still the same error.

I don't know why this is happening.

kaynezhang
World-Class Innovator
World-Class Innovator
Weird,it should work.It might have something to do with your alfresco version.
Please try to place all webscripts file(doAct.get.js/doAct.get.desc.xml/doAct.get.ftl) and "modify_metadata.js" into classpath and import it from classpath using
<import resource="classpath:/***/***/modify_metadata.js">‍‍‍

cperez
Champ in-the-making
Champ in-the-making
I place all the documens (webscripts files and modify_metadata.js)in that folder and restart alfresco every time I modified any file:
/opt/Alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/doAct‍‍‍

and I try to import the javascript file with that options:
<import resource="classpath:/alfresco/templates/webscripts/doAct/modify_metadata.js">‍‍‍

and
<import resource="classpath:/opt/Alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/doAct/modify_metadata.js">‍‍‍

and finally with the repository javascript
<import resource="/Company Home/Data Dictionary/Scripts/modify_metadata.js">‍‍‍

but I'm having the same error.

Do you know any other option??
Or is there another way to do that??

kaynezhang
World-Class Innovator
World-Class Innovator
Weird ,both
<import resource="classpath:/alfresco/templates/webscripts/doAct/modify_metadata.js">‍‍‍

and
<import resource="/Company Home/Data Dictionary/Scripts/modify_metadata.js">‍‍‍

should work.
Could you please try to copy content in "modify_metadata.js" into "doAct.get.js"  and avoid using import?

cperez
Champ in-the-making
Champ in-the-making
Yes I tried it.
If I copy content in "modify_metadata.js" into "doAct.get.js", it works ok but I need to avoid that option because I want to hide the content to end users. This is why i want to store "modify_metadata.js" in alfresco repository ans use the import option in "doAct.get.js".

Thanks.


kaynezhang
World-Class Innovator
World-Class Innovator
Could you please try it in a newer alfresco version ,it might be a bug of your version.