source: branches/TaskRewrite/src/plugins/acegi-0.5.1/src/java/org/codehaus/groovy/grails/plugins/springsecurity/SecurityAnnotationAttributes.java @ 58

Last change on this file since 58 was 58, checked in by gav, 15 years ago

Configure BootStrap? with latest concepts.
Install and setup Acegi plugin with custom views.
Test Fixture plugin in a test app but couldn't get it to work with Acegi encodePassword() so gave up.

File size: 3.6 KB
Line 
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 */
15package org.codehaus.groovy.grails.plugins.springsecurity;
16
17import java.lang.annotation.Annotation;
18import java.lang.reflect.Field;
19import java.lang.reflect.Method;
20import java.util.Collection;
21import java.util.HashSet;
22import java.util.Set;
23
24import org.springframework.core.annotation.AnnotationUtils;
25import org.springframework.metadata.Attributes;
26import org.springframework.security.SecurityConfig;
27import org.springframework.security.annotation.Secured;
28
29/**
30 * Re-implementation of Acegi's {@link SecurityAnnotationAttributes} as a temporary
31 * fix until I can figure out how to do this correctly in 2.0.
32 *
33 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
34 */
35public class SecurityAnnotationAttributes implements Attributes {
36
37        /**
38         * {@inheritDoc}
39         * @see org.springframework.metadata.Attributes#getAttributes(java.lang.Class)
40         */
41        @SuppressWarnings("unchecked")
42        public Set<SecurityConfig> getAttributes(final Class target) {
43                Set<SecurityConfig> attributes = new HashSet<SecurityConfig>();
44
45                for (Annotation annotation : target.getAnnotations()) {
46                        if (annotation instanceof Secured) {
47                                Secured attr = (Secured)annotation;
48                                for (String auth : attr.value()) {
49                                        attributes.add(new SecurityConfig(auth));
50                                }
51                                break;
52                        }
53                }
54
55                return attributes;
56        }
57
58        /**
59         * {@inheritDoc}
60         * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Method)
61         */
62        public Set<SecurityConfig> getAttributes(final Method method) {
63                Set<SecurityConfig> attributes = new HashSet<SecurityConfig>();
64
65                Annotation[] annotations = AnnotationUtils.getAnnotations(method);
66                for (Annotation annotation : annotations) {
67                        if (annotation instanceof Secured) {
68                                Secured attr = (Secured)annotation;
69                                for (String auth : attr.value()) {
70                                        attributes.add(new SecurityConfig(auth));
71                                }
72
73                                break;
74                        }
75                }
76
77                return attributes;
78        }
79
80        /**
81         * {@inheritDoc}
82         * @see org.springframework.metadata.Attributes#getAttributes(java.lang.Class, java.lang.Class)
83         */
84        @SuppressWarnings("unchecked")
85        public Collection getAttributes(final Class clazz, final Class filter) {
86                throw new UnsupportedOperationException("Unsupported operation");
87        }
88
89        /**
90         * {@inheritDoc}
91         * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Method, java.lang.Class)
92         */
93        @SuppressWarnings("unchecked")
94        public Collection getAttributes(final Method method, final Class clazz) {
95                throw new UnsupportedOperationException("Unsupported operation");
96        }
97
98        /**
99         * {@inheritDoc}
100         * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Field)
101         */
102        @SuppressWarnings("unchecked")
103        public Collection getAttributes(final Field field) {
104                throw new UnsupportedOperationException("Unsupported operation");
105        }
106
107        /**
108         * {@inheritDoc}
109         * @see org.springframework.metadata.Attributes#getAttributes(java.lang.reflect.Field, java.lang.Class)
110         */
111        @SuppressWarnings("unchecked")
112        public Collection getAttributes(final Field field, final Class clazz) {
113                throw new UnsupportedOperationException("Unsupported operation");
114        }
115}
Note: See TracBrowser for help on using the repository browser.