Exemplo n.º 1
0
 private void checkSession(Channel channel) {
   String cookieString = request.headers().get(HttpHeaderNames.COOKIE);
   if (cookieString != null) {
     Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieString);
     if (!cookies.isEmpty()) {
       for (Cookie elt : cookies) {
         if (elt.name().equalsIgnoreCase(R66SESSION + Configuration.configuration.getHOST_ID())) {
           logger.debug("Found session: " + elt);
           admin = elt;
           R66Session session = sessions.get(admin.value());
           if (session != null) {
             authentHttp = session;
             authentHttp.setStatus(73);
           } else {
             admin = null;
             continue;
           }
         } else if (elt.name().equalsIgnoreCase(I18NEXT)) {
           logger.debug("Found i18next: " + elt);
           lang = elt.value();
         }
       }
     }
   }
   if (admin == null) {
     logger.debug("NoSession: " + uriRequest + ":{}", admin);
   }
 }
Exemplo n.º 2
0
 private void clearSession() {
   if (admin != null) {
     R66Session lsession = sessions.remove(admin.value());
     admin = null;
     if (lsession != null) {
       lsession.setStatus(75);
       lsession.clear();
     }
   }
 }
Exemplo n.º 3
0
 private void checkAuthent(ChannelHandlerContext ctx) {
   newSession = true;
   if (request.method() == HttpMethod.GET) {
     String logon = Logon();
     logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(), "");
     responseContent.append(logon);
     clearSession();
     writeResponse(ctx);
     return;
   } else if (request.method() == HttpMethod.POST) {
     getParams();
     if (params == null) {
       String logon = Logon();
       logon =
           logon.replaceAll(
               REPLACEMENT.XXXERRORMESGXXX.toString(),
               Messages.getString("HttpSslHandler.EmptyLogin"));
       responseContent.append(logon);
       clearSession();
       writeResponse(ctx);
       return;
     }
   }
   boolean getMenu = false;
   if (params.containsKey("Logon")) {
     String name = null, password = null;
     List<String> values = null;
     if (!params.isEmpty()) {
       // get values
       if (params.containsKey("name")) {
         values = params.get("name");
         if (values != null) {
           name = values.get(0);
           if (name == null || name.isEmpty()) {
             getMenu = true;
           }
         }
       } else {
         getMenu = true;
       }
       // search the nb param
       if ((!getMenu) && params.containsKey("passwd")) {
         values = params.get("passwd");
         if (values != null) {
           password = values.get(0);
           if (password == null || password.isEmpty()) {
             getMenu = true;
           } else {
             getMenu = false;
           }
         } else {
           getMenu = true;
         }
       } else {
         getMenu = true;
       }
     } else {
       getMenu = true;
     }
     if (!getMenu) {
       logger.debug(
           "Name="
               + name
               + " vs "
               + name.equals(Configuration.configuration.getADMINNAME())
               + " Passwd vs "
               + Arrays.equals(
                   password.getBytes(WaarpStringUtils.UTF8),
                   Configuration.configuration.getSERVERADMINKEY()));
       if (name.equals(Configuration.configuration.getADMINNAME())
           && Arrays.equals(
               password.getBytes(WaarpStringUtils.UTF8),
               Configuration.configuration.getSERVERADMINKEY())) {
         authentHttp
             .getAuth()
             .specialNoSessionAuth(true, Configuration.configuration.getHOST_ID());
         authentHttp.setStatus(70);
       } else {
         getMenu = true;
       }
       if (!authentHttp.isAuthenticated()) {
         authentHttp.setStatus(71);
         logger.debug("Still not authenticated: {}", authentHttp);
         getMenu = true;
       }
     }
   } else {
     getMenu = true;
   }
   if (getMenu) {
     String logon = Logon();
     logon =
         logon.replaceAll(
             REPLACEMENT.XXXERRORMESGXXX.toString(),
             Messages.getString("HttpSslHandler.BadLogin"));
     responseContent.append(logon);
     clearSession();
     writeResponse(ctx);
   } else {
     String index = index();
     responseContent.append(index);
     clearSession();
     admin =
         new DefaultCookie(
             R66SESSION + Configuration.configuration.getHOST_ID(),
             Configuration.configuration.getHOST_ID() + Long.toHexString(random.nextLong()));
     sessions.put(admin.value(), this.authentHttp);
     authentHttp.setStatus(72);
     logger.debug("CreateSession: " + uriRequest + ":{}", admin);
     writeResponse(ctx);
   }
 }