Coverage Report - org.apache.shiro.samples.sprhib.model.User
 
Classes in this File Line Coverage Branch Coverage Complexity
User
0%
0/17
N/A
1
 
 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.HashSet;
 27  
 import java.util.Set;
 28  
 
 29  
 /**
 30  
  * Simple class that represents any User domain entity in any application.
 31  
  *
 32  
  * <p>Because this class performs its own Realm and Permission checks, and these can happen frequently enough in a
 33  
  * production application, it is highly recommended that the internal User {@link #getRoles} collection be cached
 34  
  * in a 2nd-level cache when using JPA and/or Hibernate.  The hibernate xml configuration for this sample application
 35  
  * does in fact do this for your reference (see User.hbm.xml - the 'roles' declaration).</p>
 36  
  */
 37  
 @Entity
 38  
 @Table(name="users")
 39  
 @Cache(usage= CacheConcurrencyStrategy.READ_WRITE)
 40  0
 public class User  {
 41  
 
 42  
     private Long id;
 43  
     private String username;
 44  
     private String email;
 45  
     private String password;
 46  0
     private Set<Role> roles = new HashSet<Role>();
 47  
 
 48  
 
 49  
     @Id
 50  
     @GeneratedValue
 51  
     public Long getId() {
 52  0
         return id;
 53  
     }
 54  
 
 55  
     public void setId(Long id) {
 56  0
         this.id = id;
 57  0
     }
 58  
 
 59  
     /**
 60  
      * Returns the username associated with this user account;
 61  
      *
 62  
      * @return the username associated with this user account;
 63  
      */
 64  
     @Basic(optional=false)
 65  
     @Column(length=100)
 66  
     @Index(name="idx_users_username")
 67  
     public String getUsername() {
 68  0
         return username;
 69  
     }
 70  
 
 71  
     public void setUsername(String username) {
 72  0
         this.username = username;
 73  0
     }
 74  
 
 75  
     @Basic(optional=false)
 76  
     @Index(name="idx_users_email")
 77  
     public String getEmail() {
 78  0
         return email;
 79  
     }
 80  
 
 81  
     public void setEmail(String email) {
 82  0
         this.email = email;
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Returns the password for this user.
 87  
      *
 88  
      * @return this user's password
 89  
      */
 90  
     @Basic(optional=false)
 91  
     @Column(length=255)
 92  
     public String getPassword() {
 93  0
         return password;
 94  
     }
 95  
 
 96  
     public void setPassword(String password) {
 97  0
         this.password = password;
 98  0
     }
 99  
 
 100  
 
 101  
     @ManyToMany
 102  
     @JoinTable(name="users_roles")
 103  
     @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
 104  
     public Set<Role> getRoles() {
 105  0
         return roles;
 106  
     }
 107  
 
 108  
     public void setRoles(Set<Role> roles) {
 109  0
         this.roles = roles;
 110  0
     }
 111  
 
 112  
 }
 113  
 
 114