View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.shiro.samples.sprhib.model;
20  
21  import org.hibernate.annotations.Cache;
22  import org.hibernate.annotations.CacheConcurrencyStrategy;
23  import org.hibernate.annotations.Index;
24  
25  import javax.persistence.*;
26  import java.util.Set;
27  
28  /**
29   * Model object that represents a security role.
30   */
31  @Entity
32  @Table(name="roles")
33  @Cache(usage= CacheConcurrencyStrategy.READ_WRITE)
34  public class Role {
35  
36      private Long id;
37  
38      private String name;
39  
40      private String description;
41  
42      private Set<String> permissions;
43  
44      protected Role() {
45      }
46  
47      public Role(String name) {
48          this.name = name;
49      }
50  
51  
52      @Id
53      @GeneratedValue
54      public Long getId() {
55          return id;
56      }
57  
58      public void setId(Long id) {
59          this.id = id;
60      }
61  
62      @Basic(optional=false)
63      @Column(length=100)
64      @Index(name="idx_roles_name")
65      public String getName() {
66          return name;
67      }
68  
69      public void setName(String name) {
70          this.name = name;
71      }
72  
73      @Basic(optional=false)
74      @Column(length=255)
75      public String getDescription() {
76          return description;
77      }
78  
79      public void setDescription(String description) {
80          this.description = description;
81      }
82  
83      @ElementCollection(targetClass=String.class)
84      @JoinTable(name="roles_permissions")
85      @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
86      public Set<String> getPermissions() {
87          return permissions;
88      }
89  
90      public void setPermissions(Set<String> permissions) {
91          this.permissions = permissions;
92      }
93  
94  }
95  
96