security - Java jersey importing packages -


i'm trying remake solution found here basic http authentication jersey / grizzly

i've included these imports far

import javax.ws.rs.webapplicationexception; import javax.ws.rs.container.containerrequestfilter; import javax.ws.rs.core.response; import javax.ws.rs.core.httpheaders; import javax.ws.rs.core.response.status; 

and after search included one

import org.glassfish.jersey.server.containerrequest; 

my problem these errors

... authfilter not abstract , not override abstract method filter(containerrequestcontext) in containerrequestfilter  ... method not override or implement method supertype  ... cannot find symbol [error] symbol:   method getheadervalue(string) [error] location: variable containerrequest of type containerrequest 

and code if don't want switch tabs here

    @override     public containerrequest filter(containerrequest containerrequest)              throws webapplicationexception {          // automatically allow requests.         string method = containerrequest.getmethod();         string path = containerrequest.getpath(true);         if (method.equals("get") && path.equals("application.wadl"))             return containerrequest;          // authentication passed in http headers parameters         string auth = containerrequest.getheadervalue("authorization");         if (auth == null)             throw unauthorized; 

unfortunately don't have needed reputation ask op appreciated.

edit: apparently com.sun.jersey.spi.container.containerrequest not include getheadervalue , 1 cannot found jersey 2.0 way around it?

import javax.ws.rs.webapplicationexception; import javax.ws.rs.container.containerrequestfilter; import javax.ws.rs.container.containerrequestcontext;  import org.glassfish.jersey.internal.util.base64; import java.io.ioexception;  public class authfilter implements containerrequestfilter {      @override     public void filter(containerrequestcontext requestcontext)              throws ioexception {          string method = requestcontext.getmethod();         string path = requestcontext.geturiinfo().getpath();           string auth = requestcontext.getheaderstring("authorization");         if (auth == null)             throw new authenticationexception("too bad");         //how import ^          auth = auth.replacefirst("[bb]asic ", "");          string entry = new string(base64.decode(auth));           if (!entry.equals("admin:password"))             throw new authenticationexception("too bad");     }  } 

that class link implementing jersey 1 specific, containerrequestfilter. class name became standard class (just name) starting jax-rs 2 (jersey 2.x). new signature method is

import java.io.ioexception; import javax.ws.rs.container.containerrequestcontext; import javax.ws.rs.container.containerrequestfilter;  public class hello implements containerrequestfilter {      @override     public void filter(containerrequestcontext requestcontext) throws ioexception {         requestcontext.getmethod();         requestcontext.geturiinfo().getpath();         requestcontext.getheaderstring("authorization");     }  } 

i added changed calls of similar methods, used in class

you can find link complete basic auth example in answer. jersey project examples, uses jersey 2


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -