use of com.hp.octane.integrations.services.vulnerabilities.ssc.dto.AuthToken in project octane-ci-java-sdk by MicroFocus.
the class SSCServerSimulator method setDefaultAuth.
public void setDefaultAuth() {
setAuthHanler(request -> {
try {
AuthToken.AuthTokenData authTokenData = new AuthToken.AuthTokenData();
authTokenData.token = "DUMMY TOKEN";
authTokenData.terminalDate = "TERMINAL_DATE";
AuthToken authToken = new AuthToken();
authToken.setData(authTokenData);
request.getResponse().setStatus(HttpStatus.SC_OK);
request.getResponse().getWriter().write(SSCTestUtils.getJson(authToken));
request.getResponse().getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
});
}
use of com.hp.octane.integrations.services.vulnerabilities.ssc.dto.AuthToken in project octane-ci-java-sdk by MicroFocus.
the class SSCRestClientImpl method sendReqAuth.
private AuthToken.AuthTokenData sendReqAuth(SSCProjectConfiguration sscProjectConfiguration) {
// "/{SSC Server Context}/api/v1"
// String url = "http://" + serverURL + "/ssc/api/v1/projects?q=id:2743&fulltextsearch=true";
String url = sscProjectConfiguration.getSSCUrl() + "/api/v1/tokens";
HttpPost request = new HttpPost(url);
request.addHeader("Authorization", sscProjectConfiguration.getSSCBaseAuthToken());
request.addHeader("Accept", "application/json");
request.addHeader("Host", getNetHost(sscProjectConfiguration.getSSCUrl()));
request.addHeader("Content-Type", "application/json;charset=UTF-8");
String body = "{\"type\": \"UnifiedLoginToken\"}";
CloseableHttpResponse response = null;
try {
HttpEntity entity = new ByteArrayEntity(body.getBytes(StandardCharsets.UTF_8));
request.setEntity(entity);
response = httpClient.execute(request);
if (succeeded(response.getStatusLine().getStatusCode())) {
String toString = CIPluginSDKUtils.inputStreamToUTF8String(response.getEntity().getContent());
AuthToken authToken = new ObjectMapper().readValue(toString, TypeFactory.defaultInstance().constructType(AuthToken.class));
return authToken.getData();
} else {
throw new PermanentException("Couldn't Authenticate SSC user, need to check SSC configuration in Octane plugin");
}
} catch (Throwable t) {
throw new PermanentException(t);
} finally {
if (response != null) {
EntityUtils.consumeQuietly(response.getEntity());
HttpClientUtils.closeQuietly(response);
}
}
}
Aggregations