Documentation
¶
Index ¶
- Constants
- func SetSecurityManager(securityManager SecurityManager)
- type AuthenticationInfo
- type AuthenticationToken
- type Authenticator
- type Authorizer
- type CacheManager
- type Cryptography
- type Gate
- type GateController
- type GateFactory
- type Permission
- type PrincipalCollection
- type Realm
- type SecurityManager
- type Session
- type SessionDAO
- type SessionKey
- type SessionManager
- type Subject
- type SubjectContext
Constants ¶
View Source
const SessionKeyName = "github.com/bitwormhole/starter-gin/security/Session#binding"
Variables ¶
This section is empty.
Functions ¶
func SetSecurityManager ¶ added in v0.0.3
func SetSecurityManager(securityManager SecurityManager)
SetSecurityManager 设置安全管理器
Types ¶
type AuthenticationInfo ¶ added in v0.0.3
type AuthenticationInfo interface {
// GetPrincipal 获取身份
GetPrincipals() PrincipalCollection
// GetCredentials 获取凭证
GetCredentials() lang.Object
}
AuthenticationInfo 验证输出
type AuthenticationToken ¶ added in v0.0.3
type AuthenticationToken interface {
// GetPrincipal 获取身份
GetPrincipal() lang.Object
// GetCredentials 获取凭证
GetCredentials() lang.Object
}
AuthenticationToken 验证输入
type Authenticator ¶ added in v0.0.3
type Authenticator interface {
// Authenticate 进行身份验证
Authenticate(token AuthenticationToken) (AuthenticationInfo, error)
}
Authenticator 身份验证者
type Authorizer ¶ added in v0.0.3
type Authorizer interface {
CheckPermissionS(subjectPrincipal PrincipalCollection, permission string) error
CheckPermissionP(subjectPrincipal PrincipalCollection, permission Permission) error
CheckPermissionsSA(subjectPrincipal PrincipalCollection, permissions ...string) error
CheckPermissionsPA(subjectPrincipal PrincipalCollection, permissions []Permission) error
CheckRole(subjectPrincipal PrincipalCollection, roleIdentifier string) error
CheckRoles(subjectPrincipal PrincipalCollection, roleIdentifiers ...string) error
HasRole(subjectPrincipal PrincipalCollection, roleIdentifier string) bool
HasRoles(subjectPrincipal PrincipalCollection, roleIdentifiers []string) []bool
HasAllRoles(subjectPrincipal PrincipalCollection, roleIdentifiers []string) bool
IsPermittedS(principals PrincipalCollection, permission string) bool
IsPermittedP(subjectPrincipal PrincipalCollection, permission Permission) bool
IsPermittedSA(subjectPrincipal PrincipalCollection, permissions ...string) bool
IsPermittedPA(subjectPrincipal PrincipalCollection, permissions []Permission) []bool
IsPermittedAllSA(subjectPrincipal PrincipalCollection, permissions ...string) bool
IsPermittedAllPA(subjectPrincipal PrincipalCollection, permissions []Permission) bool
}
Authorizer 授权者
type CacheManager ¶ added in v0.0.3
type CacheManager interface {
}
CacheManager 【注意】由于目前暂未引入泛型支持,所以该接口暂时禁用
type Gate ¶ added in v0.0.3
type Gate interface {
Control(ctx lang.Context) GateController
}
Gate 安全闸门
type GateController ¶ added in v0.0.3
type GateController interface {
Context() lang.Context
Check() (lang.Context, error)
UsePanic() GateController
DisusePanic() GateController
}
GateController 安全闸门控制器
type Permission ¶ added in v0.0.3
type Permission interface {
Implies(p Permission) bool
}
Permission 许可
type PrincipalCollection ¶ added in v0.0.3
type PrincipalCollection interface {
GetPrimaryPrincipal() lang.Object
AsList() []lang.Object
FromRealm(realmName string) []lang.Object
GetRealmNames() []string
IsEmpty() bool
}
PrincipalCollection Principal 的集合
type Realm ¶ added in v0.0.3
type Realm interface {
GetName() string
Supports(token AuthenticationToken) bool
GetAuthenticationInfo(token AuthenticationToken) (AuthenticationInfo, error)
}
Realm 是一个可以通过访问应用程序特定的安全实体(例如:用户,角色,许可),来确认验证和授权操作的安全组件。
type SecurityManager ¶ added in v0.0.3
type SecurityManager interface {
// 同时实现以下三个接口
Authenticator
Authorizer
SessionManager
Login(subject Subject, token AuthenticationToken) (Subject, error)
Logout(subject Subject)
CreateSubject(context SubjectContext) Subject
}
SecurityManager 安全管理器
func GetSecurityManager ¶ added in v0.0.3
func GetSecurityManager(ctx context.Context) (SecurityManager, error)
GetSecurityManager 取安全管理器
type Session ¶
type Session interface {
GetID() string
GetStartTimestamp() time.Time
GetLastAccessTime() time.Time
GetTimeout() (int64, error)
SetTimeout(maxIdleTimeInMillis int64) error
GetHost() string
Touch() error
Stop() error
GetAttributeKeys() ([]string, error)
GetAttribute(key string) (lang.Object, error)
SetAttribute(key string, value lang.Object) error
RemoveAttribute(key string) error
}
Session 表示一个具体的会话
type SessionDAO ¶ added in v0.0.3
type SessionDAO interface {
Create(session Session) lang.Serializable
ReadSession(sessionID lang.Serializable) (Session, error)
Update(session Session) error
Delete(session Session)
GetActiveSessions() []Session
}
SessionDAO 是Session的数据访问对象
type SessionKey ¶ added in v0.0.3
type SessionKey interface {
GetSessionId() string
}
SessionKey 跟session绑定的键
type SessionManager ¶ added in v0.0.3
type SessionManager interface {
Start(ctx context.Context) Session
GetSession(key SessionKey) (Session, error)
}
SessionManager 会话管理器
type Subject ¶ added in v0.0.3
type Subject interface {
GetPrincipal() lang.Object
GetPrincipals() PrincipalCollection
IsPermittedS(permission string) bool
IsPermittedP(permission Permission) bool
IsPermittedSA(permissions ...string) []bool
IsPermittedPA(permissions []Permission) []bool
IsPermittedAllSA(permissions ...string) bool
IsPermittedAllPA(permissions []Permission) bool
CheckPermissionS(permission string) error
CheckPermissionP(permission Permission) error
CheckPermissionsSA(permissions ...string) error
CheckPermissionsPA(permissions []Permission) error
HasRole(roleIdentifier string) bool
HasRoles(roleIdentifiers []string) []bool
HasAllRoles(roleIdentifiers []string) bool
CheckRole(roleIdentifier string) error
CheckRoles(roleIdentifiers ...string) error
Login(token AuthenticationToken) error
IsAuthenticated() bool
IsRemembered() bool
GetSession(create bool) Session
Logout()
IsRunAs() bool
GetPreviousPrincipals() PrincipalCollection
ReleaseRunAs() PrincipalCollection
}
Subject 主体,可以是任何可以与应用交互的 “用户”
func GetSubject ¶ added in v0.0.3
GetSubject 从给定的上下文取 Subject 对象
type SubjectContext ¶ added in v0.0.3
type SubjectContext interface {
collection.Attributes
GetSecurityManager() SecurityManager
SetSecurityManager(securityManager SecurityManager)
ResolveSecurityManager() SecurityManager
GetSessionID() lang.Serializable
SetSessionID(id lang.Serializable)
GetSubject() Subject
SetSubject(subject Subject)
GetPrincipals() PrincipalCollection
ResolvePrincipals() PrincipalCollection
SetPrincipals(principals PrincipalCollection)
GetSession() Session
SetSession(session Session)
ResolveSession() Session
IsAuthenticated() bool
SetAuthenticated(authc bool)
IsSessionCreationEnabled() bool
SetSessionCreationEnabled(enabled bool)
ResolveAuthenticated() bool
GetAuthenticationInfo() AuthenticationInfo
SetAuthenticationInfo(info AuthenticationInfo)
GetAuthenticationToken() AuthenticationToken
SetAuthenticationToken(token AuthenticationToken)
GetHost() string
SetHost(host string)
ResolveHost() string
}
SubjectContext Subject 上下文
Click to show internal directories.
Click to hide internal directories.