Changes in Classes and Tables
UserData
net.comactivity.core.session.UserData
has two new fields, both with initial values null
.
private BufferedImage avatar
private AvatarType avatarType
avatar
The field avatar
has a BufferedImage
. It should be set in the User Manager's implementation of net.comactivity.core.authorization.UserManagement#complementUserData
. Default implementation exists in abstract class net.comactivity.core.authorization.AbstractUserManager
.
If avatarType
changes, net.comactivity.core.authorization.AbstractUserManager#refreshAvatar
should be called to set a new value in avatar
.
avatarType
The field avatarType
has an AvatarType
. It should be set in the User Manager's implementation of net.comactivity.core.authorization.UserManagement#getUser
. There's a fallback in net.comactivity.core.authorization.UserManagement#complementUserData
, with a default implementation in abstract class net.comactivity.core.authorization.AbstractUserManager
.
EnvUsers
Table CACORE.EnvUsers
has a new column, AvatarType
.
Customizations and Guides
Setting Up Gravatar
Users that want to use Gravatars will have to create accounts with the same email address as their user account has.
User Upload of Local Avatar Images
Users can upload their own avatar images to be used with avatar type local
. The file format has to be PNG
, unless set in sitedef
with property portal.user.avatar.images.format
. The uploaded image file will be stored at the file location $PersistanceRoot/Avatars
, or location set with portal.user.avatar.images.location
. The name will be user's login name, and set file format as extension. Uploaded files will overwrite previously saved files without warning or notification.
Custom Avatar Service
The Custom Avatar Service is available for customer specific implementations. The service has to setup like a regular ApplicationService
and implement net.comactivity.core.avatar.AvatarService
.
Application Service Setup
Example: Services/CustomAvatarService.service
<Service id="CustomAvatarService" model="singleton" interface="net.comactivity.core.avatar.AvatarService">
<Implementation class="solutions.company.cust.services.impl.CustomAvatarService"/>
</Service>
Example: solutions.company.cust.services.impl.CustomAvatarService
public class CustomAvatarService implements AvatarService {
@Override
public void init() {
}
@Override
public void destroy() {
}
@Override
public Optional<BufferedImage> getAvatarImage(UserData userData) {
String format = SystemWorkspace.getSite().getPortalUserAvatarImagesFormat();
try {
URL url = new URL("https://cust.company.solutions/employees/" + userData.getEMail() + "." + format);
return Optional.ofNullable(ImageIO.read(url));
} catch (IOException e) {
return Optional.empty();
}
}
}
References
New Site Definition Properties
<Property name="portal.user.avatar.enabled" value="true"/>
<!-- Possible values are true and false. Default value is false.-->
<Property name="portal.user.avatar.type.default" value="local"/>
<!-- Possible values are gravatar, local, and custom. Default value is local.-->
<Property name="portal.user.avatar.images.location" value="../../../../tomcat/avatars/"/>
<!-- Possible values are absolute or relative paths.-->
<Property name="portal.user.avatar.images.format" value="png"/>
<!-- Possible values are lowercase representations if file formats available to javax.imageio.ImageIO.-->
<!-- Possible values should include jpg, png, gif, bmp, and wbmp.-->
<Property name="portal.user.avatar.custom.service" value="CustomAvatarService"/>
<!-- Possible values are registered application services. -->