I want to use TJWS for test my java web application with jboss. I use an implementation of ContainerRequestFilter that allows me to specify the list of roles permitted to access methods in the application (by the use of RolesAllowed annotation).
I don't know how to "insert" the filter in my tiny server. I've tried to add that to the list of providers but don't work...
below the code of the server:
public abstract class BaseServiceTest extends JpaTest {
private static final Integer PORT = 12345;
protected TJWSEmbeddedJaxrsServer server;
private static User adminUser;
private static User basicUser;
private static User racUser;
private String LOGIN_URL ="/users/login";
protected static String adminAuthentication;
protected static String basicAuthentication;
protected static String racAuthentication;
private UserDao userDao;
private String bindAddress = "localhost";
@Override
public void setUp() throws InitializationError {
super.setUp();
userDao = new UserDao();
server = new TJWSEmbeddedJaxrsServer();
server.setPort(PORT);
RestAssured.port = PORT;
server.setBindAddress(bindAddress);
server.setRootResourcePath("/");
for (Object endpoint : getEndpoints()) {
server.getDeployment().getResources().add(endpoint);
}
SecurityRequestFilter srFilter = new SecurityRequestFilter();
try {
FieldUtils.writeField(srFilter, "userDao", userDao, true);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
server.getDeployment().getProviders().add(srFilter);
server.start();
// other stuff...
}
and the code of the filter:
@Provider
@Priority(Priorities.AUTHENTICATION)
public class SecurityRequestFilter implements ContainerRequestFilter {
@Context
UriInfo uriInfo;
@Inject
UserDao userDao;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
//some filter stuff
...
}
I hope I've made my point despite my not so good english.
Aucun commentaire:
Enregistrer un commentaire