yakworks.security.spring.user.SpringUserInfo.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boot-security Show documentation
Show all versions of boot-security Show documentation
gorm-tools security and domain models
/*
* Copyright 2020 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package yakworks.security.spring.user
import groovy.transform.CompileStatic
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.userdetails.UserDetails
import yakworks.commons.model.Named
import yakworks.security.user.UserInfo
/**
* Marries UserDetails and UserInfo
*/
@CompileStatic
trait SpringUserInfo implements UserDetails, Named, UserInfo {
/** UserInfo */
Serializable id
/** UserInfo & UserDetails*/
final String username
/** UserInfo , getPssword returns this*/
final String passwordHash
/** UserInfo */
String name
// /** UserInfo & UserDetails*/
// String username
/** UserInfo */
String displayName
/** UserInfo */
String email
/** UserInfo */
Serializable orgId
/** roles */
Set roles = [] as Set
/** roles */
Set permissions = [] as Set
/** future use */
Map attributes = [:] as Map
//implements the extra UserDetails
boolean accountNonExpired = true
boolean accountNonLocked = true
boolean credentialsNonExpired = true
boolean enabled = true
/** the orginal details (usually ip addy and sessionId) from the Authentication */
Object auditDetails
// @Override //UserInfo
// Set getRoles() {
// SpringUserUtils.authoritiesToRoles((Collection)this.getAuthorities())
// }
@Override
String getPassword() {
return getPasswordHash()
}
@Override
Collection extends GrantedAuthority> getAuthorities(){
return SpringUserUtils.rolesToAuthorities(roles)
}
/** merges only a subset of the data */
def merge(UserInfo sourceUser){
['id', 'name', 'displayName', 'email', 'orgId'].each{ String prop ->
this[prop] = sourceUser[prop]
}
return this
}
}