forked from Peripli/service-manager
/
interfaces.go
97 lines (81 loc) · 3.26 KB
/
interfaces.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright 2018 The Service Manager Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package security
import (
"context"
"net/http"
"github.com/Peripli/service-manager/pkg/web"
)
// Decision represents a decision to allow or deny further
// processing or to abstain from taking a decision
type Decision int
var decisions = []string{"Abstain", "Allow", "Deny"}
const (
// Abstain represents a decision to abstain from deciding - let another component decide
Abstain Decision = iota
// Allow represents decision to allow to proceed
Allow
// Deny represents decision to deny to proceed
Deny
)
// String implements Stringer and converts the decision to human-readable value
func (a Decision) String() string {
return decisions[a]
}
// Authenticator extracts the authenticator information from the request and
// returns information about the current user or an error if security was not successful
//go:generate counterfeiter . Authenticator
type Authenticator interface {
// Authenticate returns information about the user if security is successful, a bool specifying
// whether the authenticator ran or not and an error if one occurs
Authenticate(req *http.Request) (*web.UserContext, Decision, error)
}
// Authorizer extracts the information from the authenticated user and
// returns a decision if the authorization passed
//go:generate counterfeiter . Authorizer
type Authorizer interface {
// Authorize returns decision specifying
// whether the authorizer ran or not and an error if one occurs
Authorize(req *http.Request) (Decision, error)
}
// TokenData represents the authentication token
//go:generate counterfeiter . TokenData
type TokenData interface {
// Claims reads the claims from the token into the specified struct
Claims(v interface{}) error
}
// TokenVerifier attempts to verify a token and returns it or an error if the verification was not successful
//go:generate counterfeiter . TokenVerifier
type TokenVerifier interface {
// Verify verifies that the token is valid and returns a token if so, otherwise returns an error
Verify(ctx context.Context, token string) (TokenData, error)
}
// Encrypter provides functionality to encrypt and decrypt data
//go:generate counterfeiter . Encrypter
type Encrypter interface {
Encrypt(ctx context.Context, plaintext []byte) ([]byte, error)
Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error)
}
// KeyFetcher provides functionality to get encryption key from a remote location
//go:generate counterfeiter . KeyFetcher
type KeyFetcher interface {
GetEncryptionKey(ctx context.Context) ([]byte, error)
}
// KeySetter provides functionality to set encryption key in a remote location
//go:generate counterfeiter . KeySetter
type KeySetter interface {
SetEncryptionKey(ctx context.Context, key []byte) error
}