Using digest authentication with 2 guards

3 messages Options
Embed this post
Permalink
sachin

Using digest authentication with 2 guards

Reply Threaded More More options
Print post
Permalink
Hi all,

I'm trying to use digest authentication on my rest web service. I'm using Restlet 1.1.5 version.

My web service requires me to pass two different realm values on the basis of url that the user is trying to access.

Following is the code that i'm using.

public class RestletApplication extends Application {

	/**
	 * Creates a root Restlet that will receive all incoming calls.
	 */
	@Override
	public Restlet createRoot() {
		// Create a router Restlet that routes each call to a
		
		Router root = new Router(getContext());

		Router router1 = new Router(getContext());
		router1.attach("/customer/{customerID}/orders/{orderID}/contents/{contentID}",Content.class);
		router1.attach("/customer/{customerID}/orders/{orderID}", Order.class);

		
		Router router2 = new Router(getContext());
		router2.attach("/customer/{customerID}/print/orders", SubmitOrder.class);


		Guard guard1 = new Guard(getContext().createChildContext(),
                "realm1", new ArrayList<String>() , "serverKey1");

        Guard guard2 = new Guard(getContext().createChildContext(),
                "realm2", new ArrayList<String>(), "serverKey2");
        
        guard2.getSecrets().put("sachin", "pwd".toCharArray());
        guard1.setSecretResolver(new RWSResolver());
        
        guard1.setNext(router1);
        guard2.setNext(router2);
        
        root.attach("/customer/{customerID}/print/orders/{orderID}", guard1);
        root.attach("/customer/{customerID}/print/orders", guard2);
               
		return root;
	}

	public static void main(String[] args) {
		try {
			// Create a new Component.
			Component component = new Component();

			component.getServers().add(Protocol.HTTP,8182);
			
			component.getDefaultHost().attachDefault(new RestletApplication());
			
			// Start the component.
			component.start();
		} catch (Exception e) {
			// Something is wrong.
			//ExceptionLogger.logError(e);
		}
	}
	
}


Now the problem that i'm facing is that when i send a  GET request to
"http://localhost:8182/customer/myCustomer/print/orders" then it works well that is i get 401 then after setting the credentials i get a 200 response. It passes thru the guard2 also. But when i send a GET request to "http://localhost:8182/customer/myCustomer/print/orders/order1" Then it gets processed by guard1. But after successful authorization i get a 404. It means after accepting the request guard1 is not able to redirect it to router1.

Any suggstions?

Thanks,
Sachin  
sachin

Re: Using digest authentication with 2 guards

Reply Threaded More More options
Print post
Permalink
Issue resolved :) ...


sachin wrote:
Hi all,

I'm trying to use digest authentication on my rest web service. I'm using Restlet 1.1.5 version.

My web service requires me to pass two different realm values on the basis of url that the user is trying to access.

Following is the code that i'm using.

public class RestletApplication extends Application {

	/**
	 * Creates a root Restlet that will receive all incoming calls.
	 */
	@Override
	public Restlet createRoot() {
		// Create a router Restlet that routes each call to a
		
		Router root = new Router(getContext());

		Router router1 = new Router(getContext());
		router1.attach("/customer/{customerID}/orders/{orderID}/contents/{contentID}",Content.class);
		router1.attach("/customer/{customerID}/orders/{orderID}", Order.class);

		
		Router router2 = new Router(getContext());
		router2.attach("/customer/{customerID}/print/orders", SubmitOrder.class);


		Guard guard1 = new Guard(getContext().createChildContext(),
                "realm1", new ArrayList<String>() , "serverKey1");

        Guard guard2 = new Guard(getContext().createChildContext(),
                "realm2", new ArrayList<String>(), "serverKey2");
        
        guard2.getSecrets().put("sachin", "pwd".toCharArray());
        guard1.setSecretResolver(new RWSResolver());
        
        guard1.setNext(router1);
        guard2.setNext(router2);
        
        root.attach("/customer/{customerID}/print/orders/{orderID}", guard1);
        root.attach("/customer/{customerID}/print/orders", guard2);
               
		return root;
	}

	public static void main(String[] args) {
		try {
			// Create a new Component.
			Component component = new Component();

			component.getServers().add(Protocol.HTTP,8182);
			
			component.getDefaultHost().attachDefault(new RestletApplication());
			
			// Start the component.
			component.start();
		} catch (Exception e) {
			// Something is wrong.
			//ExceptionLogger.logError(e);
		}
	}
	
}


Now the problem that i'm facing is that when i send a  GET request to
"http://localhost:8182/customer/myCustomer/print/orders" then it works well that is i get 401 then after setting the credentials i get a 200 response. It passes thru the guard2 also. But when i send a GET request to "http://localhost:8182/customer/myCustomer/print/orders/order1" Then it gets processed by guard1. But after successful authorization i get a 404. It means after accepting the request guard1 is not able to redirect it to router1.

Any suggstions?

Thanks,
Sachin  
webpost

RE: Re: Using digest authentication with 2 guards

Reply Threaded More More options
Print post
Permalink
I am facing the exact same problem.
How did you resolve this issue??
Any Help is greatly appreciated!

Thanks,
Hetal

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2413959