Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hasPermission method to check permission #1

Merged
merged 1 commit into from Feb 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions SecurityBridgeGrailsPlugin.groovy
Expand Up @@ -24,6 +24,9 @@ class SecurityBridgeGrailsPlugin {
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 developers = [
[name: 'Jeremy Michael Crosbie', email: 'jcrosbie@bcap.com']
]
def documentation = "http://bertramdev.github.io/grails-security-bridge"
def license = "APACHE"
def organization = [name: "Bertram Labs", url: "http://www.bertramlabs.com/"]
Expand Down
Expand Up @@ -27,7 +27,7 @@ class SharedSecurityService implements SecurityBridge {
* Execute the closure with the user and account object based on the passed id
*/
def withUser(identity, Closure code) {
getSecurityBridge(failOnError: true).withUser(identity, code)
getSecurityBridge(failOnError: true).withUser(identity, code)
}


Expand Down Expand Up @@ -87,6 +87,13 @@ class SharedSecurityService implements SecurityBridge {
securityBridge?.isAuthorized(object, action)
}

/**
* {@inheritDoc}
*/
boolean hasPermission(permission, opts=null) {
securityBridge?.hasPermission(permission, opts)
}

/**
* Check if the currently logged in user has the specified role
* @param role
Expand All @@ -98,7 +105,7 @@ class SharedSecurityService implements SecurityBridge {
boolean hasAnyRole(roles) {
roles = roles instanceof Collection ? roles : [roles]
roles.any { role ->
getSecurityBridge()?.hasRole(role)
getSecurityBridge()?.hasRole(role)
}
}

Expand Down
@@ -0,0 +1,109 @@
/*
* Copyright 2014 the original author or 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 org.grails.plugin.securitybridge

abstract class AbstractSecurityBridge implements SecurityBridge {

/**
* {@inheritDoc}
* @return null
*/
def getCurrentUser() {
null
}

/**
* {@inheritDoc}
* @return null
*/
def getUserIdentity() {
null
}

/**
* {@inheritDoc}
* @return null
*/
def getCurrentAccount() {
null
}

/**
* {@inheritDoc}
* @return null
*/
def getAccountIdentity() {
null
}

/**
* {@inheritDoc}
* @return null
*/
def getCurrentUserDisplayName() {
null
}

/**
* {@inheritDoc}
* @return false
*/
boolean isLoggedIn() {
false
}

/**
* {@inheritDoc}
* @return false
*/
boolean isAuthorized(object, action) {
false
}

/**
* {@inheritDoc}
* @return false
*/
boolean hasRole(role) {
false
}

/**
* {@inheritDoc}
* @return false
*/
boolean hasPermission(permission, opts=null) {
false
}

/**
* {@inheritDoc}
*/
def storeLocation(request) {
}

/**
* {@inheritDoc}
*/
def withUser(identity, Closure code) {
}

/**
* {@inheritDoc}
*/
Map createLink(String action) {
}
}
17 changes: 17 additions & 0 deletions src/groovy/org/grails/plugin/securitybridge/SecurityBridge.groovy
Expand Up @@ -64,6 +64,23 @@ interface SecurityBridge {
*/
boolean hasRole(role)

/**
* Check if the currently logged in user has the specified permission
* in any of his/her assigned roles.
* @param permission the name of the permission to check
* @param opts depending on then permissions model, this can be used to add
* configurability to permission.
*/
boolean hasPermission(permission, opts)

/**
* Check if the currently logged in user has the specified permission
* in any of his/her assigned roles.
* @param permission the name of the permission to check
*/
boolean hasPermission(permission)


/**
* Store the request location for the security service to redirect to upon login success
* @param request The request object
Expand Down