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
class SecurityTokenService { | |
def getSecurityToken(SomeDomainClass sdc) { | |
if(!sdc?.uuid){ | |
sdc.uuid = UUID.randomUUID().toString() | |
sdc.save(flush:true) | |
} | |
return sdc.uuid | |
} | |
} |
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
private def accessAllowed = { securityToken, uuid -> | |
//check if user is authenticated | |
if(!springSecurityService.isLoggedIn()){ | |
//alternatively check if a security token is provided | |
if(!securityToken || securityToken != uuid){ | |
return(false) | |
} | |
} | |
return(true) | |
} | |
def someAction = { | |
def someObject = SomeObject.get(params.id) | |
if(accessAllowed(params.securityToken, someObject.uuid)){ | |
//do stuff | |
} | |
else{ | |
render status: 403 | |
} | |
} |
No comments:
Post a Comment