source: trunk/grails-app/domain/dbnp/authentication/SecUserSecRole.groovy @ 976

Last change on this file since 976 was 976, checked in by robert@…, 12 years ago

Authentication and authorization for studies is added, according to ticket 118

File size: 1.4 KB
Line 
1package dbnp.authentication
2
3import org.apache.commons.lang.builder.HashCodeBuilder
4
5class SecUserSecRole implements Serializable {
6
7        SecUser secUser
8        SecRole secRole
9
10        boolean equals(other) {
11                if (!(other instanceof SecUserSecRole)) {
12                        return false
13                }
14
15                other.secUser?.id == secUser?.id &&
16                        other.secRole?.id == secRole?.id
17        }
18
19        int hashCode() {
20                def builder = new HashCodeBuilder()
21                if (secUser) builder.append(secUser.id)
22                if (secRole) builder.append(secRole.id)
23                builder.toHashCode()
24        }
25
26        static SecUserSecRole get(long secUserId, long secRoleId) {
27                find 'from SecUserSecRole where secUser.id=:secUserId and secRole.id=:secRoleId',
28                        [secUserId: secUserId, secRoleId: secRoleId]
29        }
30
31        static SecUserSecRole create(SecUser secUser, SecRole secRole, boolean flush = false) {
32                new SecUserSecRole(secUser: secUser, secRole: secRole).save(flush: flush, insert: true)
33        }
34
35        static boolean remove(SecUser secUser, SecRole secRole, boolean flush = false) {
36                SecUserSecRole instance = SecUserSecRole.findBySecUserAndSecRole(secUser, secRole)
37                instance ? instance.delete(flush: flush) : false
38        }
39
40        static void removeAll(SecUser secUser) {
41                executeUpdate 'DELETE FROM SecUserSecRole WHERE secUser=:secUser', [secUser: secUser]
42        }
43
44        static void removeAll(SecRole secRole) {
45                executeUpdate 'DELETE FROM SecUserSecRole WHERE secRole=:secRole', [secRole: secRole]
46        }
47
48        static mapping = {
49                id composite: ['secRole', 'secUser']
50                version false
51        }
52}
Note: See TracBrowser for help on using the repository browser.