use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class SecurityServiceImpl method getCurrentUserId.
@Override
@Monitorable
public Long getCurrentUserId() {
SecurityContext context = getContext();
Authentication authentication = getAuthentication();
if (Objects.isNull(context) || Objects.isNull(authentication) || Objects.isNull(authentication.getName())) {
return null;
}
String userName = authentication.getName();
Entity user = getUserEntity(userName);
return user.getId();
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class SecurityServiceImpl method createNewToken.
@Override
public void createNewToken(final PersistentRememberMeToken persistentRememberMeToken) {
Entity persistentToken = getPersistentTokenDD().create();
persistentToken.setField(PersistentTokenFields.USER_NAME, persistentRememberMeToken.getUsername());
persistentToken.setField(PersistentTokenFields.SERIES, persistentRememberMeToken.getSeries());
persistentToken.setField(PersistentTokenFields.TOKEN, persistentRememberMeToken.getTokenValue());
persistentToken.setField(PersistentTokenFields.LAST_USED, persistentRememberMeToken.getDate());
getPersistentTokenDD().save(persistentToken);
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class SecurityServiceImpl method onApplicationEvent.
@Override
public void onApplicationEvent(final AbstractAuthenticationEvent event) {
if (!(event instanceof AbstractAuthenticationFailureEvent)) {
UserDetails userDetails = (UserDetails) event.getAuthentication().getPrincipal();
Entity user = dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).find().add(SearchRestrictions.eq(UserFields.USER_NAME, userDetails.getUsername())).uniqueResult();
Calendar now = Calendar.getInstance();
now.add(Calendar.DAY_OF_YEAR, -1);
if (Objects.isNull(user.getField(UserFields.LAST_ACTIVITY)) || now.getTime().after(user.getDateField(UserFields.LAST_ACTIVITY))) {
user.setField(UserFields.LAST_ACTIVITY, new Date());
if (Objects.nonNull(request)) {
user.setField(UserFields.IP_ADDRESS, getClientIP());
}
dataDefinitionService.get(QcadooSecurityConstants.PLUGIN_IDENTIFIER, QcadooSecurityConstants.MODEL_USER).save(user);
}
}
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class SecurityServiceImpl method getCurrentUserOrQcadooBotName.
@Override
public String getCurrentUserOrQcadooBotName() {
String userName = getCurrentUserName();
if (Objects.isNull(userName)) {
Entity user = getAndCheckUserEntity(L_QCADOO_BOT);
userName = user.getStringField(UserFields.USER_NAME);
}
return userName;
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class SecurityServiceImpl method getCurrentUserOrQcadooBotId.
@Override
public Long getCurrentUserOrQcadooBotId() {
Long userId = getCurrentUserId();
if (Objects.isNull(userId)) {
Entity user = getAndCheckUserEntity(L_QCADOO_BOT);
userId = user.getId();
}
return userId;
}
Aggregations