Esempio n. 1
0
// IsTokenValid checks whether a token is valid for a Secure Entity.
func IsTokenValid(secureEntity SecureEntity, token string) error {
	tracelog.STARTED("Utils", "IsValidToken")

	decodedToken, err := base64.StdEncoding.DecodeString(token)
	if err != nil {
		tracelog.ERRORf(err, "Utils", "Utils.IsValidToken", "Error Decoding Passed In Token, %s", token)
		return err
	}

	entityToken, tErr := secureEntity.TokenBytes()
	if tErr != nil {
		tracelog.ERRORf(tErr, "Utils", "Utils.IsValidToken", "Error Generating Token for Entity")
		return tErr
	}

	if hmac.Equal(decodedToken, entityToken) == false {
		tracelog.ERRORf(err, "Utils", "Utils.IsValidToken", "Invalid Token Comparison,Tokens Are not the same, Invalid Token, entity[%s], decoded[%s]", string(entityToken), string(decodedToken))
		return errors.New("Invalid Token")
	}

	tracelog.COMPLETED("Utils", "IsValidToken, Token Is Valid")
	return nil
}
Esempio n. 2
0
// Prepare is called prior to the baseController method
func (baseController *BaseController) Prepare() {
	baseController.UserId = baseController.GetString("userId")
	if baseController.UserId == "" {
		baseController.UserId = baseController.GetString(":userId")
	}
	if baseController.UserId == "" {
		baseController.UserId = "Unknown"
	}

	err := baseController.Service.Prepare()
	if err != nil {
		tracelog.ERRORf(err, baseController.UserId, "BaseController.Prepare", baseController.Ctx.Request.URL.Path)
		baseController.ServeError(err)
		return
	}

	tracelog.TRACE(baseController.UserId, "BaseController.Prepare", "UserId[%s] Path[%s]", baseController.UserId, baseController.Ctx.Request.URL.Path)
}
Esempio n. 3
0
// Prepare is called prior to the controller method
func (this *BaseController) Prepare() {
	this.UserId = this.GetString("userId")
	if this.UserId == "" {
		this.UserId = this.GetString(":userId")
	}
	if this.UserId == "" {
		this.UserId = "Unknown"
	}

	err := this.Service.Prepare()
	if err != nil {
		tracelog.ERRORf(err, this.UserId, "BaseController.Prepare", this.Ctx.Request.URL.Path)
		this.ServeError(err)
		return
	}

	tracelog.TRACE(this.UserId, "BaseController.Prepare", "UserId[%s] Path[%s]", this.UserId, this.Ctx.Request.URL.Path)
}