• Get admin right in crontab

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #29306  by cjpitmd
 
Hello everyone,

i tried to add a script into the crontab and make it run every week,

but i got AccessDeniedException : Sorry, only for admin user. Here is my script:
Code: Select all
import java.io.File;
import java.io.FileOutputStream;
import java.io.StringWriter;
import com.openkm.util.impexp.RepositoryExporter;
import com.openkm.util.impexp.TextInfoDecorator;
import java.util.date;
import java.text.SimpleDateFormat;
import com.openkm.module.db.stuff.DbSessionManager;

String token = DbSessionManager.getInstance().getSystemToken();

SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");

File file = new File("C:/okmbackup/"+ df.format(new Date()));

// OpenKM root
String fldPath = "/okm:root";

StringWriter out = new StringWriter();

//create folder
file.mkdir();

RepositoryExporter.exportDocuments(token, fldPath, file, true, true, out, new TextInfoDecorator(fldPath));
when i change the parameter from token to null, ( eg. RepositoryExporter.exportDocuments(null, fldPath, file...........) )

i can run it normally when i click the Execute button ( flash icon ), but it cannot run automatically, i will get a message : nullPointerException,

So, how can i get the admin right to run those script ?

ps. I am using openkm 6.2.5
Attachments
1.png
1.png (265.82 KiB) Viewed 4728 times
 #29328  by jllort
 
Seems you're using correctly the system token. One suggestion -> upgrade to 6.3. I need to take a look at full stack trace to understand what's happening.
 #29355  by cjpitmd
 
jllort wrote:Seems you're using correctly the system token. One suggestion -> upgrade to 6.3. I need to take a look at full stack trace to understand what's happening.
OK, thx for you help

i will very happy if you find out what's happen, pls let me know if you find out how to solve the problem :D
 #29373  by jllort
 
is quite strange. With what user are you logged, okmAdmin ?
 #29378  by cjpitmd
 
jllort wrote:is quite strange. With what user are you logged, okmAdmin ?
Yes, okmAdmin . I use openkm 6.25 with mysql 5.5 .

The script can be executed in 6.3 last day, but i cannot execute it today

here is the log of openkm6.3
Code: Select all
2014-07-23 14:14:35,202 [http-bio-0.0.0.0-8080-exec-5] ERROR com.openkm.util.impexp.RepositoryExporter- Sorry, only for admin user
com.openkm.core.AccessDeniedException: Sorry, only for admin user
	at com.openkm.module.db.DbScriptingModule.getScript(DbScriptingModule.java:137)
	at com.openkm.api.OKMScripting.getScript(OKMScripting.java:72)
	at com.openkm.util.impexp.metadata.MetadataAdapter.getMetadata(MetadataAdapter.java:114)
	at com.openkm.util.impexp.RepositoryExporter.exportDocument(RepositoryExporter.java:282)
	at com.openkm.util.impexp.RepositoryExporter.exportDocumentsHelper(RepositoryExporter.java:190)
	at com.openkm.util.impexp.RepositoryExporter.exportDocumentsHelper(RepositoryExporter.java:199)
	at com.openkm.util.impexp.RepositoryExporter.exportDocuments(RepositoryExporter.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at bsh.Reflect.invokeMethod(Reflect.java:134)
	at bsh.Reflect.invokeStaticMethod(Reflect.java:98)
	at bsh.Name.invokeMethod(Name.java:874)
	at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
	at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
	at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
	at bsh.Interpreter.eval(Interpreter.java:645)
	at bsh.Interpreter.eval(Interpreter.java:739)
	at bsh.Interpreter.eval(Interpreter.java:728)
	at org.apache.jsp.admin.scripting_jsp._jspService(scripting_jsp.java:195)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
here is the script
Code: Select all
import java.io.File;
import java.io.FileOutputStream;
import java.io.StringWriter;
import com.openkm.util.impexp.RepositoryExporter;
import com.openkm.util.impexp.TextInfoDecorator;
import java.util.date;
import java.text.SimpleDateFormat;
import com.openkm.module.db.stuff.DbSessionManager;

String token = DbSessionManager.getInstance().getSystemToken();

print("System Token: "+token);

SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");

File file = new File("C:/okmbackup/"+ df.format(new Date()));

// OpenKM root
String fldPath = "/okm:root";

StringWriter out = new StringWriter();

//create folder
file.mkdir();

RepositoryExporter.exportDocuments(token, fldPath, file, true, true, out, new TextInfoDecorator(fldPath));
Attachments
1.png
1.png (237.75 KiB) Viewed 4702 times
 #29405  by cjpitmd
 
jllort wrote:Seems you're using correctly the system token. One suggestion -> upgrade to 6.3. I need to take a look at full stack trace to understand what's happening.
I success to export repository in crontab now by changed
Code: Select all
String token = DbSessionManager.getInstance().getSystemToken();
to
Code: Select all
String token = OKMAuth.getInstance().login(user,pass);
 #29421  by jllort
 
We will investigate it, because is not normal.
 #29512  by pavila
 
I have uploaded a fix. Please, try the night build (these builds are compiled at 00:02 GMT+2).
 #29543  by cjpitmd
 
pavila wrote:I have uploaded a fix. Please, try the night build (these builds are compiled at 00:02 GMT+2).
\ :D THX FOR YOUR HELP

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.