Esempio n. 1
0
func sendAuditLog(token string, requestURI string, method string, path string, requestBody string, queryParameterMap map[string][]string, pathParameterMap map[string]string, remoteAddress string) {
	// Get cache. If not exsiting, retrieving from authorization server.
	user := getCache(token)
	userName := "******"
	if user != nil {
		userName = user.Name
	}

	cloudoneAnalysisHost, ok := configuration.LocalConfiguration.GetString("cloudoneAnalysisHost")
	if ok == false {
		log.Error("Fail to get configuration cloudoneAnalysisHost")
		return
	}
	cloudoneAnalysisPort, ok := configuration.LocalConfiguration.GetInt("cloudoneAnalysisPort")
	if ok == false {
		log.Error("Fail to get configuration cloudoneAnalysisPort")
		return
	}

	// Header is not used since the header has no useful information for now
	auditLog := audit.CreateAuditLog(componentName, path, userName, remoteAddress, queryParameterMap, pathParameterMap, method, requestURI, requestBody, nil)

	url := "https://" + cloudoneAnalysisHost + ":" + strconv.Itoa(cloudoneAnalysisPort) + "/api/v1/auditlogs"

	headerMap := make(map[string]string)
	headerMap["token"] = authorization.SystemAdminToken

	_, err := restclient.RequestPost(url, auditLog, headerMap, false)
	if err != nil {
		log.Error("Fail to send audit log with error %s", err)
	}
}
Esempio n. 2
0
func auditLogWithoutVerified(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
	requestURI := req.Request.URL.RequestURI()
	method := req.Request.Method
	path := req.SelectedRoutePath()
	queryParameterMap := req.Request.URL.Query()
	pathParameterMap := req.PathParameters()
	remoteAddress := req.Request.RemoteAddr

	requestBody, _ := ioutil.ReadAll(req.Request.Body)
	// Write data back for the later use
	req.Request.Body = ioutil.NopCloser(bytes.NewReader(requestBody))

	go func() {
		userData := UserData{}
		req.ReadEntity(&userData)
		userName := userData.Username

		cloudoneAnalysisHost, ok := configuration.LocalConfiguration.GetString("cloudoneAnalysisHost")
		if ok == false {
			log.Error("Fail to get configuration cloudoneAnalysisHost")
			return
		}
		cloudoneAnalysisPort, ok := configuration.LocalConfiguration.GetInt("cloudoneAnalysisPort")
		if ok == false {
			log.Error("Fail to get configuration cloudoneAnalysisPort")
			return
		}

		// Header is not used since the header has no useful information for now
		auditLog := audit.CreateAuditLog(componentName, path, userName, remoteAddress, queryParameterMap, pathParameterMap, method, requestURI, string(requestBody), nil)

		url := "https://" + cloudoneAnalysisHost + ":" + strconv.Itoa(cloudoneAnalysisPort) + "/api/v1/auditlogs"

		headerMap := make(map[string]string)
		headerMap["token"] = authorization.SystemAdminToken

		_, err := restclient.RequestPost(url, auditLog, headerMap, false)
		if err != nil {
			log.Error("Fail to send audit log with error %s", err)
		}
	}()

	chain.ProcessFilter(req, resp)
}
Esempio n. 3
0
func sendAuditLog(ctx *context.Context, userName string, saveParameter bool) (returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			returnedError = err.(error)
		}
	}()

	cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol")
	cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost")
	cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort")

	tokenHeaderMap, tokenHeaderMapOK := ctx.Input.Session("tokenHeaderMap").(map[string]string)
	requestURI := ctx.Input.URI()
	method := ctx.Input.Method()
	path := ctx.Input.URL()
	remoteAddress := ctx.Request.RemoteAddr
	queryParameterMap := ctx.Request.Form

	proxySlice := ctx.Input.Proxy()
	if proxySlice != nil && len(proxySlice) > 0 {
		proxySlice = append(proxySlice, remoteAddress)
		remoteAddress = fmt.Sprintf("%v", proxySlice)
	}

	if saveParameter == false {
		// Not to save parameter, such as password
		requestURI = path
		queryParameterMap = nil
	}

	// Header is not used since the header has no useful information for now
	// Body is not used since the backend component will record again.
	// Path is not used since the backend component will record again.
	auditLog := audit.CreateAuditLog(componentName, path, userName, remoteAddress, queryParameterMap, nil, method, requestURI, "", nil)

	if tokenHeaderMapOK {
		url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort + "/api/v1/auditlogs"

		restclient.RequestPost(url, auditLog, tokenHeaderMap, false)
		// err is logged in analysis so don't need to here
	}

	return nil
}
func sendAuditLog(token string, requestURI string, method string, path string, requestBody string, queryParameterMap map[string][]string, pathParameterMap map[string]string, remoteAddress string) {
	// Get cache. If not exsiting, retrieving from authorization server.
	user, err := getCache(token)
	userName := ""
	if err != nil {
		log.Error(err)
		userName = "******"
	}
	if user != nil {
		userName = user.Name
	}

	// Header is not used since the header has no useful information for now
	auditLog := utilityaudit.CreateAuditLog(componentName, path, userName, remoteAddress, queryParameterMap, pathParameterMap, method, requestURI, requestBody, nil)

	err = audit.SaveAudit(auditLog, false)
	if err != nil {
		log.Error("Fail to send audit log with error %s", err)
	}
}