From: Erik Brakkee Date: Mon, 26 Apr 2010 20:16:43 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~514 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=e1d9bd9ae47021814e7d99cb82104b3c7f6cb968;p=utils --- diff --git a/security/impl/src/main/java/org/wamblee/usermgt/Group.java b/security/impl/src/main/java/org/wamblee/usermgt/Group.java index 13075aa2..275cc081 100644 --- a/security/impl/src/main/java/org/wamblee/usermgt/Group.java +++ b/security/impl/src/main/java/org/wamblee/usermgt/Group.java @@ -12,23 +12,54 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.usermgt; -import org.wamblee.persistence.AbstractPersistent; - import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; +import javax.persistence.Version; + +import org.wamblee.security.AbstractPersistent; + /** * Represents a group. * * @author Erik Brakkee */ -public class Group extends AbstractPersistent implements Serializable, - Comparable { +@Entity +@Table(name = "SEC_GROUP") +@NamedQueries( { + @NamedQuery(name = Group.QUERY_FIND_BY_NAME, query = "select g from Group g where g.name = :" + + Group.NAME_PARAM), + @NamedQuery(name = Group.QUERY_COUNT_GROUPS, query = "select count(g) from Group g"), + @NamedQuery(name = Group.QUERY_ALL_GROUPS, query = "select g from Group g") }) +public class Group implements Serializable, Comparable { + + public static final String QUERY_FIND_BY_NAME = "Group.findByName"; + public static final String QUERY_COUNT_GROUPS = "Group.count"; + public static final String QUERY_ALL_GROUPS = "Group.all"; + public static final String NAME_PARAM = "name"; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long primaryKey; + + @Version + private int version; + /** * Group name. */ + @Column(nullable = false, unique = true) private String name; /** @@ -46,7 +77,6 @@ public class Group extends AbstractPersistent implements Serializable, * */ public Group(Group aGroup) { - super(aGroup); name = aGroup.name; } @@ -109,6 +139,10 @@ public class Group extends AbstractPersistent implements Serializable, public int compareTo(Object aGroup) { return name.compareTo(((Group) aGroup).name); } + + public Long getPrimaryKey() { + return primaryKey; + } /* * (non-Javadoc) diff --git a/security/impl/src/main/java/org/wamblee/usermgt/User.java b/security/impl/src/main/java/org/wamblee/usermgt/User.java index 224435a1..8bccfaba 100644 --- a/security/impl/src/main/java/org/wamblee/usermgt/User.java +++ b/security/impl/src/main/java/org/wamblee/usermgt/User.java @@ -12,11 +12,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.usermgt; -import org.wamblee.persistence.AbstractPersistent; - +import org.wamblee.security.AbstractPersistent; import org.wamblee.security.encryption.MessageDigester; import org.wamblee.usermgt.UserMgtException.Reason; @@ -26,13 +25,32 @@ import java.io.Serializable; import java.util.Set; import java.util.TreeSet; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.Transient; +import javax.persistence.Version; + /** * Represents a user. The methods for managing the groups of the user have * package scope. Managing the groups of the user should be done through the * {@link org.wamblee.usermgt.UserAdministration} interface. */ -public class User extends AbstractPersistent implements Serializable, +@Entity +@Table(name = "SEC_USER") +public class User implements Serializable, Comparable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long primaryKey; + + @Version + private int version; + /** * User name. */ @@ -46,16 +64,19 @@ public class User extends AbstractPersistent implements Serializable, /** * Groups the user belongs to. */ + @ManyToMany private Set groups; /** * Password validator. */ + @Transient private NameValidator passwordValidator; /** * Password encoder. */ + @Transient private MessageDigester passwordEncoder; /** @@ -86,7 +107,6 @@ public class User extends AbstractPersistent implements Serializable, * */ public User(User aUser) { - super(aUser); name = aUser.name; password = aUser.password; groups = new TreeSet(); @@ -365,4 +385,8 @@ public class User extends AbstractPersistent implements Serializable, public int compareTo(Object aUser) { return name.compareTo(((User) aUser).name); } + + public Long getPrimaryKey() { + return primaryKey; + } }