use of com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse in project hub-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createErrorResponse.
private ActionResponse<OAuthEndpointResponse> createErrorResponse(HttpStatus httpStatus, String errorMessage) {
oAuthRequestValidator.removeAllRequests();
OAuthEndpointResponse oAuthEndpointResponse = new OAuthEndpointResponse(false, "", errorMessage);
return new ActionResponse<>(httpStatus, errorMessage, oAuthEndpointResponse);
}
use of com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse in project hub-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<OAuthEndpointResponse> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
try {
Optional<FieldModel> savedFieldModel = saveIfValid(fieldModel);
if (!savedFieldModel.isPresent()) {
return createErrorResponse("The configuration is invalid. Please test the configuration.");
}
FieldUtility fieldUtility = createFieldAccessor(savedFieldModel.get());
Optional<String> clientId = fieldUtility.getString(AzureBoardsDescriptor.KEY_CLIENT_ID);
if (!clientId.isPresent()) {
return createErrorResponse("App ID not found.");
}
Optional<String> alertServerUrl = alertWebServerUrlManager.getServerUrl();
if (!alertServerUrl.isPresent()) {
return createErrorResponse("Could not determine the alert server url for the callback.");
}
String requestKey = oAuthRequestValidator.generateRequestKey();
// since we have only one OAuth channel now remove any other requests.
// if we have more OAuth clients then the "remove requests" will have to be removed from here.
// beginning authentication process create the request id at the start.
oAuthRequestValidator.removeRequestsOlderThan5MinutesAgo();
oAuthRequestValidator.addAuthorizationRequest(requestKey);
logger.info("OAuth authorization request created: {}", requestKey);
String authUrl = createAuthURL(clientId.get(), requestKey);
logger.debug("Authenticating Azure OAuth URL: {}", authUrl);
return new ActionResponse<>(HttpStatus.OK, new OAuthEndpointResponse(isAuthenticated(fieldUtility), authUrl, "Authenticating..."));
} catch (Exception ex) {
logger.error("Error activating Azure Boards", ex);
return createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, "Error activating azure oauth.");
}
}
Aggregations