@Override public Rest assemble(){ if(spec==null){ spec = given(); } spec.auth().preemptive().basic(user, password); return super.assemble(); } }
private static RequestSpecification authenticatedRequest(TestAuthentication authentication) { RequestSpecification builder = jsonRequest(); if (authentication.isAuthenticated()) { builder.auth().preemptive().basic(authentication.getUsername(), authentication.getPassword()); } else { builder.auth().none(); } return builder; }
/** * Override this method to add/enable security to the rest request specification. * example:<br> * <code> * public Response execute(){ * spec.auth().preemptive().basic(user, password); * return execute(endPoint); * } * </code> * @return */ public Response execute() { LOG.debug("server: " + server); LOG.debug("method: " + method); LOG.debug("endpoint: " + endPoint); //System.out.println("url parameters: " + ToteUtils.getListAsString(urlParams)); //assemble(); // if(headerList!=null&&headerList.size()>0) { // spec.headers(headerList); // } spec.auth().none(); Response result = execute(endPoint); return result; }
@Override protected RequestSpecification buildBaseRequestSpecification() { RequestSpecification spec = RestAssured.given(); if (auth != null) { spec.auth().preemptive().basic(auth.get("username"), auth.get("password")); } if (httpLog != null) { spec.config(RestAssured .config() .logConfig(logConfig() .enableLoggingOfRequestAndResponseIfValidationFails() .defaultStream(new PrintStream(new WriterOutputStream(httpLog))) .enablePrettyPrinting(true))); } return spec; }
public static OAuth2AccessToken getClientCredentialsAccessToken(String clientId, String clientSecret) { return given() .parameters("grant_type", "client_credentials") .auth() .preemptive() .basic(clientId, clientSecret) .when() .post("/oauth/token") .as(OAuth2AccessToken.class); }
protected static void deleteUserFromCredentials(String userId, String username, String password) { given() .header("X-Requested-With", "XMLHttpRequest") .auth() .preemptive() .basic(username, password) .contentType("application/json;charset=UTF-8") .accept("application/json") .expect() .when() .delete(getHost() + CONTEXT_PATH + MONITORING_PATH + userId); }