-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 for v0.9 Release
- Loading branch information
Showing
20 changed files
with
775 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package security | ||
|
||
import ( | ||
"aahframework.org/aah.v0" | ||
"aahframework.org/config.v0" | ||
"aahframework.org/security.v0/authc" | ||
) | ||
|
||
var _ authc.Authenticator = (*AuthenticationProvider)(nil) | ||
|
||
// AuthenticationProvider struct implements `authc.Authenticator` interface. | ||
type AuthenticationProvider struct { | ||
} | ||
|
||
// Init method initializes the AuthenticationProvider, this method gets called | ||
// during server start up. | ||
func (a *AuthenticationProvider) Init(cfg *config.Config) error { | ||
|
||
// NOTE: Init is called on application startup | ||
|
||
return nil | ||
} | ||
|
||
// GetAuthenticationInfo method is `authc.Authenticator` interface | ||
func (a *AuthenticationProvider) GetAuthenticationInfo(authcToken *authc.AuthenticationToken) (*authc.AuthenticationInfo, error) { | ||
|
||
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ | ||
// This code snippet provided as a reference | ||
// | ||
// Call your appropriate datasource here (such as DB, API, LDAP, etc) | ||
// to get the subject (aka user) authentication information. | ||
// | ||
// Form Auth Values from authcToken | ||
// authcToken.Identity => username | ||
// authcToken.Credential => passowrd | ||
//_____________________________________________________________________ | ||
|
||
// user := models.FindUserByEmail(authcToken.Identity) | ||
// if user == nil { | ||
// // No subject exists, return nil and error | ||
// return nil, authc.ErrSubjectNotExists | ||
// } | ||
|
||
// User found, now create authentication info and return to the framework | ||
authcInfo := authc.NewAuthenticationInfo() | ||
// authcInfo.Principals = append(authcInfo.Principals, | ||
// &authc.Principal{ | ||
// Value: user.Email, | ||
// IsPrimary: true, | ||
// Realm: "inmemory", | ||
// }) | ||
// authcInfo.Credential = []byte(user.Password) | ||
// authcInfo.IsLocked = user.IsLocked | ||
// authcInfo.IsExpired = user.IsExpried | ||
|
||
return authcInfo, nil | ||
} | ||
|
||
func postAuthEvent(e *aah.Event) { | ||
ctx := e.Data.(*aah.Context) | ||
|
||
// Do post successful authentication actions... | ||
_ = ctx | ||
} | ||
|
||
func init() { | ||
aah.OnPostAuth(postAuthEvent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package security | ||
|
||
import ( | ||
"aahframework.org/config.v0" | ||
"aahframework.org/security.v0/authc" | ||
"aahframework.org/security.v0/authz" | ||
) | ||
|
||
var _ authz.Authorizer = (*AuthorizationProvider)(nil) | ||
|
||
// AuthorizationProvider struct implements `authz.Authorizer` interface. | ||
type AuthorizationProvider struct { | ||
} | ||
|
||
// Init method initializes the AuthorizationProvider, this method gets called | ||
// during server start up. | ||
func (a *AuthorizationProvider) Init(cfg *config.Config) error { | ||
|
||
// NOTE: Init is called on application startup | ||
|
||
return nil | ||
} | ||
|
||
// GetAuthorizationInfo method is `authz.Authorizer` interface. | ||
// | ||
// GetAuthorizationInfo method gets called after authentication is successful | ||
// to get Subject's (aka User) access control information such as roles and permissions. | ||
func (a *AuthorizationProvider) GetAuthorizationInfo(authcInfo *authc.AuthenticationInfo) *authz.AuthorizationInfo { | ||
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ | ||
// This code snippet provided as a reference | ||
// | ||
// Call your appropriate datasource here (such as DB, API, etc) | ||
// to get the subject (aka user) authorization details (roles, permissions) | ||
//__________________________________________________________________________ | ||
|
||
// authorities := models.FindUserByEmail(authcInfo.PrimaryPrincipal().Value) | ||
|
||
authzInfo := authz.NewAuthorizationInfo() | ||
// authzInfo.AddRole(authorities.Roles...) | ||
// authzInfo.AddPermissionString(authorities.Permissions...) | ||
|
||
return authzInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.