You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Gross <co...@gmail.com> on 2011/01/07 19:59:31 UTC

Configuring Embedded Tomcat

I've been looking around, but I can't seem to find somewhere that shows how
you can configure Tomcat when you embed it into an application.

My code is like this:

public void start() throws Exception {
   String hostname = System.getProperty("hostname");
   int port = Integer.parseInt(System.getProperty("port"));
   String path = System.getProperty("path");
   Embedded embedded = new Embedded();
   Engine engine = embedded.createEngine();
   engine.setName("Monitor");
   engine.setHostname(hostname);
   Host host = embedded.createHost(hostname, path);
   engine.addChild(host);
   Context sp = embedded.createContext("/Monitor", path +
"/webapps/monitor");
   host.addChild(sp);
   embedded.addEngine(engine);
   InetAddress addr = null;
   Connector connector = embedded.createConnector(addr, port, false);
   embedded.addConnector(connector);
   embedded.setName("WebServerThread");
   embedded.start();
}

It works fine as it is now, but I'd like to use Tomcat to authenticate
users.  I'll make a separate app for basic users to use to just view a page,
but give admins access to a more advanced page (the pages that I have now).
 Should I be using a different module?  Is there a spot where the embedded
Tomcat will look by default?

Any tips would be greatly appreciated.

Thanks!

-- Chris

Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
I figured it out -- I just needed to put the one application that I wanted
to be secure in the security-constraint section, then let the other ones not
require authentication.

-- Chris


On Mon, Jan 10, 2011 at 2:41 PM, Christopher Gross <co...@gmail.com>wrote:

> That did it!  Thanks Mark & Pid.
>
> Now to make it more complicated -- in order to have another page without
> that restriction, would I need to make a whole new webapp, or can I turn
> down the security for a specific page?
>
> Thanks!
>
> -- Chris
>
>
>
> On Mon, Jan 10, 2011 at 2:18 PM, Pid <pi...@pidster.com> wrote:
>
>> On 1/10/11 6:58 PM, Christopher Gross wrote:
>> > Borrowing from another web.xml (solr's), I added this to my web.xml:
>> >
>> >   <resource-env-ref>
>> >     <description>
>> >       Link to the UserDatabase instance from which we request lists of
>> >       defined role names.  Typically, this will be connected to the
>> global
>> >       user database with a ResourceLink element in server.xml or the
>> context
>> >       configuration file for the Manager web application.
>> >     </description>
>> >     <resource-env-ref-name>users</resource-env-ref-name>
>> >     <resource-env-ref-type>
>> >       org.apache.catalina.UserDatabase
>> >     </resource-env-ref-type>
>> >   </resource-env-ref>
>> >
>> >   <security-constraint>
>> >     <web-resource-collection>
>> >       <web-resource-name>Monitor</web-resource-name>
>> >       <url-pattern>/Monitor/*</url-pattern>
>> >       <http-method>GET</http-method>
>> >       <http-method>POST</http-method>
>> >     </web-resource-collection>
>> >     <auth-constraint>
>> >       <role-name>admin</role-name>
>> >     </auth-constraint>
>> >   </security-constraint>
>> >
>> >   <!-- Define the Login Configuration for this Application -->
>> >   <login-config>
>> >     <auth-method>BASIC</auth-method>
>> >     <realm>UserDatabase</realm>
>> >   </login-config>
>> >
>> >   <security-role>
>> >    <role-name>admin</role-name>
>> >   </security-role>
>> >
>> > But I'm still getting through without having to authenticate.  Is there
>> > something that I'm missing, or am I going about this all wrong?
>>
>> If 'Monitor' is the name of your Context/webapp, the above means:
>>
>>  /Monitor/Monitor/*
>>
>> Try:
>>
>>  <url-pattern>/*</url-pattern>
>>
>> instead.
>>
>>
>> p
>>
>> >
>> > Thanks!
>> >
>> > -- Chris
>> >
>> >
>> > On Mon, Jan 10, 2011 at 1:45 PM, Mark Thomas <ma...@apache.org> wrote:
>> >
>> >> On 10/01/2011 18:43, Christopher Gross wrote:
>> >>> I added the security role:
>> >>>         MemoryRealm mr = new MemoryRealm();
>> >>>         mr.setPathname(path + "/conf/tomcat-users.xml");
>> >>>         Context sp = embedded.createContext("/Monitor", path +
>> >>> "/webapps/monitor");
>> >>>         sp.setRealm(mr);
>> >>>         sp.addSecurityRole("admin");
>> >>>         host.addChild(sp);
>> >>>
>> >>> Is there anything else that I need to do for the Context?
>> >>
>> >> You need to set up some security constraints in web.xml
>> >>
>> >> Mark
>> >>
>> >>>
>> >>> -- Chris
>> >>>
>> >>>
>> >>> On Mon, Jan 10, 2011 at 1:37 PM, Mark Thomas <ma...@apache.org>
>> wrote:
>> >>>
>> >>>> On 10/01/2011 18:16, Christopher Gross wrote:
>> >>>>> I created a MemoryRealm object, pointed it to my tomcat-users.xml
>> file,
>> >>>>> added that realm to the embedded (no luck) and to the specific
>> context
>> >>>> (no
>> >>>>> luck either).  For both, it just plain loads the page -- doesn't ask
>> me
>> >>>> to
>> >>>>> do any type of logging in.
>> >>>>>
>> >>>>> Are you just using your own experience to help me, or are you aware
>> of
>> >>>> any
>> >>>>> documentation that I could peruse, instead of lobbing questions at
>> you
>> >> a
>> >>>> few
>> >>>>> times a day? :)
>> >>>>
>> >>>> Have you configured your app to require authentication? IF not the
>> realm
>> >>>> will never be used.
>> >>>>
>> >>>> Mark
>> >>>>
>> >>>>>
>> >>>>> -- Chris
>> >>>>>
>> >>>>>
>> >>>>> On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
>> >>>>>
>> >>>>>> Can you not create a org.apache.catalina.realms.MemoryRealm and set
>> >> the
>> >>>>>> path to the xml file?
>> >>>>>>
>> >>>>>>
>> >>>>>> p
>> >>>>>>
>> >>>>>>
>> >>>>>
>> >>>>
>> >>>>
>> >>>> ---------------------------------------------------------------------
>> >>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >>>> For additional commands, e-mail: users-help@tomcat.apache.org
>> >>>>
>> >>>>
>> >>>
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> >> For additional commands, e-mail: users-help@tomcat.apache.org
>> >>
>> >>
>> >
>>
>>
>

Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
That did it!  Thanks Mark & Pid.

Now to make it more complicated -- in order to have another page without
that restriction, would I need to make a whole new webapp, or can I turn
down the security for a specific page?

Thanks!

-- Chris


On Mon, Jan 10, 2011 at 2:18 PM, Pid <pi...@pidster.com> wrote:

> On 1/10/11 6:58 PM, Christopher Gross wrote:
> > Borrowing from another web.xml (solr's), I added this to my web.xml:
> >
> >   <resource-env-ref>
> >     <description>
> >       Link to the UserDatabase instance from which we request lists of
> >       defined role names.  Typically, this will be connected to the
> global
> >       user database with a ResourceLink element in server.xml or the
> context
> >       configuration file for the Manager web application.
> >     </description>
> >     <resource-env-ref-name>users</resource-env-ref-name>
> >     <resource-env-ref-type>
> >       org.apache.catalina.UserDatabase
> >     </resource-env-ref-type>
> >   </resource-env-ref>
> >
> >   <security-constraint>
> >     <web-resource-collection>
> >       <web-resource-name>Monitor</web-resource-name>
> >       <url-pattern>/Monitor/*</url-pattern>
> >       <http-method>GET</http-method>
> >       <http-method>POST</http-method>
> >     </web-resource-collection>
> >     <auth-constraint>
> >       <role-name>admin</role-name>
> >     </auth-constraint>
> >   </security-constraint>
> >
> >   <!-- Define the Login Configuration for this Application -->
> >   <login-config>
> >     <auth-method>BASIC</auth-method>
> >     <realm>UserDatabase</realm>
> >   </login-config>
> >
> >   <security-role>
> >    <role-name>admin</role-name>
> >   </security-role>
> >
> > But I'm still getting through without having to authenticate.  Is there
> > something that I'm missing, or am I going about this all wrong?
>
> If 'Monitor' is the name of your Context/webapp, the above means:
>
>  /Monitor/Monitor/*
>
> Try:
>
>  <url-pattern>/*</url-pattern>
>
> instead.
>
>
> p
>
> >
> > Thanks!
> >
> > -- Chris
> >
> >
> > On Mon, Jan 10, 2011 at 1:45 PM, Mark Thomas <ma...@apache.org> wrote:
> >
> >> On 10/01/2011 18:43, Christopher Gross wrote:
> >>> I added the security role:
> >>>         MemoryRealm mr = new MemoryRealm();
> >>>         mr.setPathname(path + "/conf/tomcat-users.xml");
> >>>         Context sp = embedded.createContext("/Monitor", path +
> >>> "/webapps/monitor");
> >>>         sp.setRealm(mr);
> >>>         sp.addSecurityRole("admin");
> >>>         host.addChild(sp);
> >>>
> >>> Is there anything else that I need to do for the Context?
> >>
> >> You need to set up some security constraints in web.xml
> >>
> >> Mark
> >>
> >>>
> >>> -- Chris
> >>>
> >>>
> >>> On Mon, Jan 10, 2011 at 1:37 PM, Mark Thomas <ma...@apache.org> wrote:
> >>>
> >>>> On 10/01/2011 18:16, Christopher Gross wrote:
> >>>>> I created a MemoryRealm object, pointed it to my tomcat-users.xml
> file,
> >>>>> added that realm to the embedded (no luck) and to the specific
> context
> >>>> (no
> >>>>> luck either).  For both, it just plain loads the page -- doesn't ask
> me
> >>>> to
> >>>>> do any type of logging in.
> >>>>>
> >>>>> Are you just using your own experience to help me, or are you aware
> of
> >>>> any
> >>>>> documentation that I could peruse, instead of lobbing questions at
> you
> >> a
> >>>> few
> >>>>> times a day? :)
> >>>>
> >>>> Have you configured your app to require authentication? IF not the
> realm
> >>>> will never be used.
> >>>>
> >>>> Mark
> >>>>
> >>>>>
> >>>>> -- Chris
> >>>>>
> >>>>>
> >>>>> On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
> >>>>>
> >>>>>> Can you not create a org.apache.catalina.realms.MemoryRealm and set
> >> the
> >>>>>> path to the xml file?
> >>>>>>
> >>>>>>
> >>>>>> p
> >>>>>>
> >>>>>>
> >>>>>
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>>> For additional commands, e-mail: users-help@tomcat.apache.org
> >>>>
> >>>>
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
>

Re: Configuring Embedded Tomcat

Posted by Pid <pi...@pidster.com>.
On 1/10/11 6:58 PM, Christopher Gross wrote:
> Borrowing from another web.xml (solr's), I added this to my web.xml:
> 
>   <resource-env-ref>
>     <description>
>       Link to the UserDatabase instance from which we request lists of
>       defined role names.  Typically, this will be connected to the global
>       user database with a ResourceLink element in server.xml or the context
>       configuration file for the Manager web application.
>     </description>
>     <resource-env-ref-name>users</resource-env-ref-name>
>     <resource-env-ref-type>
>       org.apache.catalina.UserDatabase
>     </resource-env-ref-type>
>   </resource-env-ref>
> 
>   <security-constraint>
>     <web-resource-collection>
>       <web-resource-name>Monitor</web-resource-name>
>       <url-pattern>/Monitor/*</url-pattern>
>       <http-method>GET</http-method>
>       <http-method>POST</http-method>
>     </web-resource-collection>
>     <auth-constraint>
>       <role-name>admin</role-name>
>     </auth-constraint>
>   </security-constraint>
> 
>   <!-- Define the Login Configuration for this Application -->
>   <login-config>
>     <auth-method>BASIC</auth-method>
>     <realm>UserDatabase</realm>
>   </login-config>
> 
>   <security-role>
>    <role-name>admin</role-name>
>   </security-role>
> 
> But I'm still getting through without having to authenticate.  Is there
> something that I'm missing, or am I going about this all wrong?

If 'Monitor' is the name of your Context/webapp, the above means:

 /Monitor/Monitor/*

Try:

 <url-pattern>/*</url-pattern>

instead.


p

> 
> Thanks!
> 
> -- Chris
> 
> 
> On Mon, Jan 10, 2011 at 1:45 PM, Mark Thomas <ma...@apache.org> wrote:
> 
>> On 10/01/2011 18:43, Christopher Gross wrote:
>>> I added the security role:
>>>         MemoryRealm mr = new MemoryRealm();
>>>         mr.setPathname(path + "/conf/tomcat-users.xml");
>>>         Context sp = embedded.createContext("/Monitor", path +
>>> "/webapps/monitor");
>>>         sp.setRealm(mr);
>>>         sp.addSecurityRole("admin");
>>>         host.addChild(sp);
>>>
>>> Is there anything else that I need to do for the Context?
>>
>> You need to set up some security constraints in web.xml
>>
>> Mark
>>
>>>
>>> -- Chris
>>>
>>>
>>> On Mon, Jan 10, 2011 at 1:37 PM, Mark Thomas <ma...@apache.org> wrote:
>>>
>>>> On 10/01/2011 18:16, Christopher Gross wrote:
>>>>> I created a MemoryRealm object, pointed it to my tomcat-users.xml file,
>>>>> added that realm to the embedded (no luck) and to the specific context
>>>> (no
>>>>> luck either).  For both, it just plain loads the page -- doesn't ask me
>>>> to
>>>>> do any type of logging in.
>>>>>
>>>>> Are you just using your own experience to help me, or are you aware of
>>>> any
>>>>> documentation that I could peruse, instead of lobbing questions at you
>> a
>>>> few
>>>>> times a day? :)
>>>>
>>>> Have you configured your app to require authentication? IF not the realm
>>>> will never be used.
>>>>
>>>> Mark
>>>>
>>>>>
>>>>> -- Chris
>>>>>
>>>>>
>>>>> On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
>>>>>
>>>>>> Can you not create a org.apache.catalina.realms.MemoryRealm and set
>> the
>>>>>> path to the xml file?
>>>>>>
>>>>>>
>>>>>> p
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 


Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
Borrowing from another web.xml (solr's), I added this to my web.xml:

  <resource-env-ref>
    <description>
      Link to the UserDatabase instance from which we request lists of
      defined role names.  Typically, this will be connected to the global
      user database with a ResourceLink element in server.xml or the context
      configuration file for the Manager web application.
    </description>
    <resource-env-ref-name>users</resource-env-ref-name>
    <resource-env-ref-type>
      org.apache.catalina.UserDatabase
    </resource-env-ref-type>
  </resource-env-ref>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Monitor</web-resource-name>
      <url-pattern>/Monitor/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- Define the Login Configuration for this Application -->
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm>UserDatabase</realm>
  </login-config>

  <security-role>
   <role-name>admin</role-name>
  </security-role>

But I'm still getting through without having to authenticate.  Is there
something that I'm missing, or am I going about this all wrong?

Thanks!

-- Chris


On Mon, Jan 10, 2011 at 1:45 PM, Mark Thomas <ma...@apache.org> wrote:

> On 10/01/2011 18:43, Christopher Gross wrote:
> > I added the security role:
> >         MemoryRealm mr = new MemoryRealm();
> >         mr.setPathname(path + "/conf/tomcat-users.xml");
> >         Context sp = embedded.createContext("/Monitor", path +
> > "/webapps/monitor");
> >         sp.setRealm(mr);
> >         sp.addSecurityRole("admin");
> >         host.addChild(sp);
> >
> > Is there anything else that I need to do for the Context?
>
> You need to set up some security constraints in web.xml
>
> Mark
>
> >
> > -- Chris
> >
> >
> > On Mon, Jan 10, 2011 at 1:37 PM, Mark Thomas <ma...@apache.org> wrote:
> >
> >> On 10/01/2011 18:16, Christopher Gross wrote:
> >>> I created a MemoryRealm object, pointed it to my tomcat-users.xml file,
> >>> added that realm to the embedded (no luck) and to the specific context
> >> (no
> >>> luck either).  For both, it just plain loads the page -- doesn't ask me
> >> to
> >>> do any type of logging in.
> >>>
> >>> Are you just using your own experience to help me, or are you aware of
> >> any
> >>> documentation that I could peruse, instead of lobbing questions at you
> a
> >> few
> >>> times a day? :)
> >>
> >> Have you configured your app to require authentication? IF not the realm
> >> will never be used.
> >>
> >> Mark
> >>
> >>>
> >>> -- Chris
> >>>
> >>>
> >>> On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
> >>>
> >>>> Can you not create a org.apache.catalina.realms.MemoryRealm and set
> the
> >>>> path to the xml file?
> >>>>
> >>>>
> >>>> p
> >>>>
> >>>>
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Configuring Embedded Tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 10/01/2011 18:43, Christopher Gross wrote:
> I added the security role:
>         MemoryRealm mr = new MemoryRealm();
>         mr.setPathname(path + "/conf/tomcat-users.xml");
>         Context sp = embedded.createContext("/Monitor", path +
> "/webapps/monitor");
>         sp.setRealm(mr);
>         sp.addSecurityRole("admin");
>         host.addChild(sp);
> 
> Is there anything else that I need to do for the Context?

You need to set up some security constraints in web.xml

Mark

> 
> -- Chris
> 
> 
> On Mon, Jan 10, 2011 at 1:37 PM, Mark Thomas <ma...@apache.org> wrote:
> 
>> On 10/01/2011 18:16, Christopher Gross wrote:
>>> I created a MemoryRealm object, pointed it to my tomcat-users.xml file,
>>> added that realm to the embedded (no luck) and to the specific context
>> (no
>>> luck either).  For both, it just plain loads the page -- doesn't ask me
>> to
>>> do any type of logging in.
>>>
>>> Are you just using your own experience to help me, or are you aware of
>> any
>>> documentation that I could peruse, instead of lobbing questions at you a
>> few
>>> times a day? :)
>>
>> Have you configured your app to require authentication? IF not the realm
>> will never be used.
>>
>> Mark
>>
>>>
>>> -- Chris
>>>
>>>
>>> On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
>>>
>>>> Can you not create a org.apache.catalina.realms.MemoryRealm and set the
>>>> path to the xml file?
>>>>
>>>>
>>>> p
>>>>
>>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
I added the security role:
        MemoryRealm mr = new MemoryRealm();
        mr.setPathname(path + "/conf/tomcat-users.xml");
        Context sp = embedded.createContext("/Monitor", path +
"/webapps/monitor");
        sp.setRealm(mr);
        sp.addSecurityRole("admin");
        host.addChild(sp);

Is there anything else that I need to do for the Context?

-- Chris


On Mon, Jan 10, 2011 at 1:37 PM, Mark Thomas <ma...@apache.org> wrote:

> On 10/01/2011 18:16, Christopher Gross wrote:
> > I created a MemoryRealm object, pointed it to my tomcat-users.xml file,
> > added that realm to the embedded (no luck) and to the specific context
> (no
> > luck either).  For both, it just plain loads the page -- doesn't ask me
> to
> > do any type of logging in.
> >
> > Are you just using your own experience to help me, or are you aware of
> any
> > documentation that I could peruse, instead of lobbing questions at you a
> few
> > times a day? :)
>
> Have you configured your app to require authentication? IF not the realm
> will never be used.
>
> Mark
>
> >
> > -- Chris
> >
> >
> > On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
> >
> >> Can you not create a org.apache.catalina.realms.MemoryRealm and set the
> >> path to the xml file?
> >>
> >>
> >> p
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Configuring Embedded Tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 10/01/2011 18:16, Christopher Gross wrote:
> I created a MemoryRealm object, pointed it to my tomcat-users.xml file,
> added that realm to the embedded (no luck) and to the specific context (no
> luck either).  For both, it just plain loads the page -- doesn't ask me to
> do any type of logging in.
> 
> Are you just using your own experience to help me, or are you aware of any
> documentation that I could peruse, instead of lobbing questions at you a few
> times a day? :)

Have you configured your app to require authentication? IF not the realm
will never be used.

Mark

> 
> -- Chris
> 
> 
> On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:
> 
>> Can you not create a org.apache.catalina.realms.MemoryRealm and set the
>> path to the xml file?
>>
>>
>> p
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
I created a MemoryRealm object, pointed it to my tomcat-users.xml file,
added that realm to the embedded (no luck) and to the specific context (no
luck either).  For both, it just plain loads the page -- doesn't ask me to
do any type of logging in.

Are you just using your own experience to help me, or are you aware of any
documentation that I could peruse, instead of lobbing questions at you a few
times a day? :)

-- Chris


On Mon, Jan 10, 2011 at 12:48 PM, Pid <pi...@pidster.com> wrote:

> Can you not create a org.apache.catalina.realms.MemoryRealm and set the
> path to the xml file?
>
>
> p
>
>

Re: Configuring Embedded Tomcat

Posted by Pid <pi...@pidster.com>.
On 1/10/11 5:33 PM, Christopher Gross wrote:
> The Realm class is "read only" (according to the API).  There isn't a way
> for me to set the path to the tomcat-users.xml file (or anything else for
> that matter).
> 
> I'm not seeing a function in the Engine/Embedded/Context object to have it
> load the tomcat-users.xml file either (though the context does let me add a
> security role, though it doesn't seem to really do anything at this point).
> 
> I'm attempting to go through the actual Tomcat code to see if I can look at
> the code that it uses to get everything started up so that I can build from
> that.  I'm out of other ideas and things to try.
> 
> -- Chris
> 
> 
> On Mon, Jan 10, 2011 at 12:22 PM, Pid <pi...@pidster.com> wrote:
> 
>> On 1/10/11 2:28 PM, Christopher Gross wrote:
>>> It is specified there -- but I don't have a server.xml file set up.
>>  Since
>>> I'm using the embedded version, I set up the tomcat on the fly and just
>> have
>>> the java code start it.
>>
>> What's stopping you from programmatically creating the Realm and adding
>> it to the Host?

Can you not create a org.apache.catalina.realms.MemoryRealm and set the
path to the xml file?


p

>> p
>>
>>
>>> I looked at the server.xml file that comes with the standard tomcat
>>> installation, and I see the the UserDatabaseRealm portion.  Can I put
>> that
>>> into the web.xml file?  Or is there a way for me to enter that into the
>>> embedded module?
>>>
>>> I'm not sure on what to do here.  Right now it "works", but I'm trying to
>>> get it so that I can have 2 different users and have them see 2 different
>>> web apps.  I don't often do sys admin/configuration stuff, I'd rather be
>>> coding (but I'm waiting for other people to finish up their portions, so
>> I'm
>>> adding in other niceties that I can get done before I can move on to the
>>> next big part.)
>>
>>
> 


Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
The Realm class is "read only" (according to the API).  There isn't a way
for me to set the path to the tomcat-users.xml file (or anything else for
that matter).

I'm not seeing a function in the Engine/Embedded/Context object to have it
load the tomcat-users.xml file either (though the context does let me add a
security role, though it doesn't seem to really do anything at this point).

I'm attempting to go through the actual Tomcat code to see if I can look at
the code that it uses to get everything started up so that I can build from
that.  I'm out of other ideas and things to try.

-- Chris


On Mon, Jan 10, 2011 at 12:22 PM, Pid <pi...@pidster.com> wrote:

> On 1/10/11 2:28 PM, Christopher Gross wrote:
> > It is specified there -- but I don't have a server.xml file set up.
>  Since
> > I'm using the embedded version, I set up the tomcat on the fly and just
> have
> > the java code start it.
>
> What's stopping you from programmatically creating the Realm and adding
> it to the Host?
>
>
> p
>
>
> > I looked at the server.xml file that comes with the standard tomcat
> > installation, and I see the the UserDatabaseRealm portion.  Can I put
> that
> > into the web.xml file?  Or is there a way for me to enter that into the
> > embedded module?
> >
> > I'm not sure on what to do here.  Right now it "works", but I'm trying to
> > get it so that I can have 2 different users and have them see 2 different
> > web apps.  I don't often do sys admin/configuration stuff, I'd rather be
> > coding (but I'm waiting for other people to finish up their portions, so
> I'm
> > adding in other niceties that I can get done before I can move on to the
> > next big part.)
>
>

Re: Configuring Embedded Tomcat

Posted by Pid <pi...@pidster.com>.
On 1/10/11 2:28 PM, Christopher Gross wrote:
> It is specified there -- but I don't have a server.xml file set up.  Since
> I'm using the embedded version, I set up the tomcat on the fly and just have
> the java code start it.

What's stopping you from programmatically creating the Realm and adding
it to the Host?


p


> I looked at the server.xml file that comes with the standard tomcat
> installation, and I see the the UserDatabaseRealm portion.  Can I put that
> into the web.xml file?  Or is there a way for me to enter that into the
> embedded module?
> 
> I'm not sure on what to do here.  Right now it "works", but I'm trying to
> get it so that I can have 2 different users and have them see 2 different
> web apps.  I don't often do sys admin/configuration stuff, I'd rather be
> coding (but I'm waiting for other people to finish up their portions, so I'm
> adding in other niceties that I can get done before I can move on to the
> next big part.)


Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
It is specified there -- but I don't have a server.xml file set up.  Since
I'm using the embedded version, I set up the tomcat on the fly and just have
the java code start it.

I looked at the server.xml file that comes with the standard tomcat
installation, and I see the the UserDatabaseRealm portion.  Can I put that
into the web.xml file?  Or is there a way for me to enter that into the
embedded module?

I'm not sure on what to do here.  Right now it "works", but I'm trying to
get it so that I can have 2 different users and have them see 2 different
web apps.  I don't often do sys admin/configuration stuff, I'd rather be
coding (but I'm waiting for other people to finish up their portions, so I'm
adding in other niceties that I can get done before I can move on to the
next big part.)

I appreciate your help!

Thanks!

-- Chris


On Fri, Jan 7, 2011 at 5:43 PM, Pid <pi...@pidster.com> wrote:

> On 1/7/11 9:07 PM, Christopher Gross wrote:
> > OK, so I'd need to add a Realm for the UserDatabaseRealm in either of the
> > spots you listed.  I'll probably use the file, so that I can adjust it if
> > need be.
> >
> > Where do I put the tomcat-users.xml file, so that the Realm has
> > users/passwords?  Is there a way for me to tell the Embedded object where
> it
> > is, or will it look in a certain spot by default?
>
> The file location is specified in a property of the Realm, no?
>
>
> p
>
> > Thanks!
> >
> > -- Chris
> >
> >
> > On Fri, Jan 7, 2011 at 3:55 PM, Pid <pi...@pidster.com> wrote:
> >
> >> On 1/7/11 6:59 PM, Christopher Gross wrote:
> >>> I've been looking around, but I can't seem to find somewhere that shows
> >> how
> >>> you can configure Tomcat when you embed it into an application.
> >>>
> >>> My code is like this:
> >>>
> >>> public void start() throws Exception {
> >>>    String hostname = System.getProperty("hostname");
> >>>    int port = Integer.parseInt(System.getProperty("port"));
> >>>    String path = System.getProperty("path");
> >>>    Embedded embedded = new Embedded();
> >>>    Engine engine = embedded.createEngine();
> >>>    engine.setName("Monitor");
> >>>    engine.setHostname(hostname);
> >>>    Host host = embedded.createHost(hostname, path);
> >>>    engine.addChild(host);
> >>>    Context sp = embedded.createContext("/Monitor", path +
> >>> "/webapps/monitor");
> >>>    host.addChild(sp);
> >>>    embedded.addEngine(engine);
> >>>    InetAddress addr = null;
> >>>    Connector connector = embedded.createConnector(addr, port, false);
> >>>    embedded.addConnector(connector);
> >>>    embedded.setName("WebServerThread");
> >>>    embedded.start();
> >>> }
> >>>
> >>> It works fine as it is now, but I'd like to use Tomcat to authenticate
> >>> users.  I'll make a separate app for basic users to use to just view a
> >> page,
> >>> but give admins access to a more advanced page (the pages that I have
> >> now).
> >>>  Should I be using a different module?  Is there a spot where the
> >> embedded
> >>> Tomcat will look by default?
> >>
> >> Container managed authentication & authorization is dependent on config
> >> in web.xml, part of the application.
> >>
> >> Tomcat needs a Realm against which users are configured.  Add a Realm to
> >> the webapp/META-INF/context.xml or as a child of the Host.
> >>
> >>
> >> p
> >>
> >>> Any tips would be greatly appreciated.
> >>>
> >>> Thanks!
> >>>
> >>> -- Chris
> >>>
> >>
> >>
> >
>
>

Re: Configuring Embedded Tomcat

Posted by Pid <pi...@pidster.com>.
On 1/7/11 9:07 PM, Christopher Gross wrote:
> OK, so I'd need to add a Realm for the UserDatabaseRealm in either of the
> spots you listed.  I'll probably use the file, so that I can adjust it if
> need be.
> 
> Where do I put the tomcat-users.xml file, so that the Realm has
> users/passwords?  Is there a way for me to tell the Embedded object where it
> is, or will it look in a certain spot by default?

The file location is specified in a property of the Realm, no?


p

> Thanks!
> 
> -- Chris
> 
> 
> On Fri, Jan 7, 2011 at 3:55 PM, Pid <pi...@pidster.com> wrote:
> 
>> On 1/7/11 6:59 PM, Christopher Gross wrote:
>>> I've been looking around, but I can't seem to find somewhere that shows
>> how
>>> you can configure Tomcat when you embed it into an application.
>>>
>>> My code is like this:
>>>
>>> public void start() throws Exception {
>>>    String hostname = System.getProperty("hostname");
>>>    int port = Integer.parseInt(System.getProperty("port"));
>>>    String path = System.getProperty("path");
>>>    Embedded embedded = new Embedded();
>>>    Engine engine = embedded.createEngine();
>>>    engine.setName("Monitor");
>>>    engine.setHostname(hostname);
>>>    Host host = embedded.createHost(hostname, path);
>>>    engine.addChild(host);
>>>    Context sp = embedded.createContext("/Monitor", path +
>>> "/webapps/monitor");
>>>    host.addChild(sp);
>>>    embedded.addEngine(engine);
>>>    InetAddress addr = null;
>>>    Connector connector = embedded.createConnector(addr, port, false);
>>>    embedded.addConnector(connector);
>>>    embedded.setName("WebServerThread");
>>>    embedded.start();
>>> }
>>>
>>> It works fine as it is now, but I'd like to use Tomcat to authenticate
>>> users.  I'll make a separate app for basic users to use to just view a
>> page,
>>> but give admins access to a more advanced page (the pages that I have
>> now).
>>>  Should I be using a different module?  Is there a spot where the
>> embedded
>>> Tomcat will look by default?
>>
>> Container managed authentication & authorization is dependent on config
>> in web.xml, part of the application.
>>
>> Tomcat needs a Realm against which users are configured.  Add a Realm to
>> the webapp/META-INF/context.xml or as a child of the Host.
>>
>>
>> p
>>
>>> Any tips would be greatly appreciated.
>>>
>>> Thanks!
>>>
>>> -- Chris
>>>
>>
>>
> 


Re: Configuring Embedded Tomcat

Posted by Christopher Gross <co...@gmail.com>.
OK, so I'd need to add a Realm for the UserDatabaseRealm in either of the
spots you listed.  I'll probably use the file, so that I can adjust it if
need be.

Where do I put the tomcat-users.xml file, so that the Realm has
users/passwords?  Is there a way for me to tell the Embedded object where it
is, or will it look in a certain spot by default?

Thanks!

-- Chris


On Fri, Jan 7, 2011 at 3:55 PM, Pid <pi...@pidster.com> wrote:

> On 1/7/11 6:59 PM, Christopher Gross wrote:
> > I've been looking around, but I can't seem to find somewhere that shows
> how
> > you can configure Tomcat when you embed it into an application.
> >
> > My code is like this:
> >
> > public void start() throws Exception {
> >    String hostname = System.getProperty("hostname");
> >    int port = Integer.parseInt(System.getProperty("port"));
> >    String path = System.getProperty("path");
> >    Embedded embedded = new Embedded();
> >    Engine engine = embedded.createEngine();
> >    engine.setName("Monitor");
> >    engine.setHostname(hostname);
> >    Host host = embedded.createHost(hostname, path);
> >    engine.addChild(host);
> >    Context sp = embedded.createContext("/Monitor", path +
> > "/webapps/monitor");
> >    host.addChild(sp);
> >    embedded.addEngine(engine);
> >    InetAddress addr = null;
> >    Connector connector = embedded.createConnector(addr, port, false);
> >    embedded.addConnector(connector);
> >    embedded.setName("WebServerThread");
> >    embedded.start();
> > }
> >
> > It works fine as it is now, but I'd like to use Tomcat to authenticate
> > users.  I'll make a separate app for basic users to use to just view a
> page,
> > but give admins access to a more advanced page (the pages that I have
> now).
> >  Should I be using a different module?  Is there a spot where the
> embedded
> > Tomcat will look by default?
>
> Container managed authentication & authorization is dependent on config
> in web.xml, part of the application.
>
> Tomcat needs a Realm against which users are configured.  Add a Realm to
> the webapp/META-INF/context.xml or as a child of the Host.
>
>
> p
>
> > Any tips would be greatly appreciated.
> >
> > Thanks!
> >
> > -- Chris
> >
>
>

Re: Configuring Embedded Tomcat

Posted by Pid <pi...@pidster.com>.
On 1/7/11 6:59 PM, Christopher Gross wrote:
> I've been looking around, but I can't seem to find somewhere that shows how
> you can configure Tomcat when you embed it into an application.
> 
> My code is like this:
> 
> public void start() throws Exception {
>    String hostname = System.getProperty("hostname");
>    int port = Integer.parseInt(System.getProperty("port"));
>    String path = System.getProperty("path");
>    Embedded embedded = new Embedded();
>    Engine engine = embedded.createEngine();
>    engine.setName("Monitor");
>    engine.setHostname(hostname);
>    Host host = embedded.createHost(hostname, path);
>    engine.addChild(host);
>    Context sp = embedded.createContext("/Monitor", path +
> "/webapps/monitor");
>    host.addChild(sp);
>    embedded.addEngine(engine);
>    InetAddress addr = null;
>    Connector connector = embedded.createConnector(addr, port, false);
>    embedded.addConnector(connector);
>    embedded.setName("WebServerThread");
>    embedded.start();
> }
> 
> It works fine as it is now, but I'd like to use Tomcat to authenticate
> users.  I'll make a separate app for basic users to use to just view a page,
> but give admins access to a more advanced page (the pages that I have now).
>  Should I be using a different module?  Is there a spot where the embedded
> Tomcat will look by default?

Container managed authentication & authorization is dependent on config
in web.xml, part of the application.

Tomcat needs a Realm against which users are configured.  Add a Realm to
the webapp/META-INF/context.xml or as a child of the Host.


p

> Any tips would be greatly appreciated.
> 
> Thanks!
> 
> -- Chris
>