-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
again a sample app for zyro23/grails-spring-websocket#64 (this time w…
…ith spring-security-core)
- Loading branch information
Showing
10 changed files
with
189 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
|
||
// Added by the Spring Security Core plugin: | ||
grails.plugin.springsecurity.userLookup.userDomainClassName = 'myapp.User' | ||
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'myapp.UserRole' | ||
grails.plugin.springsecurity.authority.className = 'myapp.Role' | ||
grails.plugin.springsecurity.controllerAnnotations.staticRules = [ | ||
[pattern: '/', access: ['permitAll']], | ||
[pattern: '/error', access: ['permitAll']], | ||
[pattern: '/index', access: ['permitAll']], | ||
[pattern: '/index.gsp', access: ['permitAll']], | ||
[pattern: '/shutdown', access: ['permitAll']], | ||
[pattern: '/assets/**', access: ['permitAll']], | ||
[pattern: '/**/js/**', access: ['permitAll']], | ||
[pattern: '/**/css/**', access: ['permitAll']], | ||
[pattern: '/**/images/**', access: ['permitAll']], | ||
[pattern: '/**/favicon.ico', access: ['permitAll']], | ||
[pattern: '/stomp/**', access: ['hasRole("USER")']], | ||
] | ||
|
||
grails.plugin.springsecurity.filterChain.chainMap = [ | ||
[pattern: '/assets/**', filters: 'none'], | ||
[pattern: '/**/js/**', filters: 'none'], | ||
[pattern: '/**/css/**', filters: 'none'], | ||
[pattern: '/**/images/**', filters: 'none'], | ||
[pattern: '/**/favicon.ico', filters: 'none'], | ||
[pattern: '/**', filters: 'JOINED_FILTERS'] | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package myapp | ||
|
||
import groovy.transform.EqualsAndHashCode | ||
import groovy.transform.ToString | ||
import grails.compiler.GrailsCompileStatic | ||
|
||
@GrailsCompileStatic | ||
@EqualsAndHashCode(includes='authority') | ||
@ToString(includes='authority', includeNames=true, includePackage=false) | ||
class Role implements Serializable { | ||
|
||
private static final long serialVersionUID = 1 | ||
|
||
String authority | ||
|
||
static constraints = { | ||
authority nullable: false, blank: false, unique: true | ||
} | ||
|
||
static mapping = { | ||
cache true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package myapp | ||
|
||
import groovy.transform.EqualsAndHashCode | ||
import groovy.transform.ToString | ||
import grails.compiler.GrailsCompileStatic | ||
|
||
@GrailsCompileStatic | ||
@EqualsAndHashCode(includes='username') | ||
@ToString(includes='username', includeNames=true, includePackage=false) | ||
class User implements Serializable { | ||
|
||
private static final long serialVersionUID = 1 | ||
|
||
String username | ||
String password | ||
boolean enabled = true | ||
boolean accountExpired | ||
boolean accountLocked | ||
boolean passwordExpired | ||
|
||
Set<Role> getAuthorities() { | ||
(UserRole.findAllByUser(this) as List<UserRole>)*.role as Set<Role> | ||
} | ||
|
||
static constraints = { | ||
password nullable: false, blank: false, password: true | ||
username nullable: false, blank: false, unique: true | ||
} | ||
|
||
static mapping = { | ||
password column: '`password`' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package myapp | ||
|
||
import grails.gorm.DetachedCriteria | ||
import groovy.transform.ToString | ||
|
||
import org.codehaus.groovy.util.HashCodeHelper | ||
import grails.compiler.GrailsCompileStatic | ||
|
||
@GrailsCompileStatic | ||
@ToString(cache=true, includeNames=true, includePackage=false) | ||
class UserRole implements Serializable { | ||
|
||
private static final long serialVersionUID = 1 | ||
|
||
User user | ||
Role role | ||
|
||
@Override | ||
boolean equals(other) { | ||
if (other instanceof UserRole) { | ||
other.userId == user?.id && other.roleId == role?.id | ||
} | ||
} | ||
|
||
@Override | ||
int hashCode() { | ||
int hashCode = HashCodeHelper.initHash() | ||
if (user) { | ||
hashCode = HashCodeHelper.updateHash(hashCode, user.id) | ||
} | ||
if (role) { | ||
hashCode = HashCodeHelper.updateHash(hashCode, role.id) | ||
} | ||
hashCode | ||
} | ||
|
||
static UserRole get(long userId, long roleId) { | ||
criteriaFor(userId, roleId).get() | ||
} | ||
|
||
static boolean exists(long userId, long roleId) { | ||
criteriaFor(userId, roleId).count() | ||
} | ||
|
||
private static DetachedCriteria criteriaFor(long userId, long roleId) { | ||
UserRole.where { | ||
user == User.load(userId) && | ||
role == Role.load(roleId) | ||
} | ||
} | ||
|
||
static UserRole create(User user, Role role, boolean flush = false) { | ||
def instance = new UserRole(user: user, role: role) | ||
instance.save(flush: flush) | ||
instance | ||
} | ||
|
||
static boolean remove(User u, Role r) { | ||
if (u != null && r != null) { | ||
UserRole.where { user == u && role == r }.deleteAll() | ||
} | ||
} | ||
|
||
static int removeAll(User u) { | ||
u == null ? 0 : UserRole.where { user == u }.deleteAll() as int | ||
} | ||
|
||
static int removeAll(Role r) { | ||
r == null ? 0 : UserRole.where { role == r }.deleteAll() as int | ||
} | ||
|
||
static constraints = { | ||
user nullable: false | ||
role nullable: false, validator: { Role r, UserRole ur -> | ||
if (ur.user?.id) { | ||
if (UserRole.exists(ur.user.id, r.id)) { | ||
return ['userRole.exists'] | ||
} | ||
} | ||
} | ||
} | ||
|
||
static mapping = { | ||
id composite: ['user', 'role'] | ||
version false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters