Wednesday, April 25, 2012

Add basic authendication for Jetty

1. In web.xml, it needs to add this
 
 
  
   api
   /*
  
  
   api
  
 
This config indicates that all resources need ROLE api to access.

2. In the jetty folder, find start.ini and make sure the line like this is not commented. Of course to make this realm config right.
etc/jetty-example.xml
3. Go into your etc/jetty-example.xml to make the xml similar like this

    
      
        
          hw xxx Realm
          /etc/realm.properties
          0
        
      
    

4. Go into your etc/realm.properties file to set up realm configuration.

Also these two links are very helpful.
http://docs.codehaus.org/display/JETTY/Realms
http://docs.codehaus.org/display/JETTY/JAAS Recently I found another problem with realm with jetty 8.1.7. When setup as above, the browser does not popup the authentication window but keep reporting error "This web page has a redirect loop" by Chrome. After a struggling by comparing the jetty xml files I found the issue was caused by this section in contenxts/test.xml

      
        true
      

Just comment out this section, the issue was solved.

Quit ssh with out killing running process

Since I need to keep start.jar of jetty running on EC2. I need to quit the ssh without killing the current running jetty process. There is a tool called "screen" can do this easily.

Follow the steps below
1.
screen
2.
sudo java -jar start.jar
3.
ctrl+a and then ctrl+d
4.quit ssh.