You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by KonradZuse <Th...@hotmail.com> on 2014/11/19 19:34:32 UTC

Creating securitymanager from ini, cannot read file in classpath?

Hello all,

I believe I made a topic awhile back, that wasn't fully answered, nor can I
find it, so I'm posting again.


According to "Configuration"  http://shiro.apache.org/configuration.html

SecurityManager from an INI resource

We can create the SecurityManager instance from an INI resource path.
Resources can be acquired from the file system, classpath, or URLs when
prefixed with file:, classpath:, or url: respectively. This example uses a
Factory to ingest a shiro.ini file from the root of the classpath and return
the SecurityManager instance:

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.util.Factory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.config.IniSecurityManagerFactory;

...

Factory<SecurityManager> factory = new
IniSecurityManagerFactory("classpath:shiro.ini");
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);


I'm curious where does my ini file need to be in my "JavaFX Application"
which should be exactly the same as a normal one.

I understand that in a web application it goes witrhin the WEB-INF or w/e
folder, but what about here?


I tried the default package, I tried my package and doing both above and
"classpath:pkgname.shiro.ini"

I tried the WEB-INF, also and nothing...


Anyone have any idea where I can put this so I can read it properly?  Ruight
now I am using the absolute path to my ini file...


Thanks all :)



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Creating-securitymanager-from-ini-cannot-read-file-in-classpath-tp7580331.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Creating securitymanager from ini, cannot read file in classpath?

Posted by KonradZuse <Th...@hotmail.com>.
>From what the FX forum said (which wasn't much) was that it should be the
same so I'm not sure what I could be doing wrong?  Does it have to sit at
the top of the classpath, or can we put it inside a directory and call that
specially?

Normally I thought for items in the classpath we just do ("image.png") or
something along those lines?  Is the ini different or am I missing something
here?

Thank you all!



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Creating-securitymanager-from-ini-cannot-read-file-in-classpath-tp7580331p7580388.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Creating securitymanager from ini, cannot read file in classpath?

Posted by KonradZuse <Th...@hotmail.com>.
Yeah I tried putting it in all sorts of places, including the root(Netbeans
calls this the "default package."  I'm not sure about the classloader, I
will post this on Oracle's FX section and see if someone has a comment
towards the classloader.

Thanks for the help Les!


Btw I had issues sending replies back to 2 email topics, this being one of
them, so sorry if people get 2 emails/ a double post on the forum(as of this
moment there is no other post).


It also just asked me if I was a subscriber when I tried to reply (not sure
if that's normal protocol).

Thanks all



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Creating-securitymanager-from-ini-cannot-read-file-in-classpath-tp7580331p7580362.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Creating securitymanager from ini, cannot read file in classpath?

Posted by Les Hazlewood <lh...@apache.org>.
classpath:shiro.ini indicates a shiro.ini file at the root of the classpath
- i.e. at the top of a .jar file and not in a directory.  If this doesn't
work, perhaps it's a JavaFX classloader issue?  Is there anything special
about JavaFX classloading? I'm not sure - I haven't tried this in JavaFX
myself.

--
Les Hazlewood | @lhazlewood
CTO, Stormpath | http://stormpath.com | @goStormpath | 888.391.5282

On Sat, Dec 6, 2014 at 12:27 AM, Konrad Zuse <th...@hotmail.com>
wrote:

> Thanks for the help.
>
> I tried placing it in the default (which I'm assuming is the root?) and
> nothing, I will try this conf/ business.  I have it in another package, so
> I will try to see if the / will work.  I tried to do
> classpath:conf.shiro.ini as that's what we normally do when referencing a
> package/class.
>
> You mention folders though, so I don't know if I should be working in the
> file view and not the project view, but I believe it doesn't matter...
> right?
>
>
> Thanks again for the help, will try this out tomorrow when I'm more awake
> , and will email back the results :).
>
> > Date: Fri, 5 Dec 2014 21:24:11 -0700
> > From: taidan19@gmail.com
> > To: user@shiro.apache.org
> > Subject: Re: Creating securitymanager from ini, cannot read file in
> classpath?
>
> >
> > (Note that I'm not a Shiro developer, but here's my stab at answering the
> > question as a fellow Java developer)
> >
> > Technically, you could put the shiro.ini file anywhere you want in your
> > project. But /where/ you put it will affect how you reference it in your
> > code.
> >
> > If your JavaFX application is a Maven based project, I would place the
> > config file in src/main/resources. By putting it there, Maven would place
> > the file at the root of the JAR/WAR it generates, which would then allow
> you
> > to write the code as you originally have it:
> >
> > Factory<SecurityManager> factory = new
> > IniSecurityManagerFactory("classpath:shiro.ini");
> >
> > If it isn't a Maven application, then you could still place it at the
> root
> > of your project's source tree. Or you could create a conf/ folder or
> > somthing, and place it in there. Then the line above might look like
> this:
> >
> > Factory<SecurityManager> factory = new
> > IniSecurityManagerFactory("classpath:conf/shiro.ini");
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> http://shiro-user.582556.n2.nabble.com/Creating-securitymanager-from-ini-cannot-read-file-in-classpath-tp7580331p7580353.html
> > Sent from the Shiro User mailing list archive at Nabble.com.
>

RE: Creating securitymanager from ini, cannot read file in classpath?

Posted by Konrad Zuse <th...@hotmail.com>.
Thanks for the help.

I tried placing it in the default (which I'm assuming is the root?) and nothing, I will try this conf/ business.  I have it in another package, so I will try to see if the / will work.  I tried to do classpath:conf.shiro.ini as that's what we normally do when referencing a package/class.

You mention folders though, so I don't know if I should be working in the file view and not the project view, but I believe it doesn't matter... right?


Thanks again for the help, will try this out tomorrow when I'm more awake , and will email back the results :).
> Date: Fri, 5 Dec 2014 21:24:11 -0700
> From: taidan19@gmail.com
> To: user@shiro.apache.org
> Subject: Re: Creating securitymanager from ini, cannot read file in classpath?
> 
> (Note that I'm not a Shiro developer, but here's my stab at answering the
> question as a fellow Java developer)
> 
> Technically, you could put the shiro.ini file anywhere you want in your
> project. But /where/ you put it will affect how you reference it in your
> code.
> 
> If your JavaFX application is a Maven based project, I would place the
> config file in src/main/resources. By putting it there, Maven would place
> the file at the root of the JAR/WAR it generates, which would then allow you
> to write the code as you originally have it:
> 
> Factory<SecurityManager> factory = new
> IniSecurityManagerFactory("classpath:shiro.ini"); 
> 
> If it isn't a Maven application, then you could still place it at the root
> of your project's source tree. Or you could create a conf/ folder or
> somthing, and place it in there. Then the line above might look like this:
> 
> Factory<SecurityManager> factory = new
> IniSecurityManagerFactory("classpath:conf/shiro.ini");
> 
> 
> 
> 
> 
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Creating-securitymanager-from-ini-cannot-read-file-in-classpath-tp7580331p7580353.html
> Sent from the Shiro User mailing list archive at Nabble.com.
 		 	   		  

Re: Creating securitymanager from ini, cannot read file in classpath?

Posted by taidan19 <ta...@gmail.com>.
(Note that I'm not a Shiro developer, but here's my stab at answering the
question as a fellow Java developer)

Technically, you could put the shiro.ini file anywhere you want in your
project. But /where/ you put it will affect how you reference it in your
code.

If your JavaFX application is a Maven based project, I would place the
config file in src/main/resources. By putting it there, Maven would place
the file at the root of the JAR/WAR it generates, which would then allow you
to write the code as you originally have it:

Factory<SecurityManager> factory = new
IniSecurityManagerFactory("classpath:shiro.ini"); 

If it isn't a Maven application, then you could still place it at the root
of your project's source tree. Or you could create a conf/ folder or
somthing, and place it in there. Then the line above might look like this:

Factory<SecurityManager> factory = new
IniSecurityManagerFactory("classpath:conf/shiro.ini");





--
View this message in context: http://shiro-user.582556.n2.nabble.com/Creating-securitymanager-from-ini-cannot-read-file-in-classpath-tp7580331p7580353.html
Sent from the Shiro User mailing list archive at Nabble.com.