1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 namespace PetStore
.Model
18 using System
.Security
.Principal
;
20 using Castle
.ActiveRecord
;
22 using NHibernate
.Expression
;
25 [ActiveRecord("`User`", DiscriminatorColumn
="type", DiscriminatorType
="String", DiscriminatorValue
="user")]
26 public class User
: ActiveRecordBase
, IPrincipal
32 private string password
;
33 private string userType
;
46 set { login = value; }
60 set { email = value; }
64 public string Password
66 get { return password; }
67 set { password = value; }
71 /// Exposing the discriminator column
72 /// has its restrictions
74 [Property("type", Insert
=false, Update
=false)]
75 public string UserType
77 get { return userType; }
78 set { userType = value; }
81 public bool IsInRole(string role
)
83 // We do not implement this functionality
87 public IIdentity Identity
89 get { return new GenericIdentity(name, "castle.authentication"); }
92 public static User
Find(int id
)
94 return (User
) FindByPrimaryKey( typeof(User
), id
);
97 public static User
FindByLogin(String login
)
99 User
[] users
= (User
[])
100 FindAll( typeof(User
), Expression
.Eq("Login", login
) );
102 if (users
.Length
== 1)