-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated documentation in preparation for the 2.0.8 release
Updated changelog
- Loading branch information
Showing
12 changed files
with
273 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ss2: 2.0.6 | ||
ss2: 2.0.8 | ||
ss1: 0.2.6 |
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,59 @@ | ||
--- | ||
file: authorization | ||
--- | ||
# Adding Authorization | ||
|
||
SecureSocial provides a way to add authorization logic to your controller actions. This is done by implementing an `Authorization` object that is passed to the `SecuredAction` as a parameter. | ||
|
||
After checking if a user is authenticated the `Authorization` instance is used to verify if the execution should be allowed or not. | ||
|
||
## Scala | ||
|
||
For Scala, you need to implement the `Authorization` trait. | ||
|
||
:::scala | ||
trait Authorization { | ||
def isAuthorized(user: Identity): Boolean | ||
} | ||
|
||
This is a sample implementation that only grants acccess to users that logged in usign a given provider: | ||
|
||
:::scala | ||
case class WithProvider(provider: String) extends Authorization { | ||
def isAuthorized(user: Identity) = { | ||
user.id.providerId == provider | ||
} | ||
} | ||
|
||
Here's how you would use it: | ||
|
||
:::scala | ||
def myAction = SecuredAction(WithProvider("twitter")) { implicit request => | ||
// do something here | ||
} | ||
|
||
## Java | ||
|
||
For Java, you need to implement the `Authorization` interface. | ||
|
||
:::java | ||
public interface Authorization { | ||
boolean isAuthorized(Identity user, String[] params); | ||
} | ||
|
||
This is an equivalent implementation to the Scala sample: | ||
|
||
:::java | ||
public class WithProvider implements Authorization { | ||
public boolean isAuthorized(Identity user, String params[]) { | ||
return user.id().providerId().equals(params[0]); | ||
} | ||
} | ||
|
||
Here's how you would use it: | ||
|
||
:::java | ||
@SecureSocial.SecuredAction( authorization = WithProvider.class, params = {"twitter"}) | ||
public static Result myAction() { | ||
// do something here | ||
} |
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
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
Oops, something went wrong.