Beispiel #1
0
 @Test
 public void testUnknowmParam() {
   Authenticate authenticate = new Authenticate(UNKNOW_PARAM);
   assertEquals("auth", authenticate.getParameter("unknown"));
   assertEquals("*****@*****.**", authenticate.getParameter("realm"));
   authenticate = new Authenticate(authenticate.toString());
   assertEquals("auth", authenticate.getParameter("unknown"));
 }
Beispiel #2
0
 @Test
 public void testToString() {
   Authenticate authenticate = new Authenticate(RFC2617);
   authenticate = new Authenticate(authenticate.toString());
   assertEquals("*****@*****.**", authenticate.getRealm());
   assertEquals("auth,auth-int", authenticate.getQop());
   assertEquals("dcd98b7102dd2f0e8b11d0f600bfb0c093", authenticate.getNonce());
   assertEquals("5ccc069c403ebaf9f0171e9517f40e41", authenticate.getOpaque());
   assertFalse(authenticate.isStale());
   assertEquals("Digest", authenticate.getScheme());
 }
Beispiel #3
0
  public synchronized void open(
      String host, int port, String username, String password, boolean ssl)
      throws IOException, ProtocolException {
    if (username == null || password == null) {
      Authenticate auth = getAuthenticator();

      if (auth != null) {
        if (username == null) {
          User user = auth.getUser(host, "pop3", null);

          if (user != null) {
            username = user.getUsername();
            password = user.getPassword();
          }
        } else {
          password = auth.getPassword(host, "pop3", username);
        }
      }
    }

    Socket socket =
        ssl ? SSLSocketFactory.getDefault().createSocket(host, port) : new Socket(host, port);

    in = new ReadLineInputStream(socket.getInputStream());
    out = socket.getOutputStream();

    checkLine(readLine());
    sendCommand("user " + username);
    sendCommand("pass " + password);

    String s = sendCommand("stat");

    try {
      messages = new Message[getNumberOfMessages(s)];
    } catch (NumberFormatException e) {
      close();
      throw e;
    }

    for (int i = 0; i < messages.length; ++i) {
      messages[i] = new Message(i + 1);
    }
  }
Beispiel #4
0
  public String runMacro(ExternalHTTPRequests httpReq, String parm) {
    Hashtable parms = parseParms(parm);
    String journalName = httpReq.getRequestParameter("JOURNAL");
    if (journalName == null) return " @break@";

    if (CMLib.journals().isArchonJournalName(journalName)) {
      MOB M = Authenticate.getAuthenticatedMob(httpReq);
      if ((M == null) || (!CMSecurity.isASysOp(M))) return " @break@";
    }

    String srch = httpReq.getRequestParameter("JOURNALMESSAGESEARCH");
    if (srch != null) srch = srch.toLowerCase();
    String last = httpReq.getRequestParameter("JOURNALMESSAGE");
    int cardinal = CMath.s_int(httpReq.getRequestParameter("JOURNALCARDINAL"));
    if (parms.containsKey("RESET")) {
      if (last != null) {
        httpReq.removeRequestParameter("JOURNALMESSAGE");
        httpReq.removeRequestParameter("JOURNALCARDINAL");
      }
      return "";
    }
    MOB M = Authenticate.getAuthenticatedMob(httpReq);
    cardinal++;
    JournalsLibrary.JournalEntry entry = null;
    List<JournalsLibrary.JournalEntry> msgs = JournalInfo.getMessages(httpReq, journalName);
    while ((entry == null)
        || (!CMLib.journals().canReadMessage(entry, srch, M, parms.contains("NOPRIV")))) {
      entry = JournalInfo.getNextEntry(msgs, last);
      if (entry == null) {
        httpReq.addRequestParameters("JOURNALMESSAGE", "");
        if (parms.containsKey("EMPTYOK")) return "<!--EMPTY-->";
        return " @break@";
      }
      last = entry.key;
    }
    entry.cardinal = cardinal;
    httpReq.addRequestParameters("JOURNALCARDINAL", "" + cardinal);
    httpReq.addRequestParameters("JOURNALMESSAGE", last);
    return "";
  }
Beispiel #5
0
  protected MMObjectNode getGroupOrUserNode(Parameters a) {
    MMObjectNode groupOrUser = getNode(a.getString(PARAMETER_GROUPORUSER));
    if (groupOrUser == null)
      throw new IllegalArgumentException(
          "There is no node with id '" + a.get(PARAMETER_GROUPORUSER) + "'");

    MMObjectBuilder parent = groupOrUser.getBuilder();
    MMObjectBuilder userBuilder = Authenticate.getInstance().getUserProvider().getUserBuilder();
    if (!(parent instanceof Groups || userBuilder.getClass().isInstance(parent))) {
      throw new IllegalArgumentException(
          "Node '" + a.get(PARAMETER_GROUPORUSER) + "' does not represent a group or a user");
    }
    return groupOrUser;
  }
Beispiel #6
0
 protected boolean isOwnNode(User user, MMObjectNode node) {
   return Authenticate.getInstance().getUserProvider().isOwnNode(user, node);
 }
Beispiel #7
0
  @Override
  public String runMacro(HTTPRequest httpReq, String parm) {
    final java.util.Map<String, String> parms = parseParms(parm);
    final String last = httpReq.getUrlParameter("JOURNAL");
    if (last == null) return " @break@";
    boolean securityOverride = false;
    if ((Thread.currentThread() instanceof CWThread)
        && CMath.s_bool(((CWThread) Thread.currentThread()).getConfig().getMiscProp("ADMIN"))
        && parms.containsKey("ALLFORUMJOURNALS")) securityOverride = true;

    final MOB M = Authenticate.getAuthenticatedMob(httpReq);
    if ((!securityOverride)
        && (CMLib.journals().isArchonJournalName(last))
        && ((M == null) || (!CMSecurity.isASysOp(M)))) return " @break@";

    final Clan setClan = CMLib.clans().getClan(httpReq.getUrlParameter("CLAN"));
    final JournalsLibrary.ForumJournal journal = CMLib.journals().getForumJournal(last, setClan);
    if (journal == null) return " @break@";

    final StringBuffer str = new StringBuffer("");
    if (parms.containsKey("ISSMTPFORWARD")) {
      @SuppressWarnings("unchecked")
      final TreeMap<String, JournalsLibrary.SMTPJournal> set =
          (TreeMap<String, JournalsLibrary.SMTPJournal>)
              Resources.getResource("SYSTEM_SMTP_JOURNALS");
      final JournalsLibrary.SMTPJournal entry =
          (set != null) ? set.get(last.toUpperCase().trim()) : null;
      final String email =
          ((M != null) && (M.playerStats() != null) && (M.playerStats().getEmail() != null))
              ? M.playerStats().getEmail()
              : "";
      str.append(
              ((entry != null) && (email.length() > 0)) ? Boolean.toString(entry.forward) : "false")
          .append(", ");
    }

    if (parms.containsKey("ISSMTPSUBSCRIBER")) {
      final Map<String, List<String>> lists =
          Resources.getCachedMultiLists("mailinglists.txt", true);
      final List<String> mylist = lists.get(last);
      str.append(
              ((mylist != null) && (M != null))
                  ? Boolean.toString(mylist.contains(M.Name()))
                  : "false")
          .append(", ");
    }

    if (parms.containsKey("SMTPADDRESS")) {
      @SuppressWarnings("unchecked")
      final TreeMap<String, JournalsLibrary.SMTPJournal> set =
          (TreeMap<String, JournalsLibrary.SMTPJournal>)
              Resources.getResource("SYSTEM_SMTP_JOURNALS");
      final JournalsLibrary.SMTPJournal entry =
          (set != null) ? set.get(last.toUpperCase().trim()) : null;
      if ((entry != null) && (entry.forward)) {
        str.append(entry.name.replace(' ', '_') + "@" + CMProps.getVar(CMProps.Str.MUDDOMAIN))
            .append(", ");
      }
    }

    if (parms.containsKey("CANADMIN") || parms.containsKey("ISADMIN"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.ADMIN)).append(", ");

    if (parms.containsKey("CANPOST"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.POST)).append(", ");

    if (parms.containsKey("CANREAD"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.READ)).append(", ");

    if (parms.containsKey("CANREPLY"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.REPLY)).append(", ");

    if (parms.containsKey("ADMINMASK")) str.append("" + journal.adminMask()).append(", ");

    if (parms.containsKey("READMASK")) str.append("" + journal.readMask()).append(", ");

    if (parms.containsKey("POSTMASK")) str.append("" + journal.postMask()).append(", ");

    if (parms.containsKey("REPLYMASK")) str.append("" + journal.replyMask()).append(", ");

    if (parms.containsKey("ID")) str.append("" + journal.NAME()).append(", ");

    if (parms.containsKey("NAME")) str.append("" + journal.NAME()).append(", ");

    if (parms.containsKey("EXPIRE")) str.append("").append(", ");

    final JournalsLibrary.JournalSummaryStats stats = CMLib.journals().getJournalStats(journal);
    if (stats == null) return " @break@";

    if (parms.containsKey("POSTS")) str.append("" + stats.posts).append(", ");

    if (parms.containsKey("THREADS")) str.append("" + stats.threads).append(", ");

    if (parms.containsKey("SHORTDESC")) str.append("" + stats.shortIntro).append(", ");

    if (parms.containsKey("LONGDESC")) str.append("" + stats.longIntro).append(", ");

    if (parms.containsKey("IMAGEPATH")) {
      if ((stats.imagePath == null) || (stats.imagePath.trim().length() == 0))
        str.append(L("images/lilcm.jpg")).append(", ");
      else str.append("" + stats.threads).append(", ");
    }

    String strstr = str.toString();
    if (strstr.endsWith(", ")) strstr = strstr.substring(0, strstr.length() - 2);
    return clearWebMacros(strstr);
  }
Beispiel #8
0
  public String runMacro(ExternalHTTPRequests httpReq, String parm) {
    if (!CMProps.getBoolVar(CMProps.SYSTEMB_MUDSTARTED))
      return CMProps.getVar(CMProps.SYSTEM_MUDSTATUS);

    Hashtable parms = parseParms(parm);
    String last = httpReq.getRequestParameter("PLAYER");
    if (last == null) return " @break@";
    if (last.length() > 0) {
      MOB M = CMLib.players().getLoadPlayer(last);
      if (M == null) {
        MOB authM = Authenticate.getAuthenticatedMob(httpReq);
        if ((authM != null) && (authM.Name().equalsIgnoreCase(last))) M = authM;
        else return " @break@";
      }

      boolean firstTime =
          (!httpReq.isRequestParameter("ACTION"))
              || (httpReq.getRequestParameter("ACTION")).equals("FIRSTTIME");
      StringBuffer str = new StringBuffer("");
      for (int i = 0; i < MOB.AUTODESC.length; i++) {
        if (parms.containsKey(MOB.AUTODESC[i])) {
          boolean set = CMath.isSet(M.getBitmap(), i);
          if (MOB.AUTOREV[i]) set = !set;
          str.append((set ? "ON" : "OFF") + ",");
        }
      }
      for (int i : CharStats.CODES.ALL()) {
        String stat = CharStats.CODES.NAME(i);
        if (!stat.equalsIgnoreCase("GENDER")) {
          CharStats C = M.charStats();
          if (parms.containsKey(stat)) {
            String old = httpReq.getRequestParameter(stat);
            if ((firstTime) || (old.length() == 0)) {
              if ((!CharStats.CODES.isBASE(i)) && (i != CharStats.STAT_GENDER))
                old = "" + C.getSave(i);
              else old = "" + C.getStat(i);
            }
            str.append(old + ", ");
          }
        }
      }
      for (int i : CharStats.CODES.ALL()) {
        String stat = CharStats.CODES.NAME(i);
        if (!stat.equalsIgnoreCase("GENDER")) {
          CharStats C = M.baseCharStats();
          if (parms.containsKey("BASE" + stat)) {
            String old = httpReq.getRequestParameter("BASE" + stat);
            if ((firstTime) || (old.length() == 0)) old = "" + C.getStat(i);
            str.append(old + ", ");
          }
        }
      }
      for (int i = 0; i < BASICS.length; i++) {
        if (parms.containsKey(BASICS[i])) {
          if (httpReq.isRequestParameter(BASICS[i]))
            str.append(httpReq.getRequestParameter(BASICS[i]) + ", ");
          else str.append(getBasic(M, i));
        }
      }
      if (parms.containsKey("RACE")) {
        String old = httpReq.getRequestParameter("RACE");
        if ((firstTime) || (old.length() == 0)) old = "" + M.baseCharStats().getMyRace().ID();
        for (Enumeration r = CMClass.races(); r.hasMoreElements(); ) {
          Race R2 = (Race) r.nextElement();
          str.append("<OPTION VALUE=\"" + R2.ID() + "\"");
          if (R2.ID().equals(old)) str.append(" SELECTED");
          str.append(">" + R2.name());
        }
      }
      if (parms.containsKey("DEITY")) {
        String old = httpReq.getRequestParameter("DEITY");
        if (firstTime) old = M.getWorshipCharID();
        str.append("<OPTION " + ((old.length() == 0) ? "SELECTED" : "") + " VALUE=\"\">Godless");
        for (Enumeration e = CMLib.map().deities(); e.hasMoreElements(); ) {
          Deity E = (Deity) e.nextElement();
          str.append("<OPTION VALUE=\"" + E.Name() + "\"");
          if (E.Name().equalsIgnoreCase(old)) str.append(" SELECTED");
          str.append(">" + E.Name());
        }
      }
      if (parms.containsKey("TITLELIST")) {
        if (M.playerStats() != null) {
          int b = 0;
          Vector titles = new Vector();
          if (firstTime) CMParms.addToVector(M.playerStats().getTitles(), titles);
          else
            while (httpReq.isRequestParameter("TITLE" + b)) {
              String B = httpReq.getRequestParameter("TITLE" + b);
              if ((B != null) && (B.trim().length() > 0)) titles.addElement(B);
              b++;
            }
          for (b = 0; b < titles.size(); b++) {
            String B = (String) titles.elementAt(b);
            if (B != null)
              str.append(
                  "<INPUT TYPE=TEXT NAME=TITLE"
                      + b
                      + " SIZE="
                      + B.length()
                      + " VALUE=\""
                      + CMStrings.replaceAll(B, "\"", "&quot;")
                      + "\"><BR>");
          }
          str.append("<INPUT TYPE=TEXT NAME=TITLE" + titles.size() + " SIZE=60 VALUE=\"\">");
        }
      }
      if (parms.containsKey("CLAN")) {
        String old = httpReq.getRequestParameter("CLAN");
        if (firstTime) old = M.getClanID();
        str.append("<OPTION " + ((old.length() == 0) ? "SELECTED" : "") + " VALUE=\"\">Clanless");
        for (Enumeration e = CMLib.clans().allClans(); e.hasMoreElements(); ) {
          Clan C = (Clan) e.nextElement();
          str.append("<OPTION VALUE=\"" + C.clanID() + "\"");
          if (C.clanID().equalsIgnoreCase(old)) str.append(" SELECTED");
          str.append(">" + C.getName());
        }
      }
      if (parms.containsKey("ALIGNMENT")) {
        String old = httpReq.getRequestParameter("ALIGNMENT");
        if ((firstTime) || (old.length() == 0))
          old = "" + M.fetchFaction(CMLib.factions().AlignID());
        if (CMLib.factions().getFaction(CMLib.factions().AlignID()) != null) {
          for (int v = 1; v < Faction.ALIGN_NAMES.length; v++) {
            str.append("<OPTION VALUE=" + Faction.ALIGN_NAMES[v]);
            if (old.equalsIgnoreCase(Faction.ALIGN_NAMES[v])) str.append(" SELECTED");
            str.append(">" + CMStrings.capitalizeAndLower(Faction.ALIGN_NAMES[v].toLowerCase()));
          }
        }
      }
      if (parms.containsKey("BASEGENDER")) {
        String old = httpReq.getRequestParameter("BASEGENDER");
        if (firstTime) old = "" + M.baseCharStats().getStat(CharStats.STAT_GENDER);
        str.append("<OPTION VALUE=M " + ((old.equalsIgnoreCase("M")) ? "SELECTED" : "") + ">M");
        str.append("<OPTION VALUE=F " + ((old.equalsIgnoreCase("F")) ? "SELECTED" : "") + ">F");
        str.append("<OPTION VALUE=N " + ((old.equalsIgnoreCase("N")) ? "SELECTED" : "") + ">N");
      }
      str.append(MobData.expertiseList(M, httpReq, parms));
      str.append(MobData.classList(M, httpReq, parms));
      str.append(MobData.itemList(M, M, httpReq, parms, 0));
      str.append(MobData.abilities(M, httpReq, parms, 0));
      str.append(MobData.factions(M, httpReq, parms, 0));
      str.append(AreaData.affectsNBehaves(M, httpReq, parms, 0));
      str.append(ExitData.dispositions(M, firstTime, httpReq, parms));
      str.append(MobData.senses(M, firstTime, httpReq, parms));
      String strstr = str.toString();
      if (strstr.endsWith(", ")) strstr = strstr.substring(0, strstr.length() - 2);
      return clearWebMacros(strstr);
    }
    return "";
  }
 private String passwd(Authenticate logged) {
   return "".equals(logged.password()) ? passwd : logged.password();
 }
 private String user(Authenticate logged) {
   return "".equals(logged.username()) ? username : logged.username();
 }
Beispiel #11
0
  /**
   * Obtain a new context object. If a context object has already been created for this HTTP
   * request, it is re-used, otherwise it is created. If a user has authenticated with the system,
   * the current user of the context is set appropriately.
   *
   * @param request the HTTP request
   * @return a context object
   */
  public static Context obtainContext(HttpServletRequest request) throws SQLException {

    // Set encoding to UTF-8, if not set yet
    // This avoids problems of using the HttpServletRequest
    // in the getSpecialGroups() for an AuthenticationMethod,
    // which causes the HttpServletRequest to default to
    // non-UTF-8 encoding.
    try {
      if (request.getCharacterEncoding() == null) {
        request.setCharacterEncoding(Constants.DEFAULT_ENCODING);
      }
    } catch (Exception e) {
      log.error("Unable to set encoding to UTF-8.", e);
    }

    Context c = (Context) request.getAttribute("dspace.context");

    if (c == null) {
      // No context for this request yet
      c = new Context();
      HttpSession session = request.getSession();

      // See if a user has authentication
      Integer userID = (Integer) session.getAttribute("dspace.current.user.id");

      if (userID != null) {
        String remAddr = (String) session.getAttribute("dspace.current.remote.addr");
        if (remAddr != null && remAddr.equals(request.getRemoteAddr())) {
          EPerson e = EPerson.find(c, userID.intValue());

          Authenticate.loggedIn(c, request, e);
        } else {
          log.warn(
              "POSSIBLE HIJACKED SESSION: request from "
                  + request.getRemoteAddr()
                  + " does not match original "
                  + "session address: "
                  + remAddr
                  + ". Authentication rejected.");
        }
      }

      // Set any special groups - invoke the authentication mgr.
      int[] groupIDs = AuthenticationManager.getSpecialGroups(c, request);

      for (int i = 0; i < groupIDs.length; i++) {
        c.setSpecialGroup(groupIDs[i]);
        log.debug("Adding Special Group id=" + String.valueOf(groupIDs[i]));
      }

      // Set the session ID and IP address
      String ip = request.getRemoteAddr();
      if (useProxies == null) {
        useProxies = ConfigurationManager.getBooleanProperty("useProxies", false);
      }
      if (useProxies && request.getHeader("X-Forwarded-For") != null) {
        /* This header is a comma delimited list */
        for (String xfip : request.getHeader("X-Forwarded-For").split(",")) {
          if (!request.getHeader("X-Forwarded-For").contains(ip)) {
            ip = xfip.trim();
          }
        }
      }
      c.setExtraLogInfo("session_id=" + request.getSession().getId() + ":ip_addr=" + ip);

      // Store the context in the request
      request.setAttribute("dspace.context", c);
    }

    // Set the locale to be used
    Locale sessionLocale = getSessionLocale(request);
    Config.set(request.getSession(), Config.FMT_LOCALE, sessionLocale);
    c.setCurrentLocale(sessionLocale);

    return c;
  }
Beispiel #12
0
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public SheetViewModelCollection getSheets(@Context HttpServletRequest req) {
    if (!Authenticate.authenticateHeader(req)) {
      return null;
    }

    SheetController sheetController = new SheetController();
    sheetvector sheets =
        sheetController.GetSheetsByUsername(Authenticate.getAuthRequest(req).getUsername());

    ContentPlaceholderController cphController = new ContentPlaceholderController();
    FeedController feedc = new FeedController();
    ItemController itemc = new ItemController();

    List<SheetViewModel> models = new ArrayList<SheetViewModel>();

    int sheetLen = (int) sheets.size();
    for (int i = 0; i < sheetLen; i++) {
      boolean column1 = false;
      boolean column2 = false;

      List<newsfeeder.lib.model.ContentPlaceholder> contentPlaceholders =
          new ArrayList<newsfeeder.lib.model.ContentPlaceholder>();

      Sheet s = sheets.get(i);
      cphvector cphs = cphController.GetContentPlaceholdersBySheetId(s.getId());

      int cphLen = (int) cphs.size();
      for (int x = 0; x < cphLen; x++) {
        nfdb.ContentPlaceholder cph = cphs.get(x);

        NewsContentPlaceholder newsCPH =
            new NewsContentPlaceholder(cph.getColumn(), cph.getOrder());
        contentPlaceholders.add(newsCPH);

        if (cph.getColumn() == 0) {
          column1 = true;
        }

        if (cph.getColumn() == 1) {
          column2 = true;
        }

        feedvector feeds = feedc.GetFeedsByCphId(cph.getId());
        int feedLen = (int) feeds.size();

        for (int y = 0; y < feedLen; y++) {
          Feed f = feeds.get(y);

          itemvector items = itemc.GetItemsByFeedId(f.getId());
          int itemLen = (int) items.size();
          for (int z = 0; z < itemLen; z++) {
            nfdb.Item dbItem = items.get(z);

            NewsItem item =
                new NewsItem(dbItem.getId(), dbItem.getContent(), dbItem.getTitle(), "");
            newsCPH.addItem(item);
          }
        }
      }

      SheetLayout layout = get2ColLayout();

      if (column1 && column2) {
        layout = get2ColLayout();
      } else if (column1) {
        layout = get1ColLayout(0);
      } else if (column2) {
        layout = get1ColLayout(1);
      }

      SheetViewModel model =
          new SheetViewModel(s.getId(), s.getName(), layout, contentPlaceholders);
      models.add(model);
    }

    SheetViewModelCollection collection = new SheetViewModelCollection();
    collection.Sheets = (ArrayList<SheetViewModel>) models;

    return collection;
  }