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

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

Updated the BaseController? to incorporate basic authentication (not yet implemented) to capture all method ( = controller and action ) calls. For now is authorizes everything, to be continued...

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