1 | /* Copyright 2006-2009 the original author or authors. |
---|
2 | * |
---|
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | * you may not use this file except in compliance with the License. |
---|
5 | * You may obtain a copy of the License at |
---|
6 | * |
---|
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | * |
---|
9 | * Unless required by applicable law or agreed to in writing, software |
---|
10 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | * See the License for the specific language governing permissions and |
---|
13 | * limitations under the License. |
---|
14 | */ |
---|
15 | package org.codehaus.groovy.grails.plugins.springsecurity |
---|
16 | |
---|
17 | import org.codehaus.groovy.grails.commons.ApplicationHolder as AH |
---|
18 | |
---|
19 | /** |
---|
20 | * Helper class for RequestmapFilterInvocationDefinition to perform Requestmap dynamic query. |
---|
21 | * |
---|
22 | * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> |
---|
23 | */ |
---|
24 | class RequestmapFilterInvocationDefinitionHelper { |
---|
25 | |
---|
26 | private String _requestMapClass // 'Requestmap' |
---|
27 | private String _requestMapPathFieldName // 'url' |
---|
28 | private String _requestMapConfigAttributeField // 'configAttribute' |
---|
29 | |
---|
30 | /** |
---|
31 | * Constructor. |
---|
32 | * @param requestMapClass Requestmap class name |
---|
33 | * @param requestMapPathFieldName Requestmap path pattern field name |
---|
34 | * @param requestMapConfigAttributeField Requestmap config attribute (roles) field name |
---|
35 | */ |
---|
36 | RequestmapFilterInvocationDefinitionHelper(String requestMapClass, |
---|
37 | String requestMapPathFieldName, String requestMapConfigAttributeField) { |
---|
38 | _requestMapClass = requestMapClass |
---|
39 | _requestMapPathFieldName = requestMapPathFieldName |
---|
40 | _requestMapConfigAttributeField = requestMapConfigAttributeField |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Load all Requestmaps and build a map with the relevant data. |
---|
45 | * @return keys are url patterns, values are roles |
---|
46 | */ |
---|
47 | Map<String, String> loadRequestmaps() { |
---|
48 | Class requestmapClass = AH.application.getClassForName(_requestMapClass) |
---|
49 | Map<String, String> data = [:] |
---|
50 | def requestmaps = requestmapClass.list() |
---|
51 | for (requestmap in requestmaps) { |
---|
52 | String urlPattern = requestmap."${_requestMapPathFieldName}" |
---|
53 | String configAttribute = requestmap."${_requestMapConfigAttributeField}" |
---|
54 | data[urlPattern] = configAttribute |
---|
55 | } |
---|
56 | |
---|
57 | return data |
---|
58 | } |
---|
59 | } |
---|