(no commit message)
[utils] / security / impl / src / main / java / org / wamblee / security / authorization / AbstractAuthorizationService.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16 package org.wamblee.security.authorization;
17
18 import javax.persistence.DiscriminatorColumn;
19 import javax.persistence.Entity;
20 import javax.persistence.GeneratedValue;
21 import javax.persistence.GenerationType;
22 import javax.persistence.Id;
23 import javax.persistence.Inheritance;
24 import javax.persistence.InheritanceType;
25 import javax.persistence.NamedQueries;
26 import javax.persistence.NamedQuery;
27 import javax.persistence.Table;
28 import javax.persistence.Version;
29
30 /**
31  * Service to determine if access to a certain resource is allowed.
32  * 
33  * @author Erik Brakkee
34  */
35 @Entity
36 @Table(name = "SEC_AUTH_SVC")
37 @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
38 @DiscriminatorColumn(name = "TYPE")
39 @NamedQueries( 
40     @NamedQuery(name = AbstractAuthorizationService.QUERY_FIND_BY_NAME, 
41         query = "select s from AbstractAuthorizationService s where s.name = :" +
42         AbstractAuthorizationService.NAME_PARAM)
43         )
44 public abstract class AbstractAuthorizationService implements AuthorizationService {
45  
46     public static final String QUERY_FIND_BY_NAME = "AuthorizationService.findByName";
47     public static final String NAME_PARAM = "name";
48     
49     @Id
50     @GeneratedValue(strategy = GenerationType.AUTO)
51     private Long id;
52
53     @Version
54     private int version;
55     
56     /**
57      * Name for this instance of the authorization service.
58      */
59     private String name; 
60     
61     public AbstractAuthorizationService() { 
62         // Empty. 
63     }
64     
65     public AbstractAuthorizationService(String aName) { 
66         name = aName; 
67     }
68     
69     public AbstractAuthorizationService(AbstractAuthorizationService aSvc) { 
70         id = aSvc.id;
71         version = aSvc.version;
72         name = aSvc.name;
73     }
74     
75     public String getName() {
76         return name;
77     }
78 }