forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
37 lines (29 loc) · 881 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package auth
import (
"github.com/hyperledger/fabric/protos/peer"
)
// Filter defines an authentication filter that intercepts
// ProcessProposal methods
type Filter interface {
peer.EndorserServer
// Init initializes the Filter with the next EndorserServer
Init(next peer.EndorserServer)
}
// ChainFilters chains the given auth filters in the order provided.
// the last filter always forwards to the endorser
func ChainFilters(endorser peer.EndorserServer, filters ...Filter) peer.EndorserServer {
if len(filters) == 0 {
return endorser
}
// Each filter forwards to the next
for i := 0; i < len(filters)-1; i++ {
filters[i].Init(filters[i+1])
}
// Last filter forwards to the endorser
filters[len(filters)-1].Init(endorser)
return filters[0]
}