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