代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package deliver
import (
"time"
"gitee.com/hyperledger-fabric-gm/fabric/protos/common"
"github.com/pkg/errors"
)
// ExpiresAtFunc is used to extract the time at which an identity expires.
type ExpiresAtFunc func(identityBytes []byte) time.Time
// ConfigSequencer provides the sequence number of the current config block.
type ConfigSequencer interface {
Sequence() uint64
}
// NewSessionAC creates an instance of SessionAccessControl. This constructor will
// return an error if a signature header cannot be extracted from the envelope.
func NewSessionAC(chain ConfigSequencer, env *common.Envelope, policyChecker PolicyChecker, channelID string, expiresAt ExpiresAtFunc) (*SessionAccessControl, error) {
signedData, err := env.AsSignedData()
if err != nil {
return nil, err
}
return &SessionAccessControl{
envelope: env,
channelID: channelID,
sequencer: chain,
policyChecker: policyChecker,
sessionEndTime: expiresAt(signedData[0].Identity),
}, nil
}
// SessionAccessControl holds access control related data for a common Envelope
// that is used to determine if a request is allowed for the identity
// associated with the request envelope.
type SessionAccessControl struct {
sequencer ConfigSequencer
policyChecker PolicyChecker
channelID string
envelope *common.Envelope
lastConfigSequence uint64
sessionEndTime time.Time
usedAtLeastOnce bool
}
// Evaluate uses the PolicyChecker to determine if a request should be allowed.
// The decision is cached until the identity expires or the chain configuration
// changes.
func (ac *SessionAccessControl) Evaluate() error {
if !ac.sessionEndTime.IsZero() && time.Now().After(ac.sessionEndTime) {
return errors.Errorf("client identity expired %v before", time.Since(ac.sessionEndTime))
}
policyCheckNeeded := !ac.usedAtLeastOnce
if currentConfigSequence := ac.sequencer.Sequence(); currentConfigSequence > ac.lastConfigSequence {
ac.lastConfigSequence = currentConfigSequence
policyCheckNeeded = true
}
if !policyCheckNeeded {
return nil
}
ac.usedAtLeastOnce = true
return ac.policyChecker.CheckPolicy(ac.envelope, ac.channelID)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。