Beispiel #1
0
  public Object executeLogin() throws SQLException, ValidationException {
    if (StringUtils.isEmpty(this.getUsername())) {
      throw new ValidationException(new ValidationError("LoginForm.GENERAL_ERROR"));
    }
    if (StringUtils.isEmpty(this.getPassword())) {
      throw new ValidationException(new ValidationError("LoginForm.GENERAL_ERROR"));
    }
    SystemUserDAO systemUserDAO = DAOManager.getSystemUserDAO();
    SystemUserExample systemUserExample = new SystemUserExample();
    Criteria criteria = systemUserExample.createCriteria();
    criteria.andUsernameEqualTo(this.getUsername());
    List<SystemUser> list = systemUserDAO.selectSystemUserByExample(systemUserExample);
    if (list.isEmpty()) {
      throw new ValidationException(new ValidationError("LoginForm.GENERAL_ERROR"));
    }
    SystemUser exists = list.get(0);
    if (!exists.getPassword().equals(CryptoUtils.getHashedValue(this.getPassword()))) {
      throw new ValidationException(new ValidationError("LoginForm.GENERAL_ERROR"));
    }

    WebsiteUser user = new WebsiteUser();
    user.setId(exists.getId());
    Set<String> roles = new HashSet<String>();
    roles.add(Administrator.INSTANCE.getName());
    user.setRoles(roles);
    return user;
  }
Beispiel #2
0
 @Override
 protected byte[] loadInTransaction(int id, String type, int version, File local)
     throws SQLException {
   BlobDataDAO blobDataDAO = DAOManager.getBlobDataDAO();
   BlobDataExample blobDataExample = new BlobDataExample();
   blobDataExample.createCriteria().andIdEqualTo(id).andDatatypeEqualTo(type);
   List<BlobData> result = blobDataDAO.selectBlobDataByExampleWithBLOBs(blobDataExample);
   if (result.isEmpty()) {
     return null;
   } else {
     return result.get(0).getContent();
   }
 }