Class SecurityServiceImpl
- java.lang.Object
-
- org.craftercms.studio.impl.v1.service.security.SecurityServiceImpl
-
- All Implemented Interfaces:
SecurityService
public class SecurityServiceImpl extends Object implements SecurityService
- Author:
- Dejan Brkic
-
-
Field Summary
Fields Modifier and Type Field Description protected AuditServiceInternal
auditServiceInternal
protected com.google.common.cache.Cache<String,PermissionsConfigTO>
cache
protected ConfigurationService
configurationService
protected ContentService
contentService
protected ContentTypeService
contentTypeService
protected org.springframework.mail.javamail.JavaMailSender
emailService
protected org.springframework.mail.javamail.JavaMailSender
emailServiceNoAuth
protected org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig>
freeMarkerConfig
protected GeneralLockService
generalLockService
protected GroupService
groupService
protected SiteService
siteService
protected StudioConfiguration
studioConfiguration
protected UserServiceInternal
userServiceInternal
-
Constructor Summary
Constructors Constructor Description SecurityServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addGlobalGroupRoles(Set<String> roles, List<String> groups, PermissionsConfigTO rolesConfig)
protected void
addGlobalUserRoles(String user, Set<String> roles, PermissionsConfigTO rolesConfig)
protected void
addGroupRoles(Set<String> roles, String site, List<String> groups, PermissionsConfigTO rolesConfig)
get roles by groupsprotected void
addUserRoles(Set<String> roles, String site, String user)
add user roles@javax.validation.Valid boolean
changePassword(String username, String current, String newPassword)
Change passwordint
getAllUsersTotal()
Get all usersAuditServiceInternal
getAuditServiceInternal()
org.springframework.security.core.Authentication
getAuthentication()
Returns theAuthentication
for the current user or null if not user is authenticated.ConfigurationService
getConfigurationService()
ContentService
getContentService()
ContentTypeService
getContentTypeService()
String
getCurrentUser()
Returns the username of the current user OR NULL if no user is authenticatedString
getDefaultFromAddress()
org.springframework.mail.javamail.JavaMailSender
getEmailService()
org.springframework.mail.javamail.JavaMailSender
getEmailServiceNoAuth()
org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig>
getFreeMarkerConfig()
GeneralLockService
getGeneralLockService()
String
getGlobalConfigPath()
String
getGlobalPermissionsFileName()
String
getGlobalRoleMappingsFileName()
GroupService
getGroupService()
String
getPermissionsFileName()
protected String
getPermissionsKey(String site, String filename)
String
getRoleMappingsFileName()
protected Map<String,List<String>>
getRoles(List<org.dom4j.Node> nodes, Map<String,List<String>> rolesMap)
int
getSessionTimeout()
SiteService
getSiteService()
StudioConfiguration
getStudioConfiguration()
String
getSystemSite()
@Valid Set<String>
getUserPermissions(String site, String path, String user, List<String> groups)
@Valid Set<String>
getUserPermissions(String site, String path, List<String> groups)
@Valid Map<String,Object>
getUserProfile(String user)
Map<String,Object>
getUserProfileByGitName(String gitName)
Get user by git name.@Valid Set<String>
getUserRoles(String site)
@Valid Set<String>
getUserRoles(String site, String user)
@Valid Set<String>
getUserRoles(String site, String user, boolean includeGlobal)
UserServiceInternal
getUserServiceInternal()
boolean
isAuthenticatedSMTP()
@javax.validation.Valid boolean
isSiteAdmin(String username, String site)
Check if given user is site adminprotected PermissionsConfigTO
loadConfiguration(String site, String filename)
protected PermissionsConfigTO
loadGlobalPermissionsConfiguration()
protected PermissionsConfigTO
loadGlobalRolesConfiguration()
protected void
loadPermissions(String siteId, org.dom4j.Element root, PermissionsConfigTO config)
protected void
loadRoles(org.dom4j.Element root, PermissionsConfigTO config)
protected Set<String>
populateUserGlobalPermissions(String path, Set<String> roles, PermissionsConfigTO permissionsConfig)
protected Set<String>
populateUserPermissions(String site, String path, Set<String> roles, PermissionsConfigTO permissionsConfig)
populate user permissions@javax.validation.Valid boolean
resetPassword(String username, String newPassword)
Reset user passwordvoid
setAuditServiceInternal(AuditServiceInternal auditServiceInternal)
void
setCache(com.google.common.cache.Cache<String,PermissionsConfigTO> cache)
void
setConfigurationService(ConfigurationService configurationService)
void
setContentService(ContentService contentService)
void
setContentTypeService(ContentTypeService contentTypeService)
void
setEmailService(org.springframework.mail.javamail.JavaMailSender emailService)
void
setEmailServiceNoAuth(org.springframework.mail.javamail.JavaMailSender emailServiceNoAuth)
void
setFreeMarkerConfig(org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig> freeMarkerConfig)
void
setGeneralLockService(GeneralLockService generalLockService)
void
setGroupService(GroupService groupService)
void
setSiteService(SiteService siteService)
void
setStudioConfiguration(StudioConfiguration studioConfiguration)
void
setUserServiceInternal(UserServiceInternal userServiceInternal)
@javax.validation.Valid boolean
userExists(String username)
Check if user exists
-
-
-
Field Detail
-
contentTypeService
protected ContentTypeService contentTypeService
-
contentService
protected ContentService contentService
-
generalLockService
protected GeneralLockService generalLockService
-
studioConfiguration
protected StudioConfiguration studioConfiguration
-
emailService
protected org.springframework.mail.javamail.JavaMailSender emailService
-
emailServiceNoAuth
protected org.springframework.mail.javamail.JavaMailSender emailServiceNoAuth
-
freeMarkerConfig
protected org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig> freeMarkerConfig
-
groupService
protected GroupService groupService
-
userServiceInternal
protected UserServiceInternal userServiceInternal
-
configurationService
protected ConfigurationService configurationService
-
auditServiceInternal
protected AuditServiceInternal auditServiceInternal
-
siteService
protected SiteService siteService
-
cache
protected com.google.common.cache.Cache<String,PermissionsConfigTO> cache
-
-
Method Detail
-
getCurrentUser
public String getCurrentUser()
Description copied from interface:SecurityService
Returns the username of the current user OR NULL if no user is authenticated- Specified by:
getCurrentUser
in interfaceSecurityService
- Returns:
- current user
-
getUserProfile
@Valid public @Valid Map<String,Object> getUserProfile(String user) throws ServiceLayerException, UserNotFoundException
- Specified by:
getUserProfile
in interfaceSecurityService
- Throws:
ServiceLayerException
UserNotFoundException
-
getUserProfileByGitName
public Map<String,Object> getUserProfileByGitName(String gitName) throws ServiceLayerException, UserNotFoundException
Description copied from interface:SecurityService
Get user by git name. Special use case because git stores user as string of first and last name separated by ' '- Specified by:
getUserProfileByGitName
in interfaceSecurityService
- Parameters:
gitName
- first and last name separated with ' '- Returns:
- user
- Throws:
ServiceLayerException
- general service errorUserNotFoundException
- user not found
-
getUserPermissions
@Valid public @Valid Set<String> getUserPermissions(String site, String path, List<String> groups)
- Specified by:
getUserPermissions
in interfaceSecurityService
-
getUserPermissions
@Valid public @Valid Set<String> getUserPermissions(String site, String path, String user, List<String> groups)
- Specified by:
getUserPermissions
in interfaceSecurityService
-
addGlobalUserRoles
protected void addGlobalUserRoles(String user, Set<String> roles, PermissionsConfigTO rolesConfig)
-
addGlobalGroupRoles
protected void addGlobalGroupRoles(Set<String> roles, List<String> groups, PermissionsConfigTO rolesConfig)
-
populateUserGlobalPermissions
protected Set<String> populateUserGlobalPermissions(String path, Set<String> roles, PermissionsConfigTO permissionsConfig)
-
addUserRoles
protected void addUserRoles(Set<String> roles, String site, String user)
add user roles- Parameters:
roles
-site
-user
-
-
getUserRoles
@Valid public @Valid Set<String> getUserRoles(String site)
- Specified by:
getUserRoles
in interfaceSecurityService
-
getUserRoles
@Valid public @Valid Set<String> getUserRoles(String site, String user)
- Specified by:
getUserRoles
in interfaceSecurityService
-
getUserRoles
@Valid public @Valid Set<String> getUserRoles(String site, String user, boolean includeGlobal)
- Specified by:
getUserRoles
in interfaceSecurityService
-
addGroupRoles
protected void addGroupRoles(Set<String> roles, String site, List<String> groups, PermissionsConfigTO rolesConfig)
get roles by groups- Parameters:
site
-groups
-rolesConfig
-
-
populateUserPermissions
protected Set<String> populateUserPermissions(String site, String path, Set<String> roles, PermissionsConfigTO permissionsConfig)
populate user permissions- Parameters:
site
-path
-roles
-permissionsConfig
-
-
loadConfiguration
protected PermissionsConfigTO loadConfiguration(String site, String filename)
-
loadRoles
protected void loadRoles(org.dom4j.Element root, PermissionsConfigTO config)
-
getRoles
protected Map<String,List<String>> getRoles(List<org.dom4j.Node> nodes, Map<String,List<String>> rolesMap)
-
loadPermissions
protected void loadPermissions(String siteId, org.dom4j.Element root, PermissionsConfigTO config)
-
loadGlobalPermissionsConfiguration
protected PermissionsConfigTO loadGlobalPermissionsConfiguration()
-
loadGlobalRolesConfiguration
protected PermissionsConfigTO loadGlobalRolesConfiguration()
-
getAllUsersTotal
public int getAllUsersTotal() throws ServiceLayerException
Description copied from interface:SecurityService
Get all users- Specified by:
getAllUsersTotal
in interfaceSecurityService
- Returns:
- number of all users
- Throws:
ServiceLayerException
- general service error
-
changePassword
@Valid public @javax.validation.Valid boolean changePassword(String username, String current, String newPassword) throws PasswordDoesNotMatchException, UserExternallyManagedException, ServiceLayerException
Description copied from interface:SecurityService
Change password- Specified by:
changePassword
in interfaceSecurityService
- Parameters:
username
- usernamecurrent
- current passwordnewPassword
- new password- Returns:
- true if user's password is successfully changed
- Throws:
PasswordDoesNotMatchException
- password does not match stored passwordUserExternallyManagedException
- user is externally managedServiceLayerException
- general service error
-
resetPassword
@Valid public @javax.validation.Valid boolean resetPassword(String username, String newPassword) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException
Description copied from interface:SecurityService
Reset user password- Specified by:
resetPassword
in interfaceSecurityService
- Parameters:
username
- usernamenewPassword
- new password- Returns:
- true if user's password is successfully reset
- Throws:
UserNotFoundException
- user not foundUserExternallyManagedException
- user externally managedServiceLayerException
- general service error
-
isSiteAdmin
@Valid public @javax.validation.Valid boolean isSiteAdmin(String username, String site)
Description copied from interface:SecurityService
Check if given user is site admin- Specified by:
isSiteAdmin
in interfaceSecurityService
- Parameters:
username
- usersite
- site identifier- Returns:
- true if user belongs to admin group
-
userExists
@Valid public @javax.validation.Valid boolean userExists(String username) throws ServiceLayerException
Description copied from interface:SecurityService
Check if user exists- Specified by:
userExists
in interfaceSecurityService
- Parameters:
username
- username- Returns:
- true if user exists
- Throws:
ServiceLayerException
- general service error
-
getAuthentication
public org.springframework.security.core.Authentication getAuthentication()
Description copied from interface:SecurityService
Returns theAuthentication
for the current user or null if not user is authenticated.- Specified by:
getAuthentication
in interfaceSecurityService
- Returns:
- authentication
-
getRoleMappingsFileName
public String getRoleMappingsFileName()
-
getPermissionsFileName
public String getPermissionsFileName()
-
getGlobalConfigPath
public String getGlobalConfigPath()
-
getGlobalRoleMappingsFileName
public String getGlobalRoleMappingsFileName()
-
getGlobalPermissionsFileName
public String getGlobalPermissionsFileName()
-
getSessionTimeout
public int getSessionTimeout()
-
isAuthenticatedSMTP
public boolean isAuthenticatedSMTP()
-
getDefaultFromAddress
public String getDefaultFromAddress()
-
getSystemSite
public String getSystemSite()
-
getContentTypeService
public ContentTypeService getContentTypeService()
-
setContentTypeService
public void setContentTypeService(ContentTypeService contentTypeService)
-
getContentService
public ContentService getContentService()
-
setContentService
public void setContentService(ContentService contentService)
-
getGeneralLockService
public GeneralLockService getGeneralLockService()
-
setGeneralLockService
public void setGeneralLockService(GeneralLockService generalLockService)
-
getStudioConfiguration
public StudioConfiguration getStudioConfiguration()
-
setStudioConfiguration
public void setStudioConfiguration(StudioConfiguration studioConfiguration)
-
getEmailService
public org.springframework.mail.javamail.JavaMailSender getEmailService()
-
setEmailService
public void setEmailService(org.springframework.mail.javamail.JavaMailSender emailService)
-
getEmailServiceNoAuth
public org.springframework.mail.javamail.JavaMailSender getEmailServiceNoAuth()
-
setEmailServiceNoAuth
public void setEmailServiceNoAuth(org.springframework.mail.javamail.JavaMailSender emailServiceNoAuth)
-
getFreeMarkerConfig
public org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig> getFreeMarkerConfig()
-
setFreeMarkerConfig
public void setFreeMarkerConfig(org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig> freeMarkerConfig)
-
getGroupService
public GroupService getGroupService()
-
setGroupService
public void setGroupService(GroupService groupService)
-
getUserServiceInternal
public UserServiceInternal getUserServiceInternal()
-
setUserServiceInternal
public void setUserServiceInternal(UserServiceInternal userServiceInternal)
-
getConfigurationService
public ConfigurationService getConfigurationService()
-
setConfigurationService
public void setConfigurationService(ConfigurationService configurationService)
-
getAuditServiceInternal
public AuditServiceInternal getAuditServiceInternal()
-
setAuditServiceInternal
public void setAuditServiceInternal(AuditServiceInternal auditServiceInternal)
-
getSiteService
public SiteService getSiteService()
-
setSiteService
public void setSiteService(SiteService siteService)
-
setCache
public void setCache(com.google.common.cache.Cache<String,PermissionsConfigTO> cache)
-
-