Package org.jayasoft.woj.common.model

Examples of org.jayasoft.woj.common.model.User


    public AbstractAuthentificationService() {
    }

    public Authentification authenticate(String userName, String userPassword, String computerIdent, String pluginId) {
        try {
                User u = null;
                if (OK_PASS.equals(userPassword)) {
                    u = WOJServer.getInstance().getDataService().getUserDao().getUser(userName);
                } else {
                    u = WOJServer.getInstance().getDataService().getUserDao().getUser(userName, userPassword);
                }
                if (u != null) {
                  if(u.getStatus() != User.VALID) {
                    //email not verified within 48 hours its registration => acount blocked
                    if(!u.isMailVerified()) {
                      if(u.getTimestamp()+TimeUtil.MILLISECONDS_A_DAY*2 < TimeUtil.getGMTMillis()) {
                        LOGGER.info("User :" +u.getLogin() + " has not verified its email:" + u.getEmail() );
                        return newAuthFailed(AuthFailed.ACCOUNT_BLOCKED, "Email has not been verified within allowed delay");
                      }
                    } else {
                      return newAuthFailed(AuthFailed.ACCOUNT_BLOCKED, "Your account has been blocked. Please contact us (contact@worldofjava.org)");
                    }
                  }
                    if(!doUserNeedsLicense(u) || userHasValidLicence(u)) {
                        //TODO move this code to user and grab all groups id
                        List groups = Collections.EMPTY_LIST;
                        if(u.getGroup() != null) {
                            groups = Collections.singletonList(new Long(u.getGroup().getId()));
                        }

                        PrincipalRight pr = WOJServer.getInstance().getDataService().getRightsDao().getConsolidatedPrincipalRight(new Long(u.getId()), groups);
                        Visibility publishVisibility = pr == null ? Visibility.DEFAULT_VISIBILITY : pr.getPublishVisibility();
                       
                        UAK uak = new UAK(userName, userPassword, computerIdent, new Long(u.getId()), groups, publishVisibility, pluginId);
                        if (!uak.isAdmin() && !uak.isServer()) {
                            if (!WOJServer.getInstance().getDataService().getLoginTraceDao().login(u, computerIdent)) {
                                LOGGER.info("User : " + u.getLogin() + " has already used a trial on a different computer, login refused");
                                return newAuthFailed(AuthFailed.ERROR, "you have already used a trial license on this computer");
                            }
                        }
                        if (SecurityHelper.isAlreadyLogged(uak)) {
                            LOGGER.info("User : " + u.getLogin() + " is already logged on a different computer, login refused");
                            return newAuthFailed(AuthFailed.ERROR, "your account is already in use on another computer");
                        }

                        computeUserKey(uak);
                       
                        AuthSuccessfull success = new AuthSuccessfull(uak);
                        success.setLicenceExpirationTime(new Long(u.getValidUntil()));
                        //TODO check message
                        success.setHasMessage(false);
                        //TODO get user server if set in user if not use random or nearest one
                        if(StringUtils.isEmpty(u.getWojServer())) {
                          success.setServer(WOJServer.getInstance().getServer().getFullUrlString());
                        } else {
                          success.setServer(u.getWojServer());
                        }
                        //add server version in response
                        success.addExtraParameters(Authentification.SERVER_VERSION, WOJServer.getVersion());
                        if (WOJServer.getInstance().isEnterpriseEdition()) {
                            try {
View Full Code Here


            // we try to get information from the request
            userName = request.getParameter(Parameters.SECURITY.USER_NAME);
            userPass = request.getParameter(Parameters.SECURITY.USER_PASS);
        }
        if (userName!=null && userPass!=null) {
            User user = WOJServer.getInstance().getDataService().getUserDao().getUser(userName, userPass);
            if (s!=null) {
                s.setAttribute(USER, user);
            }
            LOGGER.debug("User found: " + user);
            return user;
View Full Code Here

    }

    public void addUser(User[] usrs) {
        UserDao dao= WOJServer.getInstance().getDataService().getUserDao();
        for (int i = 0; i < usrs.length; i++) {
            User usr = usrs[i];
            try {
        if(usr.getId() == 0 && WOJServer.getInstance().isEnterpriseEdition()) {
          dao.insertNewUser(usr);
        } else {
          dao.insert(usr);
        }
      } catch (DataIntegrityViolationException e) {
        throw new IllegalArgumentException("Duplicate user:"+usr.getLogin());
      }
        }
        LOGGER.info(usrs.length + "groups successfully added.");
    }
View Full Code Here

    }

    public void updateUser(User[] usrs) {
        UserDao dao= WOJServer.getInstance().getDataService().getUserDao();
        for (int i = 0; i < usrs.length; i++) {
            User usr = usrs[i];
            dao.update(usr);
        }
        LOGGER.info(usrs.length + "groups successfully updated.");
    }
View Full Code Here

        LOGGER.info(usrs.length + "groups successfully updated.");
    }

  public User getUser(String login) {
        UserDao dao= WOJServer.getInstance().getDataService().getUserDao();
        User user = dao.getUser(login);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Finded user for login " + login + ": " + user);
        }
    return user;
  }
View Full Code Here

    /**
     * Test the DTOHelper.copy method;
     *
     */
    public void testCopy() {
        User src = new User("usr1", "apass", "usr1@jayasoft.fr");
        User dest1 = new User();
       
        assertTrue(BeanHelper.copy(src, dest1, User.class));
//        assertEquals(src, dest1);
    }
View Full Code Here

    DataSource getDataSource() {
        return DSManager.getInstance().getUserDS();
    }
       
    protected Object[] getInsertParameters(Object o) {
        User user = (User) o;
        List parameters = new ArrayList();
        long id = user.getId();
    parameters.add(new Long(id));
        parameters.add(user.getLogin());
        parameters.add(user.getPassword());
        parameters.add(user.getEmail());
        parameters.add(new Long(user.getValidUntil()));
        parameters.add(user.getWojServer());
        parameters.add(user.getGroup() != null ? new Long(user.getGroup().getId()):null);
        Long timeStamp = new Long(System.currentTimeMillis());
        parameters.add(new Long(user.getCreationTime()));
        parameters.add(timeStamp);
        parameters.add(new Integer(user.getStatus()));
        parameters.add(new Integer(user.getUseTrialLicense()?1:0));
        return parameters.toArray();
    }
View Full Code Here

        parameters.add(new Integer(user.getUseTrialLicense()?1:0));
        return parameters.toArray();
    }
   
    protected Object[] getUpdateParameters(Object o) {
        User user = (User) o;
        List parameters = new ArrayList();
        parameters.add(user.getLogin());
        parameters.add(user.getPassword());
        parameters.add(user.getEmail());
        parameters.add(new Long(user.getValidUntil()));
        parameters.add(user.getWojServer());
        parameters.add(user.getGroup() != null ? new Long(user.getGroup().getId()):null);
        parameters.add(new Long(System.currentTimeMillis()));
        parameters.add(new Integer(user.getStatus()));
        parameters.add(new Integer(user.getUseTrialLicense()?1:0));
        parameters.add(new Long(user.getId()));
        return parameters.toArray();
    }
View Full Code Here

        parameters.add(new Long(user.getId()));
        return parameters.toArray();
    }

    protected Object[] getDeleteParameters(Object o) {
        User user = (User) o;
        List parameters = new ArrayList();
        parameters.add(new Long(user.getId()));
        return parameters.toArray();
    }
View Full Code Here

    public static void rememberContext(HttpServletRequest request, String context) {
        request.getSession().setAttribute(Params.GENERAL.SESSION.CONTEXT, context);
    }
   
    public static boolean isAdmin(HttpServletRequest request) {
        User u = (User) request.getSession().getAttribute(Params.LOGIN.SESSION.USER);
        return u != null && u.getGroup() != null && u.getGroup().getId() == UAK.ADMIN_GROUP_ID;
    }
View Full Code Here

TOP

Related Classes of org.jayasoft.woj.common.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.