Skip to content

Commit

Permalink
Merge pull request #2 from bertramdev/namespace-support
Browse files Browse the repository at this point in the history
Namespace support
  • Loading branch information
davydotcom committed Jun 25, 2015
2 parents d916cfd + 9e80ed7 commit 1078c7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions SecurityBridgeGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class SecurityBridgeGrailsPlugin {
def title = "Security Bridge Plugin" // Headline display name of the plugin
def author = "David Estes"
def authorEmail = "destes@bcap.com"
def description = 'Defines a standard corss-plugin security bridge implementation for better decoupling of authentication in plugin heavy applications.'
def description = 'Defines a standard cross-plugin security bridge implementation for better decoupling of authentication in plugin heavy applications.'

def developers = [
[name: 'Jeremy Michael Crosbie', email: 'jcrosbie@bcap.com']
[name: 'Jeremy Michael Crosbie', email: 'jcrosbie@bcap.com', name: 'William Chu', email: 'wchu@bcap.com']
]
def documentation = "http://bertramdev.github.io/grails-security-bridge"
def license = "APACHE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class SharedSecurityService implements SecurityBridge {

SecurityBridge getSecurityBridge(options=[:]) {
if (!sharedSecurityBridge) {
def message = "An attempt was made to use the sharedSecurityBridge, but none has been defined. Please refer to the grails security btidge plugin docs for information on how to define a bridge."
def message = "An attempt was made to use the sharedSecurityBridge, but none has been defined. Please refer to the grails security bridge plugin docs for information on how to define a bridge."
if(options.failOnError) {
throw new IllegalArgumentException(message)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SecurityBridgeTagLib {
def sharedSecurityService

/**
* Executes the body of the tag is the user is logged in.
* Executes the body of the tag if the user is logged in.
*/
def ifLoggedIn = {attrs, body ->
if(sharedSecurityService.isLoggedIn()) {
Expand Down Expand Up @@ -47,6 +47,8 @@ class SecurityBridgeTagLib {
* then the current controller is used.
* @attr action OPTIONAL the name of the action to check. If not given the
* current action is used.
* @attr namespace OPTIONAL the namespace of the controller to check. If not given
* then the first controller returned by getArtefactByLogicalPropertyName is used.
*/
def ifAuthorized = {attrs, body ->
if(checkAuthorized(attrs)) {
Expand Down Expand Up @@ -89,7 +91,19 @@ class SecurityBridgeTagLib {
private checkAuthorized(attrs) {
def controller = attrs.remove('controller') ?: controllerName
def action = attrs.remove('action') ?: actionName
def namespace = attrs.remove('namespace') ?: null

sharedSecurityService.isAuthorized(grailsApplication.getArtefactByLogicalPropertyName('Controller', controller), action)
def controllerToCheck
if(namespace) {
controllerToCheck = grailsApplication.getArtefacts('Controller').find {
if(it.logicalPropertyName == controller && it.namespace && it.namespace == namespace) {
return true
}
}
} else {
controllerToCheck = grailsApplication.getArtefactByLogicalPropertyName('Controller', controller)
}

sharedSecurityService.isAuthorized(controllerToCheck, action)
}
}
}

0 comments on commit 1078c7b

Please sign in to comment.