Search in sources :

Example 6 with Entity

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();
}
Also used : Entity(com.qcadoo.model.api.Entity) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 7 with Entity

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);
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 8 with Entity

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);
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) UserDetails(org.springframework.security.core.userdetails.UserDetails) Calendar(java.util.Calendar) Date(java.util.Date) AbstractAuthenticationFailureEvent(org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent)

Example 9 with Entity

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;
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 10 with Entity

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;
}
Also used : Entity(com.qcadoo.model.api.Entity)

Aggregations

Entity (com.qcadoo.model.api.Entity)2833 FormComponent (com.qcadoo.view.api.components.FormComponent)514 Test (org.junit.Test)491 BigDecimal (java.math.BigDecimal)376 DataDefinition (com.qcadoo.model.api.DataDefinition)337 FieldComponent (com.qcadoo.view.api.components.FieldComponent)210 LookupComponent (com.qcadoo.view.api.components.LookupComponent)188 Date (java.util.Date)185 List (java.util.List)149 GridComponent (com.qcadoo.view.api.components.GridComponent)141 Map (java.util.Map)124 Autowired (org.springframework.beans.factory.annotation.Autowired)114 Service (org.springframework.stereotype.Service)112 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)105 Transactional (org.springframework.transaction.annotation.Transactional)101 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)100 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)95 Collectors (java.util.stream.Collectors)87 Lists (com.google.common.collect.Lists)75 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)75