czetsuya
czetsuya

Reputation: 5063

Basic authentication with arquillian testing in jboss

I've just finished writing arquillian testing with jboss and document it here:

http://czetsuya-tech.blogspot.com/2014/11/rest-testing-with-arquillian-in-jboss.html#.VGQkCvmUeSk

But I have a problem, our rest web services are secured using a filter:

@WSSecured
@Provider
public class RESTSecurityInterceptor implements ContainerRequestFilter,
        ExceptionMapper<Exception> { //... }

How do you add username / password token when calling an arquillian rest easy resource?

@RunAsClient
@Test
public void testCreate(
@ArquillianResteasyResource("api/rest") CountryWs countryWs) { }

Upvotes: 2

Views: 740

Answers (1)

czetsuya
czetsuya

Reputation: 5063

The solution to this problem is create a producer that will produce a default user and add this class to the test war:

@Singleton
@Startup
public class DefaultUserProducer {

    @Inject
    private Logger log;

    @Inject
    private UserService userService;

    private User currentUser;

    @PostConstruct
    public void init() {
        try {
            currentUser = userService.login("username", "password");
        } catch (LoginException e) {
            log.error("Failed to login. {}", e.getMessage());
        }
    }

    @Produces
    @RSUser
    public User getCurrentUser() {
        return currentUser;
    }

}

Upvotes: 1

Related Questions