source: trunk/grails-app/controllers/BaseController.groovy @ 13

Last change on this file since 13 was 13, checked in by duh, 13 years ago

added some comments

  • Property svn:keywords set to Date Author Rev
File size: 2.1 KB
Line 
1import org.codehaus.groovy.grails.commons.GrailsApplication
2import grails.util.GrailsUtil
3//import org.apache.log4j.*
4
5/**
6 * Base Controller
7 * @Author  Jeroen Wesbeek
8 * @Since   20091014
9 * @see     Authorization.groovy
10 * @Description
11 *
12 * Base Controller which provides general functionality. Should always be
13 * extended in all controllers
14 *
15 * Revision information:
16 * $Rev: 13 $
17 * $Author: duh $
18 * $Date: 2009-10-19 14:08:10 +0000 (ma, 19 okt 2009) $
19 */
20class BaseController {
21    /**
22     * @var object authorization object
23     * @visibility public
24     */
25    public def Authorization;
26    public def scaffold = false;
27
28    /**
29     * class constructor
30     * @void
31     */
32    protected BaseController() {
33        // instantiate Authorization class
34        this.Authorization = new Authorization();
35
36        // dynamically set scaffolding
37        this.scaffold = (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT && this.class.name != 'BaseController');
38    }
39
40    /**
41     * Render default output to the browser, overload this in extended classes
42     * @void
43     */
44    def index = {
45        render(sprintf("default index for %s @ %s environment :: nothing to see here! :)",this.class.name,GrailsUtil.environment));
46    }
47
48    /**
49     * intercept any method calls in extended classes
50     * @see http://www.grails.org/Controllers+-+Interceptors
51     */
52    def beforeInterceptor = {
53        def controller = params.controller;
54        def action = params.action;
55       
56        // check if the user is Authorized to call this method
57        if (Authorization.isAuthorized(controller,action)) {
58            // user is not authorized to use this functionality
59            printf("authorized call to action: %s->%s(...)\n",controller,action);
60        } else {
61            // user is not authorized to use this functionality
62            printf("!! unauthorized call to action: %s-->%s(...)\n",controller,action);
63
64            // redirect to error page
65            flash['error'] = sprintf("unauthorized call to action: %s::%s\n",controller,action);
66            redirect(controller:'error',action:'index');
67        }
68    }
69
70    /**
71     * after interception
72     * @param object model
73     * @param object modelAndView
74     * @see http://www.grails.org/Controllers+-+Interceptors
75     */
76    def afterInterceptor = {
77        // nothing here yet
78    }
79}
Note: See TracBrowser for help on using the repository browser.