Search in sources :

Example 1 with OAuthEndpointResponse

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);
}
Also used : OAuthEndpointResponse(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 2 with 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.");
    }
}
Also used : OAuthEndpointResponse(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)2 OAuthEndpointResponse (com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse)2 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)1