Skip to content

Instantly share code, notes, and snippets.

@aweigold
Last active August 29, 2015 14:13
Show Gist options
  • Save aweigold/517acb0fefdc391fffa6 to your computer and use it in GitHub Desktop.
Save aweigold/517acb0fefdc391fffa6 to your computer and use it in GitHub Desktop.
Auditing your Spring Security mappings with Groovy
//Add net.sf.corn:corn-cps:1.0.1 to your classpath
import net.sf.corn.cps.*
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.security.access.prepost.PreAuthorize
def classes = CPScanner.scanClasses(new PackageNameFilter("com.company.*"), new ClassFilter().appendAnnotation(Controller))
classes.each { clazz ->
clazz.getDeclaredMethods().each { method ->
RequestMapping mapping = method.getAnnotation(RequestMapping)
if (mapping != null){
PreAuthorize auth = method.getAnnotation(PreAuthorize)
if (auth != null){
println "URL: " + mapping.value()
println "PERM: " + auth.value()
println "------"
}
}
}
}
return "DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment