fpravica / grep4j

Automatically exported from code.google.com/p/grep4j
0 stars 0 forks source link

problem with access remote server without password #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello! I'm using your framework to remote server grep. For example, I'm using 
next code:
             profile = ProfileBuilder.newBuilder()
                    .name("Max")
                    .filePath(serverPath)
                    .onRemotehost(host.getHost())
                    .credentials(login, pass)
                    .build();
             grep(constantExpression(id), on(profile));

and all working good. 
The problem appear, when I need to access the server, which has access through 
login WITHOUT password. I'm using:

            Profile profile = new Profile("Max", serverPath);
            ServerDetails serverDetails = new ServerDetails(host);
            serverDetails.setUser(login);
            serverDetails.setPasswordRequired(false);
            profile.setServerDetails(serverDetails);
         grep(constantExpression(id), on(profile));

But after grep I've got the next error:

ERROR [2013-12-11 10:36:09,902] 
ua.privatbank.eantifraud.client.core.resource.EntryPointResource: 
EntryPointResource::processLogRequest error = Error when executing the GrepTask
WARN  [2013-12-11 10:36:09,919] org.eclipse.jetty.servlet.ServletHandler: 
/api/logs
! java.lang.IllegalStateException: Committed
! at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1144) 
~[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
javax.servlet.ServletResponseWrapper.resetBuffer(ServletResponseWrapper.java:232
) ~[javax.servlet-3.0.0.v201112011016.jar:na]
! at 
org.eclipse.jetty.http.gzip.CompressedResponseWrapper.resetBuffer(CompressedResp
onseWrapper.java:268) ~[jetty-http-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.http.gzip.CompressedResponseWrapper.sendError(CompressedRespon
seWrapper.java:282) ~[jetty-http-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
com.sun.jersey.spi.container.servlet.WebComponent$Writer.finish(WebComponent.jav
a:282) ~[jersey-servlet-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241)
 ~[jersey-server-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebAppl
icationImpl.java:1479) ~[jersey-server-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebAppli
cationImpl.java:1391) ~[jersey-server-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebAppli
cationImpl.java:1381) ~[jersey-server-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
 ~[jersey-servlet-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.j
ava:538) ~[jersey-servlet-1.17.1.jar:1.17.1]
! at 
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.j
ava:716) ~[jersey-servlet-1.17.1.jar:1.17.1]
! at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) 
~[javax.servlet-3.0.0.v201112011016.jar:na]
! at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669) 
~[jetty-servlet-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1448) ~[jetty-servlet-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
com.yammer.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:2
9) ~[dropwizard-core-0.6.2.jar:na]
! at 
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.jav
a:1419) ~[jetty-servlet-8.1.10.v20130312.jar:8.1.10.v20130312]
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455) 
[jetty-servlet-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:107
5) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384) 
[jetty-servlet-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009
) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
com.yammer.metrics.jetty.InstrumentedHandler.handle(InstrumentedHandler.java:200
) [metrics-jetty-2.2.0.jar:na]
! at org.eclipse.jetty.server.handler.GzipHandler.handle(GzipHandler.java:264) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
com.yammer.dropwizard.jetty.BiDiGzipHandler.handle(BiDiGzipHandler.java:123) 
[dropwizard-core-0.6.2.jar:na]
! at 
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java
:154) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at org.eclipse.jetty.server.Server.handle(Server.java:368) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnec
tion.java:489) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnec
tion.java:53) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConne
ction.java:942) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(Ab
stractHttpConnection.java:1004) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640) 
[jetty-http-8.1.10.v20130312.jar:8.1.10.v20130312]
! at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) 
[jetty-http-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.ja
va:72) [jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.ru
n(BlockingChannelConnector.java:298) 
[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
 [jetty-util-8.1.10.v20130312.jar:8.1.10.v20130312]
! at 
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) 
[jetty-util-8.1.10.v20130312.jar:8.1.10.v20130312]
! at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
127.0.0.1 - - [11/Dec/2013:10:36:09 +0000] "GET 
/api/logs?id=52a8351ce4b0d200a587f1f0&date=11&month=12&year=2013&server=prod 
HTTP/1.1" 200 27 700 700

What am I doing wrong? How rigth to access the server without password?

Original issue reported on code.google.com by Malovich...@gmail.com on 11 Dec 2013 at 11:18

GoogleCodeExporter commented 9 years ago
is this something you can workaround by using userAuthPrivateKeyLocation ? 
Example:
Profile remoteProfileWithPublicKey = ProfileBuilder.newBuilder()
                                     .name("Another remote server log")
                                     .filePath("/path/to/file/filename.txt")
                                     .onRemotehost("172.x.x.x")
                                     .userAuthPrivateKeyLocation("/home/user/.ssh/id_dsa")
                                     .withUser("user")
                                     .build();

Original comment by marcocast@gmail.com on 12 Dec 2013 at 12:14

GoogleCodeExporter commented 9 years ago
Thank for your answer!
I tried your way before address to you, but was exception too (full stack 
trace):

Exception in thread "main" java.lang.RuntimeException: Error when executing the 
GrepTask
    at org.grep4j.core.executors.GrepExecutor.execute(GrepExecutor.java:59)
    at org.grep4j.core.executors.GrepExecutor.execute(GrepExecutor.java:27)
    at org.grep4j.core.Grep4j.execute(Grep4j.java:239)
    at org.grep4j.core.Grep4j.grep(Grep4j.java:145)
    at org.grep4j.core.Grep4j.grep(Grep4j.java:213)
    at ua.privatbank.eantifraud.client.core.resource.EntryPointResource.main(EntryPointResource.java:181)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: 
Error when executing the CommandExecutorTasks
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.grep4j.core.executors.GrepExecutor.execute(GrepExecutor.java:54)
    ... 10 more
Caused by: java.lang.RuntimeException: Error when executing the 
CommandExecutorTasks
    at org.grep4j.core.executors.GrepTaskExecutor.execute(GrepTaskExecutor.java:51)
    at org.grep4j.core.executors.GrepTaskExecutor.execute(GrepTaskExecutor.java:25)
    at org.grep4j.core.task.GrepTask.call(GrepTask.java:51)
    at org.grep4j.core.task.GrepTask.call(GrepTask.java:31)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: 
ERROR: Unrecoverable error when performing remote command ERROR: Unrecoverable 
error when trying to connect to serverDetails :  
ServerDetails(host=remote.host, user=eanfuser, password=null, port=22, 
privateKeyLocation=/home/user/.ssh/id_rsa, isPasswordRequired=false)
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.grep4j.core.executors.GrepTaskExecutor.execute(GrepTaskExecutor.java:48)
    ... 7 more
Caused by: java.lang.RuntimeException: ERROR: Unrecoverable error when 
performing remote command ERROR: Unrecoverable error when trying to connect to 
serverDetails :  ServerDetails(host=remote.host, user=eanfuser, password=null, 
port=22, privateKeyLocation=/home/user/.ssh/id_rsa, isPasswordRequired=false)
    at org.grep4j.core.command.linux.JschCommandExecutor.execute(JschCommandExecutor.java:46)
    at org.grep4j.core.task.CommandExecutorTask.call(CommandExecutorTask.java:35)
    at org.grep4j.core.task.CommandExecutorTask.call(CommandExecutorTask.java:19)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    ... 4 more
Caused by: java.lang.RuntimeException: ERROR: Unrecoverable error when trying 
to connect to serverDetails :  ServerDetails(host=remote.host, user=eanfuser, 
password=null, port=22, privateKeyLocation=/home/user/.ssh/id_rsa, 
isPasswordRequired=false)
    at org.grep4j.core.command.linux.SessionFactory.makeObject(SessionFactory.java:39)
    at org.grep4j.core.command.linux.SessionFactory.makeObject(SessionFactory.java:15)
    at org.apache.commons.pool.impl.StackKeyedObjectPool.borrowObject(StackKeyedObjectPool.java:165)
    at org.grep4j.core.command.linux.JschCommandExecutor.execute(JschCommandExecutor.java:37)
    ... 8 more
Caused by: com.jcraft.jsch.JSchException: Auth cancel
    at com.jcraft.jsch.Session.connect(Session.java:490)
    at com.jcraft.jsch.Session.connect(Session.java:162)
    at org.grep4j.core.command.linux.SessionFactory.makeObject(SessionFactory.java:37)
    ... 11 more

But I'm sure, there're no problems with my permission to server - I can get 
into server by console

Code I'm using:

        Profile profile = ProfileBuilder.newBuilder()
                .name("Another")
                .filePath("/opt/eantifraud-processor/log/log.log")
                .onRemotehost("remote.host")                               //I tried IP of host too
                .userAuthPrivateKeyLocation("/home/user/.ssh/id_rsa")
                .withUser("user")
                .build();

        grep(constantExpression(myId), on(profile));

Original comment by Malovich...@gmail.com on 12 Dec 2013 at 1:21

GoogleCodeExporter commented 9 years ago
Did you generated a pair of authentication keys?
see http://www.linuxproblem.org/art_9.html
If you have a AuthPrivateKeyLocation you should point to your specific id_rsa, 
the code you are using is using the same as the grep4j example 
/home/user/.ssh/id_rsa which i doubt is your correct location.

Original comment by marcocast@gmail.com on 13 Dec 2013 at 12:51

GoogleCodeExporter commented 9 years ago
May be too late to come to this page.. This is the same issue I had faced with 
remote access without requiring a password or "sudo". The solution explained in 
http://www.linuxproblem.org/art_9.html will resolve the issue. Only thing you 
need to do is to specify a correct RSA private key location.

Grep4j correctly returns the results after that.

Original comment by NitinSg1...@gmail.com on 21 Apr 2014 at 7:22