You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Julio Carlos Barrera Juez <ju...@i2cat.net> on 2014/05/28 13:14:28 UTC
set credentials on CommandSession
Hello.
I'm creating a Pax Exam test and I want to install a bundle in an specific
moment of the test. I'm using a CommandSession to use bundle:install
command. I get more or less all the stuff working, but I'm getting
"java.lang.SecurityException: Insufficient credentials".
My CommandSession is obtained locally (without getting explicitly the OSGi
service with:
final CommandSession commandSession =
commandProcessor.createSession(System.in, printStream, System.err);
as I saw in many examples. What I need to do to inject credentials in this
session. I've found many non-working solutions like:
commandSession.put("APPLICATION", System.getProperty("karaf.name", "root"));
commandSession.put("USER", "karaf");
Thank you!
Julio C. Barrera Juez
Office phone: +34 93 357 99 27
Distributed Applications and Networks Area (DANA)
i2CAT Foundation, Barcelona, Spain
http://dana.i2cat.net
Re: set credentials on CommandSession
Posted by Julio Carlos Barrera Juez <ju...@i2cat.net>.
Hi Jean-Baptiste
Don't worry about my name ;)
I'm using a fresh Karaf 3.0.1 installation because I'm in a Pax Exam test
using this option:
KarafDistributionOption.karafDistributionConfiguration().frameworkUrl(CoreOptions.maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz")).karafVersion("3.0.1").name("Apache
Karaf")
Then, I suppose I have default values in etc/* files.
Bundle:install commands work perfectly in standalone Karaf instance with
same bundles.
I will use this class as reference for my future tests if I need executing
commands in the shell. Now, as Achim Nierbeck told me, I will inject and
use BundleContext in order to install and uninstall bundles in my test.
Thank you very much.
<http://dana.i2cat.net> <http://www.i2cat.net/en>
Julio C. Barrera Juez [image: View my profile on
LinkedIn]<http://es.linkedin.com/in/jcbarrera/en>
Office phone: (+34) 93 357 99 27 (ext. 527)
Office mobile phone: (+34) 625 66 77 26
Distributed Applications and Networks Area (DANA)
i2CAT Foundation, Barcelona
On 28 May 2014 16:58, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> Hi Julio,
>
> first of all, sorry in my previous e-mail to not use your correct name ;)
>
> You get Insufficient credentials for all commands or only for bundle:*
> commands ? Could you check what you have in etc/*acl.cfg files ?
>
> The same action works fine in Karaf standalone, right ?
>
> Can you use the executeCommand() method provided by KarafTestSupport ?
>
> For instance, in the Karaf itest, we do:
>
> @Test
> public void installUninstallCommand() throws Exception {
> executeCommand("bundle:install mvn:org.apache.servicemix.
> bundles/org.apache.servicemix.bundles.commons-lang/2.4_6");
>
> assertBundleInstalled("org.apache.servicemix.bundles.commons-lang");
> executeCommand("bundle:uninstall org.apache.servicemix.bundles.
> commons-lang");
>
> assertBundleNotInstalled("org.apache.servicemix.bundles.commons-lang");
> }
>
> If you can't (or don't want to) use the KarafTestSupport, you have to use
> Subject.doAs() to execute the command session in "privileged" mode
> (something like:
>
> commandFuture = new FutureTask<String>(new Callable<String>() {
> @Override
> public String call() throws Exception {
> Subject subject = new Subject();
>
> subject.getPrincipals().addAll(Arrays.asList(principals));
> return Subject.doAs(subject, new
> PrivilegedExceptionAction<String>() {
> @Override
> public String run() throws Exception {
> return commandCallable.call();
> }
> });
> }
> });
> )
>
> Honestly, the easiest way is to directly use the executeCommand() provided
> by KarafTestSupport.
>
> Regards
> JB
>
>
> On 05/28/2014 03:02 PM, Julio Carlos Barrera Juez wrote:
>
>> I'm using Karaf 3.0.1 and Pax Exam 3.5.0. I tried using these commands
>> in my test:
>>
>> bundle:install -s -f mvn:<gId>/<aId>/<v> (two times with different
>> bundles)
>> bundle:uninstall -f <bundleId>
>>
>> I configured CommandSession without any option. I am still getting the
>> exception after calling the install command:
>>
>> bundle:install -s -f mvn:<gId>/<aId>/<v>
>> java.lang.SecurityException: Insufficient credentials.
>> ...
>>
>> What is my mistake?
>>
>> Thank you.
>>
>> PD: I'm Julio, not Julian ;)
>>
>>
>> Julio C. Barrera Juez
>> Office phone: +34 93 357 99 27
>> Distributed Applications and Networks Area (DANA)
>> i2CAT Foundation, Barcelona
>> http://dana.i2cat.net <http://dana.i2cat.net/>
>>
>>
>>
>> On 28 May 2014 14:01, Jean-Baptiste Onofré <jb@nanthrax.net
>> <ma...@nanthrax.net>> wrote:
>>
>> Hi Julian,
>>
>> I guess that you use Karaf 3.0.0, right ?
>>
>> What's the command that you want to do (maybe bundle:* -f may help) ?
>>
>> You don't have to provide any use as it uses the default one
>> (karaf), like when you run karaf bin bin/karaf.
>>
>> Regards
>> JB
>>
>>
>> On 05/28/2014 01:14 PM, Julio Carlos Barrera Juez wrote:
>>
>> Hello.
>>
>> I'm creating a Pax Exam test and I want to install a bundle in an
>> specific moment of the test. I'm using a CommandSession to
>> use bundle:install command. I get more or less all the stuff
>> working,
>> but I'm getting "java.lang.SecurityException: Insufficient
>> credentials".
>>
>> My CommandSession is obtained locally (without getting
>> explicitly the
>> OSGi service with:
>>
>> final CommandSession commandSession =
>> commandProcessor.__createSession(System.in, printStream,
>>
>> System.err);
>>
>>
>> as I saw in many examples. What I need to do to inject
>> credentials in
>> this session. I've found many non-working solutions like:
>>
>> commandSession.put("__APPLICATION",
>>
>> System.getProperty("karaf.name <http://karaf.name>
>> <http://karaf.name>", "root"));
>>
>>
>> commandSession.put("USER", "karaf");
>>
>> Thank you!
>>
>>
>> Julio C. Barrera Juez
>> Office phone: +34 93 357 99 27 <tel:%2B34%2093%20357%2099%2027>
>>
>> Distributed Applications and Networks Area (DANA)
>> i2CAT Foundation, Barcelona, Spain
>> http://dana.i2cat.net <http://dana.i2cat.net/>
>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org <ma...@apache.org>
>>
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>>
>>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
Re: set credentials on CommandSession
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Julio,
first of all, sorry in my previous e-mail to not use your correct name ;)
You get Insufficient credentials for all commands or only for bundle:*
commands ? Could you check what you have in etc/*acl.cfg files ?
The same action works fine in Karaf standalone, right ?
Can you use the executeCommand() method provided by KarafTestSupport ?
For instance, in the Karaf itest, we do:
@Test
public void installUninstallCommand() throws Exception {
executeCommand("bundle:install
mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-lang/2.4_6");
assertBundleInstalled("org.apache.servicemix.bundles.commons-lang");
executeCommand("bundle:uninstall
org.apache.servicemix.bundles.commons-lang");
assertBundleNotInstalled("org.apache.servicemix.bundles.commons-lang");
}
If you can't (or don't want to) use the KarafTestSupport, you have to
use Subject.doAs() to execute the command session in "privileged" mode
(something like:
commandFuture = new FutureTask<String>(new Callable<String>() {
@Override
public String call() throws Exception {
Subject subject = new Subject();
subject.getPrincipals().addAll(Arrays.asList(principals));
return Subject.doAs(subject, new
PrivilegedExceptionAction<String>() {
@Override
public String run() throws Exception {
return commandCallable.call();
}
});
}
});
)
Honestly, the easiest way is to directly use the executeCommand()
provided by KarafTestSupport.
Regards
JB
On 05/28/2014 03:02 PM, Julio Carlos Barrera Juez wrote:
> I'm using Karaf 3.0.1 and Pax Exam 3.5.0. I tried using these commands
> in my test:
>
> bundle:install -s -f mvn:<gId>/<aId>/<v> (two times with different
> bundles)
> bundle:uninstall -f <bundleId>
>
> I configured CommandSession without any option. I am still getting the
> exception after calling the install command:
>
> bundle:install -s -f mvn:<gId>/<aId>/<v>
> java.lang.SecurityException: Insufficient credentials.
> ...
>
> What is my mistake?
>
> Thank you.
>
> PD: I'm Julio, not Julian ;)
>
>
> Julio C. Barrera Juez
> Office phone: +34 93 357 99 27
> Distributed Applications and Networks Area (DANA)
> i2CAT Foundation, Barcelona
> http://dana.i2cat.net <http://dana.i2cat.net/>
>
>
> On 28 May 2014 14:01, Jean-Baptiste Onofré <jb@nanthrax.net
> <ma...@nanthrax.net>> wrote:
>
> Hi Julian,
>
> I guess that you use Karaf 3.0.0, right ?
>
> What's the command that you want to do (maybe bundle:* -f may help) ?
>
> You don't have to provide any use as it uses the default one
> (karaf), like when you run karaf bin bin/karaf.
>
> Regards
> JB
>
>
> On 05/28/2014 01:14 PM, Julio Carlos Barrera Juez wrote:
>
> Hello.
>
> I'm creating a Pax Exam test and I want to install a bundle in an
> specific moment of the test. I'm using a CommandSession to
> use bundle:install command. I get more or less all the stuff
> working,
> but I'm getting "java.lang.SecurityException: Insufficient
> credentials".
>
> My CommandSession is obtained locally (without getting
> explicitly the
> OSGi service with:
>
> final CommandSession commandSession =
> commandProcessor.__createSession(System.in, printStream,
> System.err);
>
>
> as I saw in many examples. What I need to do to inject
> credentials in
> this session. I've found many non-working solutions like:
>
> commandSession.put("__APPLICATION",
> System.getProperty("karaf.name <http://karaf.name>
> <http://karaf.name>", "root"));
>
>
> commandSession.put("USER", "karaf");
>
> Thank you!
>
>
> Julio C. Barrera Juez
> Office phone: +34 93 357 99 27 <tel:%2B34%2093%20357%2099%2027>
> Distributed Applications and Networks Area (DANA)
> i2CAT Foundation, Barcelona, Spain
> http://dana.i2cat.net <http://dana.i2cat.net/>
>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org <ma...@apache.org>
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com
Re: set credentials on CommandSession
Posted by Julio Carlos Barrera Juez <ju...@i2cat.net>.
I'm using Karaf 3.0.1 and Pax Exam 3.5.0. I tried using these commands in
my test:
bundle:install -s -f mvn:<gId>/<aId>/<v> (two times with different bundles)
bundle:uninstall -f <bundleId>
I configured CommandSession without any option. I am still getting the
exception after calling the install command:
bundle:install -s -f mvn:<gId>/<aId>/<v>
java.lang.SecurityException: Insufficient credentials.
...
What is my mistake?
Thank you.
PD: I'm Julio, not Julian ;)
Julio C. Barrera Juez
Office phone: +34 93 357 99 27
Distributed Applications and Networks Area (DANA)
i2CAT Foundation, Barcelona
http://dana.i2cat.net
On 28 May 2014 14:01, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> Hi Julian,
>
> I guess that you use Karaf 3.0.0, right ?
>
> What's the command that you want to do (maybe bundle:* -f may help) ?
>
> You don't have to provide any use as it uses the default one (karaf), like
> when you run karaf bin bin/karaf.
>
> Regards
> JB
>
>
> On 05/28/2014 01:14 PM, Julio Carlos Barrera Juez wrote:
>
>> Hello.
>>
>> I'm creating a Pax Exam test and I want to install a bundle in an
>> specific moment of the test. I'm using a CommandSession to
>> use bundle:install command. I get more or less all the stuff working,
>> but I'm getting "java.lang.SecurityException: Insufficient credentials".
>>
>> My CommandSession is obtained locally (without getting explicitly the
>> OSGi service with:
>>
>> final CommandSession commandSession =
>> commandProcessor.createSession(System.in, printStream, System.err);
>>
>>
>> as I saw in many examples. What I need to do to inject credentials in
>> this session. I've found many non-working solutions like:
>>
>> commandSession.put("APPLICATION", System.getProperty("karaf.name
>> <http://karaf.name>", "root"));
>>
>>
>> commandSession.put("USER", "karaf");
>>
>> Thank you!
>>
>>
>> Julio C. Barrera Juez
>> Office phone: +34 93 357 99 27
>> Distributed Applications and Networks Area (DANA)
>> i2CAT Foundation, Barcelona, Spain
>> http://dana.i2cat.net <http://dana.i2cat.net/>
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
Re: set credentials on CommandSession
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Julian,
I guess that you use Karaf 3.0.0, right ?
What's the command that you want to do (maybe bundle:* -f may help) ?
You don't have to provide any use as it uses the default one (karaf),
like when you run karaf bin bin/karaf.
Regards
JB
On 05/28/2014 01:14 PM, Julio Carlos Barrera Juez wrote:
> Hello.
>
> I'm creating a Pax Exam test and I want to install a bundle in an
> specific moment of the test. I'm using a CommandSession to
> use bundle:install command. I get more or less all the stuff working,
> but I'm getting "java.lang.SecurityException: Insufficient credentials".
>
> My CommandSession is obtained locally (without getting explicitly the
> OSGi service with:
>
> final CommandSession commandSession =
> commandProcessor.createSession(System.in, printStream, System.err);
>
>
> as I saw in many examples. What I need to do to inject credentials in
> this session. I've found many non-working solutions like:
>
> commandSession.put("APPLICATION", System.getProperty("karaf.name
> <http://karaf.name>", "root"));
>
> commandSession.put("USER", "karaf");
>
> Thank you!
>
>
> Julio C. Barrera Juez
> Office phone: +34 93 357 99 27
> Distributed Applications and Networks Area (DANA)
> i2CAT Foundation, Barcelona, Spain
> http://dana.i2cat.net <http://dana.i2cat.net/>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com