You should also be able to define the constraint handler bean outside of the jetty handler and then define it via a ref in the jetty engine. You will need to define a jetty engine per port i think but at least you should be able to reuse the constraint handler bean def. On Oct 14, 2012 7:55 AM, <[email protected]> wrote:
> You can define a property for the port and then load that from properties > using property placeholder configurer in spring. > > http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/ > > > http://static.springsource.org/spring/docs/3.1.0.RELEASE/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html > On Oct 14, 2012 3:15 AM, "Juan José Pérez Consuegra" <[email protected]> > wrote: > >> I think i've found the error, is that in my config file I established port >> number = "0", becouse I want to aply security rule to any port number, and >> it doesn't. How can I set port number dynamically as in the example?? >> >> 2012/10/12 Freeman Fang <[email protected]> >> >> > Hi, >> > >> > We have a system test which demonstrate how to enable jetty basic auth, >> it >> > should be a good start for you. From this link[1] you can find all >> > material, the test code, the configuration files, it's very similar as >> what >> > you want to do. >> > >> > [1]http://svn.apache.org/viewvc?view=revision&revision=1075784 >> > ------------- >> > Freeman Fang >> > >> > Red Hat, Inc. >> > FuseSource is now part of Red Hat >> > Web: http://fusesource.com | http://www.redhat.com/ >> > Twitter: freemanfang >> > Blog: http://freemanfang.blogspot.com >> > http://blog.sina.com.cn/u/1473905042 >> > weibo: http://weibo.com/u/1473905042 >> > >> > On 2012-10-12, at 上午5:05, Juan José Pérez Consuegra wrote: >> > >> > > I'm trying to use Jetty security loading configuration from xml config >> > > file. The file loads without any error but policies seems not to >> work. I >> > > thought to load configuration via code, but I'm using >> > > JAXRSServerFactoryBean and it seems also not to be possible. Here it >> is >> > mi >> > > config file: >> > > >> > > <beans xmlns="http://www.springframework.org/schema/beans" >> > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> > > xmlns:httpj=" >> > > http://cxf.apache.org/transports/http-jetty/configuration" >> > > xsi:schemaLocation=" >> > > http://cxf.apache.org/transports/http-jetty/configuration >> > > http://cxf.apache.org/schemas/configuration/http-jetty.xsd >> > > http://www.springframework.org/schema/beans >> > > http://www.springframework.org/schema/beans/spring-beans.xsd"> >> > > >> > > <httpj:engine-factory bus="cxf"> >> > > <httpj:engine port="0"> >> > > <httpj:threadingParameters minThreads="5" >> > > maxThreads="15" /> >> > > <httpj:handlers> >> > > <bean >> > > class="org.eclipse.jetty.security.ConstraintSecurityHandler"> >> > > <property name="loginService" >> > > ref="securityLoginService" /> >> > > <property name="constraintMappings"> >> > > <list> >> > > <ref bean="securityConstraintMapping" /> >> > > </list> >> > > </property> >> > > </bean> >> > > </httpj:handlers> >> > > </httpj:engine> >> > > </httpj:engine-factory> >> > > >> > > <bean id="securityLoginService" >> > > class="org.eclipse.jetty.security.HashLoginService"> >> > > <property name="name" value="WSRealm" /> >> > > <property name="config" >> > > >> > >> value="src/es/uned/scc/related/cserver/ws/configuration/jetty-realm.properties" >> > > /> >> > > </bean> >> > > >> > > <bean id="securityConstraint" >> > > class="org.eclipse.jetty.http.security.Constraint"> >> > > <property name="name" value="BASIC" /> >> > > <property name="roles" value="admin" /> >> > > <property name="authenticate" value="true" /> >> > > </bean> >> > > >> > > <bean id="securityConstraintMapping" >> > > class="org.eclipse.jetty.security.ConstraintMapping"> >> > > <property name="constraint" ref="securityConstraint" /> >> > > <property name="pathSpec" value="/*" /> >> > > </bean> >> > > </beans> >> > > >> > > >> > > jetty-realm.properties >> > > # Defines users that can access the web (console, demo, etc.) >> > > # username: password [,rolename ...] >> > > ffang: pswd, admin >> > > >> > > And the code that creates the server: >> > > >> > > static{ >> > > // set the configuration file >> > > SpringBusFactory factory = new SpringBusFactory(); >> > > Bus bus = >> > > >> > >> factory.createBus("src/es/uned/scc/related/cserver/ws/configuration/server-sec-bean.xml"); >> > > BusFactory.setDefaultBus(bus); >> > > } >> > > >> > > .... >> > > .... >> > > .... >> > > ..... >> > > >> > > public void start() throws Exception{ >> > > if (sf == null){ >> > > sf = new JAXRSServerFactoryBean(); >> > > sf.setResourceClasses(RLABSystemWSRest.class); >> > > sf.setResourceProvider(RLABSystemWSRest.class, >> > > new SingletonResourceProvider(new RLABSystemWSRest())); >> > > sf.setAddress(address); >> > > >> > > >> > > server = sf.create(); >> > > >> > > System.out.println("Servidor arrancado y servicio >> > > publicado..."); >> > > } else { >> > > if (server.isStarted()) { >> > > System.out.println("Servidor ya estaba arrancado y el >> servicio >> > > publicado..."); >> > > }else{ >> > > server.start(); >> > > System.out.println("Servidor arrancado y servicio >> > > publicado..."); >> > > } >> > > } >> > > } >> > > >> > > >> > > As I said before, the config file loads perfectly, at least >> apparently, >> > but >> > > if I try to call any operation defined as service without any >> > credential, I >> > > receive server status 200 OK, and the correct response of course. >> > > >> > > Any idea. >> > > >> > > Thank to everybody, >> > > >> > > Juanjo. >> > >> > >> >
