Package com.liferay.portal.auth

Examples of com.liferay.portal.auth.AuthException


        if ( company.getAuthType().equals( Company.AUTH_TYPE_EA ) ) {

            //Verify that the System User is not been use to log in inside the system
            if ( systemUser.getEmailAddress().equalsIgnoreCase( login ) ) {
                SecurityLogger.logInfo(this.getClass(),"An invalid attempt to login as a System User has been made  - you cannot login as the System User");
                throw new AuthException( "Unable to login as System User - you cannot login as the System User." );
            }

            authResult = UserManagerUtil.authenticateByEmailAddress( company.getCompanyId(), login, password );
            userId = UserManagerUtil.getUserId( company.getCompanyId(), login );

        } else {

            //Verify that the System User is not been use to log in inside the system
            if ( systemUser.getUserId().equalsIgnoreCase( login ) ) {
                SecurityLogger.logInfo(this.getClass(),"An invalid attempt to login as a System User has been made  - you cannot login as the System User");
                throw new AuthException( "Unable to login as System User - you cannot login as the System User." );
            }

            authResult = UserManagerUtil.authenticateByUserId( company.getCompanyId(), login, password );
        }

    try {
      PrincipalFinder principalFinder =
        (PrincipalFinder)InstancePool.get(
          PropsUtil.get(PropsUtil.PRINCIPAL_FINDER));

      userId = principalFinder.fromLiferay(userId);
    }
    catch (Exception e) {
    }

    if (authResult == Authenticator.SUCCESS) {
      User user = UserLocalManagerUtil.getUserById(userId);
     
      //DOTCMS-4943
      UserAPI userAPI = APILocator.getUserAPI();     
      boolean respectFrontend = WebAPILocator.getUserWebAPI().isLoggedToBackend(req);     
      Locale userSelectedLocale = (Locale)req.getSession().getAttribute(Globals.LOCALE_KEY);     
      user.setLanguageId(userSelectedLocale.toString());
      userAPI.save(user, userAPI.getSystemUser(), respectFrontend);

      ses.setAttribute(WebKeys.USER_ID, userId);
     
      //DOTCMS-6392
      PreviewFactory.setVelocityURLS(req);
     
      //set the host to the domain of the URL if possible if not use the default host
      //http://jira.dotmarketing.net/browse/DOTCMS-4475
      try{
        String domainName = req.getServerName();
        Host h = null;
        h = APILocator.getHostAPI().findByName(domainName, user, false);
        if(h == null || !UtilMethods.isSet(h.getInode())){
          h = APILocator.getHostAPI().findByAlias(domainName, user, false);
        }
        if(h != null && UtilMethods.isSet(h.getInode())){
          req.getSession().setAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID, h.getIdentifier());
        }else{
          req.getSession().setAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID, APILocator.getHostAPI().findDefaultHost(APILocator.getUserAPI().getSystemUser(), true).getIdentifier());
        }
      }catch (DotSecurityException se) {
        req.getSession().setAttribute(com.dotmarketing.util.WebKeys.CMS_SELECTED_HOST_ID, APILocator.getHostAPI().findDefaultHost(APILocator.getUserAPI().getSystemUser(), true).getIdentifier());
      }
           
      ses.removeAttribute("_failedLoginName");
      Cookie idCookie = new Cookie(CookieKeys.ID,UserManagerUtil.encryptUserId(userId));
      idCookie.setPath("/");

     
      if (rememberMe) {
        idCookie.setMaxAge(31536000);
      }
      else {
        idCookie.setMaxAge(0);
      }
     


      res.addCookie(idCookie);

      EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGIN_EVENTS_PRE), req, res);
      EventsProcessor.process(PropsUtil.getArray(PropsUtil.LOGIN_EVENTS_POST), req, res);
     
    }

    if (authResult != Authenticator.SUCCESS) {
      //Logger.info(this, "An invalid attempt to login as " + login + " has been made from IP: " + req.getRemoteAddr());
      SecurityLogger.logInfo(this.getClass(),"An invalid attempt to login as " + login + " has been made from IP: " + req.getRemoteAddr());
      throw new AuthException();
    }
   
    //Logger.info(this, "User " + login + " has sucessfully login from IP: " + req.getRemoteAddr());
    SecurityLogger.logInfo(this.getClass(),"User " + login + " has sucessfully login from IP: " + req.getRemoteAddr());
  }
View Full Code Here

TOP

Related Classes of com.liferay.portal.auth.AuthException

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.