All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.beaglesecurity.client.BeagleSecurityClientBase Maven / Gradle / Ivy

Go to download

The Beagle Security SDK for Java provides Java APIs for building software for penetration testing using Beagle Security platform.

The newest version!
/**
 * Copyright (c) Beagle Cyber Innovations Pvt. Ltd. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for
 * license information.
 */

package com.beaglesecurity.client;

import org.apache.http.HttpStatus;

import com.beaglesecurity.execptions.ForbiddenException;
import com.beaglesecurity.execptions.GeneralAPIException;
import com.beaglesecurity.execptions.InternalServerErrorException;
import com.beaglesecurity.execptions.UnAuthorizedException;
import com.fasterxml.jackson.databind.ObjectMapper;

public abstract class BeagleSecurityClientBase {
	protected static final String baseUrl = "https://api.beaglesecurity.com/rest/v2/";	
	protected String token;	
	/**
     * 

* Convert a json string to object given as type *

* @param json string to convert as object * @param type the type to which the json string needs to convert * @param passing class type * @return Converted json object */ protected T convertJsonToObject(String json, Class type) { try { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(json, type); } catch (Exception e) { } return null; } /** *

* Generate common exceptions based or REST API return code *

* * @param errorCode is the code for generating custom exception * @throws GeneralAPIException * General exceptions. * @throws UnAuthorizedException * No permission to view the application * @throws ForbiddenException * Forbidden * @throws InternalServerErrorException * Internal server error */ protected void handleCommonExceptions(int errorCode) { if (errorCode == HttpStatus.SC_FORBIDDEN) { throw new ForbiddenException("Forbidden."); } else if (errorCode == HttpStatus.SC_UNAUTHORIZED) { throw new UnAuthorizedException("Unauthorized."); } else if (errorCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) { throw new InternalServerErrorException("Internal server error."); } else { throw new GeneralAPIException("Some error has occured."); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy