bacoAlunos
ENGSOFT2019
BlueGrey
calm
Elegant
Català-Valencià - Catalan
中文 - Chinese (Simplified)
中文 - Chinese (Traditional)
Česky - Czech
Dansk - Danish
Nederlands - Dutch
English - English
Suomi - Finnish
Français - French
Deutsch - German
עברית - Hebrew
हिंदी - Hindi
Magyar - Hungarian
Bahasa Indonesia - Indonesian
Italiano - Italian
日本語 - Japanese
한국어 - Korean
मराठी - Marathi
Norsk - Norwegian
Polski - Polish
Português - Portuguese
Português - Portuguese (Brazil)
Русский - Russian
Slovenčina - Slovak
Slovenščina - Slovenian
Español - Spanish
Svenska - Swedish
Türkçe - Turkish
Oëzbekcha - Uzbek
Subversion Repositories
bacoAlunos
(root)
/
branches
/
v3
/
impl
/
src
/
java
/
pt
/
estgp
/
estgweb
/
domain
/
GenericUserImpl.java
@ 1844
- Rev 1814
Rev
Rev 1524
|
Blame
|
Compare with Previous
|
Last modification
|
View Log
|
RSS feed
package
pt.estgp.estgweb.domain
;
import
jomm.utils.MessageResources
;
import
org.apache.log4j.Logger
;
import
pt.estgp.estgweb.domain.utils.RoleManagerDomain
;
import
pt.estgp.estgweb.utils.Globals
;
import
pt.estgp.estgweb.utils.RoleManager
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @author Jorge Machado
* @date 2/Mar/2008
* @time 10:27:25
* @see pt.estgp.estgweb.domain
*/
public
abstract
class
GenericUserImpl
extends
GenericUser
implements
IOwned
{
private
static
1.
5
.0/docs/api/java/util/logging/Logger.html">
Logger
logger =
1.
5
.0/docs/api/java/util/logging/Logger.html">
Logger
.
getLogger
(
GenericUserImpl.
class
)
;
public
GenericUserImpl
(
)
{
}
public
1.
5
.0/docs/api/java/io/Serializable.html">
Serializable
getSerializable
(
)
{
return
getId
(
)
;
}
public
void
addRole
(
1.
5
.0/docs/api/java/lang/String.html">
String
role
)
{
setRoles
(
RoleManager.
addRole
(
super
.
getRoles
(
)
, role
)
)
;
}
public
void
removeRole
(
1.
5
.0/docs/api/java/lang/String.html">
String
role
)
{
setRoles
(
RoleManager.
removeRole
(
super
.
getRoles
(
)
, role
)
)
;
}
public
boolean
hasRole
(
1.
5
.0/docs/api/java/lang/String.html">
String
r
)
{
if
(
r ==
null
|| getRoles
(
)
==
null
|| getRoles
(
)
.
length
(
)
== 0
)
return
false
;
for
(
1.
5
.0/docs/api/java/lang/String.html">
String
role : RoleManager.
getRolesFromSerial
(
getRoles
(
)
)
)
{
if
(
role.
equals
(
r
)
)
return
true
;
}
return
false
;
}
public
boolean
hasRolePrefix
(
1.
5
.0/docs/api/java/lang/String.html">
String
r
)
{
if
(
r ==
null
|| getRoles
(
)
==
null
|| getRoles
(
)
.
length
(
)
== 0
)
return
false
;
for
(
1.
5
.0/docs/api/java/lang/String.html">
String
role : RoleManager.
getRolesFromSerial
(
getRoles
(
)
)
)
{
if
(
role.
startsWith
(
r
)
)
return
true
;
}
return
false
;
}
public
boolean
hasRole
(
List
<
String
>
roles
)
{
return
RoleManagerDomain.
hasRole
(
this
, roles
)
;
}
public
GenericUser getOwner
(
)
{
return
this
;
}
/**
* @return a list of role Strings
*/
public
List
<
String
>
getOwnerRoles
(
)
{
return
getRolesList
(
)
;
}
/**
* Not implemented here
* @return null
*/
public
1.
5
.0/docs/api/java/lang/String.html">
String
getChoosedOwnerRole
(
)
{
logger.
warn
(
"Invoke not implemented method in class:"
+ getClass
(
)
.
getName
(
)
)
;
return
null
;
}
public
List
<
String
>
getRolesList
(
)
{
return
RoleManager.
getRolesFromSerial
(
getRoles
(
)
)
;
}
public
boolean
isSuperuser
(
)
{
return
super
.
isSuperuser
(
)
|| hasRole
(
Globals.
SUPER_USER_ROLE
)
;
}
public
boolean
isAdmin
(
)
{
return
hasRole
(
Globals.
ADMIN_ROLE
)
;
}
public
boolean
isSuperuserOrAdmin
(
)
{
return
isSuperuser
(
)
|| isAdmin
(
)
;
}
public
1.
5
.0/docs/api/java/lang/String.html">
String
getRolesDescription
(
HttpServletRequest request,
1.
5
.0/docs/api/java/lang/String.html">
String
separator
)
{
1.
5
.0/docs/api/java/lang/String.html">
String
sep =
""
;
1.
5
.0/docs/api/java/lang/StringBuilder.html">
StringBuilder
strBuilder =
new
1.
5
.0/docs/api/java/lang/StringBuilder.html">
StringBuilder
(
)
;
for
(
1.
5
.0/docs/api/java/lang/String.html">
String
role : getRolesList
(
)
)
{
if
(
!
role.
equals
(
Globals.
SUPER_USER_ROLE
)
)
{
strBuilder.
append
(
sep + MessageResources.
getMessage
(
request,
"user.role."
+ role
)
)
;
sep = separator
;
}
}
return
strBuilder.
toString
(
)
;
}
//Filipe Matos
//depois ir meter isto no globals
public
boolean
isTeacher
(
)
{
return
hasRole
(
"teacher"
)
;
}
public
boolean
isStudent
(
)
{
return
hasRole
(
"student"
)
;
}
}