コード例 #1
0
 /** 功能:修改图片 */
 @ResponseBody
 @RequestMapping(value = "/upLoadImages", method = RequestMethod.POST)
 public ResultMsg upLoadImages(String id2, @RequestParam MultipartFile[] images2, String gid)
     throws Exception {
   ResultMsg result = new ResultMsg();
   result.setResultMessage("errors");
   MusicBg music = new MusicBg();
   if (images2 != null && images2.length > 0) {
     for (MultipartFile $file : images2) {
       if (!$file.isEmpty()) {
         String name = $file.getOriginalFilename();
         String ext = name.substring(name.lastIndexOf("."), name.length());
         String sha1 = DigestUtils.shaHex($file.getInputStream());
         String fileName = sha1 + ext;
         String path =
             Constants.DEFAULT_UPLOADIMAGEPATH + File.separator + Constants.sha1ToPath(sha1);
         Constants.mkdirs(path);
         FileUtils.copyInputStreamToFile($file.getInputStream(), new File(path, fileName));
         music.setImageSha1(sha1);
         music.setImage(fileName);
       }
     }
   }
   music.setId(id2);
   if (this.musicBgService.addMusicBg(music, gid)) {
     result.setResultMessage("success");
   }
   return result;
 }
コード例 #2
0
 /** 功能:添加修改 */
 @RequestMapping(value = "/save", method = RequestMethod.POST)
 public ModelAndView save(@RequestParam MultipartFile[] images, String gid) throws Exception {
   ModelAndView mav =
       new ModelAndView(com.baofeng.utils.Constants.COREWEB_BUILDITEMS + "/musicbg");
   MusicBg music = new MusicBg();
   if (images != null && images.length > 0) {
     for (MultipartFile $file : images) {
       if (!$file.isEmpty()) {
         String name = $file.getOriginalFilename();
         String ext = name.substring(name.lastIndexOf("."), name.length());
         String sha1 = DigestUtils.shaHex($file.getInputStream());
         String fileName = sha1 + ext;
         String path =
             Constants.DEFAULT_UPLOADIMAGEPATH + File.separator + Constants.sha1ToPath(sha1);
         Constants.mkdirs(path);
         FileUtils.copyInputStreamToFile($file.getInputStream(), new File(path, fileName));
         music.setImageSha1(sha1);
         music.setImage(fileName);
       }
     }
   }
   this.musicBgService.addMusicBg(music, gid);
   WeekService week = this.weekServiceService.readWeekService(gid);
   if (week != null) {
     mav.addObject("week", week);
   }
   return mav;
 }
コード例 #3
0
  public static InputStream openCachedStream(URI uri) {
    TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault();
    if (rc == null) {
      return null;
    }

    if (rc.cacheDir == null) {
      return null;
    }

    String hash = DigestUtils.shaHex(uri.toString());
    File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX);

    if (!bFile.exists() || !hFile.exists()) {
      return null;
    }

    try {
      return new FileInputStream(bFile);
    } catch (FileNotFoundException e) {
      // Fallback to URL download?
      return null;
    }
  }
コード例 #4
0
  @Override
  public CacheResponse get(URI uri, String rqstMethod, Map<String, List<String>> rqstHeaders)
      throws IOException {
    if (uri == null || cacheDir == null) return null;

    // Get our key, which is a hash of the URI
    String hash = DigestUtils.shaHex(uri.toString());

    // Make our cache files
    File hFile = new File(cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(cacheDir, hash + BODY_SUFFIX);

    if (!bFile.exists() || !hFile.exists()) {
      return null;
    }

    // Read in the headers
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    BufferedReader rdr = new BufferedReader(new FileReader(hFile), 1024);
    for (String line = rdr.readLine(); line != null; line = rdr.readLine()) {
      String keyval[] = line.split("=", 2);
      if (!headers.containsKey(keyval[0])) {
        headers.put(keyval[0], new ArrayList<String>());
      }
      headers.get(keyval[0]).add(keyval[1]);
    }
    rdr.close();

    // Update the access log
    hFile.setLastModified(System.currentTimeMillis());

    // Respond with the cache
    return new TiCacheResponse(headers, new FileInputStream(bFile));
  }
コード例 #5
0
 private AuthCacheKey(String header, String ip) {
   if (header == null) {
     this.hashedHeader = EMPTY_HEADER;
   } else {
     this.hashedHeader = DigestUtils.shaHex(header);
   }
   this.ip = ip;
 }
コード例 #6
0
ファイル: Encriptador.java プロジェクト: panietoar/webPage
  public static String encriptarClave(String usuario, String clave) {

    String sinEnc = usuario + ":" + clave;

    String code = DigestUtils.shaHex(sinEnc.toUpperCase());

    return code.toLowerCase();
  }
コード例 #7
0
ファイル: JoinServiceBase.java プロジェクト: tiunnn/bbb-java
 protected static String checksum(String s) {
   String checksum = "";
   try {
     checksum = DigestUtils.shaHex(s);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return checksum;
 }
コード例 #8
0
 public static void addCompleteListener(URI uri, CompleteListener listener) {
   synchronized (completeListeners) {
     String hash = DigestUtils.shaHex(uri.toString());
     if (!completeListeners.containsKey(hash)) {
       completeListeners.put(hash, new ArrayList<CompleteListener>());
     }
     completeListeners.get(hash).add(listener);
   }
 }
コード例 #9
0
  /**
   * Establish the SAML2IDP using the PROXY_URLPATH_CONTEXT from the session<br>
   * Also puts the SAML2IDP's EntityId in the Session as PROXY_SHADOWED_ENTITYID<br>
   * <br>
   * When no SAML2IDP match could be made, there will be no PROXY_SHADOWED_ENTITYID attribute
   * written in the session, and null is returned.
   *
   * @param oAttributes Session Attributes
   * @param oURLPathContext non-null initialized URLPathContext instance to process
   * @return SAML2IDP organization as established, or null when no match could be made
   */
  protected SAML2IDP processURLPathContext(
      ISessionAttributes oAttributes, URLPathContext oURLPathContext) throws OAException {
    // Did we try to find a match before?
    if (oAttributes.contains(
        com.alfaariss.oa.util.session.ProxyAttributes.class,
        com.alfaariss.oa.util.session.ProxyAttributes.PROXY_SHADOWED_IDPID)) {
      String sShadowedEntityId =
          (String)
              oAttributes.get(
                  com.alfaariss.oa.util.session.ProxyAttributes.class,
                  com.alfaariss.oa.util.session.ProxyAttributes.PROXY_SHADOWED_IDPID);

      // Re-use this intelligence, and return the SAML2IDP instance
      IIDP oIDP = _organizationStorage.getIDP(sShadowedEntityId);
      if (oIDP instanceof SAML2IDP) {
        _logger.info("Found IDP '" + sShadowedEntityId + "' from previous URLPath Context match");
        return (SAML2IDP) oIDP;
      } else {
        _logger.warn(
            "Non-SAML2IDP found in IDP Storage - inform developers of this condition! (1)");
        return null;
      }
    }

    String sIValue = oURLPathContext.getParams().get("i");
    if (sIValue == null) {
      _logger.info("No 'i' value found in URLPath Context path ('" + oURLPathContext + "')");
      return null;
    }

    List<IIDP> lAllIDPs = _organizationStorage.getAll();
    for (IIDP oIDP : lAllIDPs) {
      String sIDPEntityIdHash = DigestUtils.shaHex(oIDP.getID());
      if (sIDPEntityIdHash.equalsIgnoreCase(sIValue)) {
        _logger.info("Found IDP '" + oIDP.getID() + "' in matching URLPath Context");
        if (oIDP instanceof SAML2IDP) {
          // Store the IDP that was found on the map
          oAttributes.put(
              com.alfaariss.oa.util.session.ProxyAttributes.class,
              com.alfaariss.oa.util.session.ProxyAttributes.PROXY_SHADOWED_IDPID,
              oIDP.getID());

          // Return result
          return (SAML2IDP) oIDP;
        } else {
          _logger.warn(
              "Non-SAML2IDP found in IDP Storage - inform developers of this condition! (2)");
          return null;
        }
      }
    }

    _logger.info("No IDP found for provided i");
    return null;
  }
コード例 #10
0
  public static void remove(URI uri) {
    TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault();
    if (rc == null) return;
    if (rc.cacheDir == null) return;

    String hash = DigestUtils.shaHex(uri.toString());
    File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX);
    if (bFile.exists()) bFile.delete();
    if (hFile.exists()) hFile.delete();
  }
コード例 #11
0
  public static boolean peek(URI uri) {
    TiResponseCache rc = (TiResponseCache) TiResponseCache.getDefault();
    if (rc == null) return false;
    if (rc.cacheDir == null) return false;

    String hash = DigestUtils.shaHex(uri.toString());
    File hFile = new File(rc.cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(rc.cacheDir, hash + BODY_SUFFIX);
    if (!bFile.exists() || !hFile.exists()) return false;
    return true;
  }
コード例 #12
0
 private static final void fireCacheCompleted(URI uri) {
   synchronized (completeListeners) {
     String hash = DigestUtils.shaHex(uri.toString());
     if (completeListeners.containsKey(hash)) {
       for (CompleteListener listener : completeListeners.get(hash)) {
         listener.cacheCompleted(uri);
       }
       completeListeners.remove(hash);
     }
   }
 }
コード例 #13
0
 public String encryptPassword(String pass, String salt) throws Exception {
   try {
     ScriptEngineManager factory = new ScriptEngineManager();
     ScriptEngine engine = factory.getEngineByName("JavaScript");
     if (engine == null) throw new RuntimeException("JavaScript engine not found");
     final String md5enc =
         (String)
             engine.eval(JavaScript_MD5Crypt + "md5crypt(\"" + pass + "\", \"" + salt + "\")");
     return DigestUtils.shaHex(md5enc);
   } catch (Exception e) {
     throw new ServiceConnectionProblemException("Can't execute javascript");
   }
 }
コード例 #14
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 @Path("hash/")
 public Response hashing() throws IOException {
   VolumeDAO volumeDAO = DAOFactory.getInstance().getVolumeDAO();
   List<Volume> findAll = volumeDAO.findAll();
   Transaction beginTransaction = volumeDAO.getSession().beginTransaction();
   for (Volume volume : findAll) {
     String fileSHA1 = DigestUtils.shaHex(FileUtils.openInputStream(new File(volume.getPath())));
     volume.setHashSH1(fileSHA1);
   }
   beginTransaction.commit();
   return Response.ok("hashed").build();
 }
コード例 #15
0
  public void testSaveAsChunks() throws IOException {

    byte[] data = new byte[10 * 1024 * 1024];
    new Random(12345).nextBytes(data);
    byte[] sha = DigestUtils.sha(data);

    Mongo mongo = getMongo();
    MongoContentStorage storage = new MongoContentStorage(mongo.getDB("test"));

    ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(data));

    BSONObject doc = assertMockMongoContainsDocument("test.v7files.content", sha);
    assertEquals("cat", doc.get("store"));
    assertEquals(data.length, storage.getContent(pointer).getLength());
    assertEquals(
        Hex.encodeHexString(sha), DigestUtils.shaHex(storage.getContent(pointer).getInputStream()));
  }
コード例 #16
0
  private String generateTicket() {
    final StringBuilder builder = new StringBuilder();

    builder.append(getExternalId());
    builder.append(hashCode());

    final InstitutionAffiliationEvent event = getInstitutionAffiliationEvent();
    final Person person = event.getPerson();
    final User user = person.getUser();
    builder.append(user.getUserUId());
    builder.append(user.getExternalId());

    final DateTime instant = getGenerated();
    builder.append(instant.toString("yyyy-MM-dd HH:mm:ss"));

    return DigestUtils.shaHex(builder.toString());
  }
コード例 #17
0
  protected boolean checkShaIsValid(Number orderId, SisowData sisowData) throws Exception {
    // $pars["sha1"] = sha1($this->purchaseId . $this->entranceCode . round($this->amount * 100) .
    // $this->merchantId . $this->merchantKey);

    String concat =
        orderId
            + ""
            + orderId
            + sisowData.getAmount()
            + sisowData.getMerchantId()
            + sisowData.getMerchantKey();
    sisowData.setCalculatedHash(DigestUtils.shaHex(concat));

    logger.debug("Calculated sha1 hash: " + sisowData.getCalculatedHash());

    return sisowData.getCalculatedHash().equals(sisowData.getSha1());
  }
コード例 #18
0
  private static class AuthCacheKey {
    private static final String EMPTY_HEADER = DigestUtils.shaHex("");

    private final String hashedHeader;
    private final String ip;

    private AuthCacheKey(String header, String ip) {
      if (header == null) {
        this.hashedHeader = EMPTY_HEADER;
      } else {
        this.hashedHeader = DigestUtils.shaHex(header);
      }
      this.ip = ip;
    }

    public boolean hasEmptyHeader() {
      return this.hashedHeader.equals(EMPTY_HEADER);
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) {
        return true;
      }
      if (o == null || getClass() != o.getClass()) {
        return false;
      }
      AuthCacheKey key = (AuthCacheKey) o;
      return hashedHeader.equals(key.hashedHeader) && ip.equals(key.ip);
    }

    @Override
    public int hashCode() {
      int result = hashedHeader.hashCode();
      result = 31 * result + ip.hashCode();
      return result;
    }
  }
コード例 #19
0
  @Override
  public CacheRequest put(URI uri, URLConnection conn) throws IOException {
    if (cacheDir == null) return null;

    // Make sure the cacheDir exists, in case user clears cache while app is running
    if (!cacheDir.exists()) {
      cacheDir.mkdirs();
    }

    // Gingerbread 2.3 bug: getHeaderField tries re-opening the InputStream
    // getHeaderFields() just checks the response itself
    Map<String, List<String>> headers = makeLowerCaseHeaders(conn.getHeaderFields());
    String cacheControl = getHeader(headers, "cache-control");
    if (cacheControl != null && cacheControl.matches("^.*(no-cache|no-store|must-revalidate).*")) {
      return null; // See RFC-2616
    }

    boolean skipTransferEncodingHeader = false;
    String tEncoding = getHeader(headers, "transfer-encoding");
    if (tEncoding != null && tEncoding.toLowerCase().equals("chunked")) {
      skipTransferEncodingHeader =
          true; // don't put "chunked" transfer-encoding into our header file, else the http
                // connection object that gets our header information will think the data starts
                // with a chunk length specification
    }

    // Form the headers and generate the content length
    String newl = System.getProperty("line.separator");
    long contentLength = getHeaderInt(headers, "content-length", 0);
    StringBuilder sb = new StringBuilder();
    for (String hdr : headers.keySet()) {
      if (!skipTransferEncodingHeader || !hdr.equals("transfer-encoding")) {
        for (String val : headers.get(hdr)) {
          sb.append(hdr);
          sb.append("=");
          sb.append(val);
          sb.append(newl);
        }
      }
    }
    if (contentLength + sb.length() > maxCacheSize) {
      return null;
    }

    // Work around an android bug which gives us the wrong URI
    try {
      uri = conn.getURL().toURI();
    } catch (URISyntaxException e) {
    }

    // Get our key, which is a hash of the URI
    String hash = DigestUtils.shaHex(uri.toString());

    // Make our cache files
    File hFile = new File(cacheDir, hash + HEADER_SUFFIX);
    File bFile = new File(cacheDir, hash + BODY_SUFFIX);

    // Write headers synchronously
    FileWriter hWriter = new FileWriter(hFile);
    try {
      hWriter.write(sb.toString());
    } finally {
      hWriter.close();
    }

    synchronized (this) {
      // Don't add it to the cache if its already being written
      if (!bFile.createNewFile()) {
        return null;
      }
      return new TiCacheRequest(uri, bFile, hFile, contentLength);
    }
  }
コード例 #20
0
 /**
  * @param user
  * @param passwd
  * @throws com.autentia.tnt.util.HashEngineException
  */
 public void changePassword(User user, String passwd) {
   user.setPassword(DigestUtils.shaHex(passwd));
 }
コード例 #21
0
 /**
  * @param user
  * @param passwd
  * @throws com.autentia.tnt.util.HashEngineException
  * @return
  */
 public boolean checkPassword(User user, String passwd) {
   return DigestUtils.shaHex(passwd).equalsIgnoreCase(user.getPassword());
 }
コード例 #22
0
 @Override
 public String getCondensedId() {
   return DigestUtils.shaHex(getLongId());
 }
コード例 #23
0
 private String getRequestToken(
     final String request, final String salt, final String communicationToken) {
   final String random = String.format("%06x", new Random().nextInt(0xFFFFFF));
   return random
       + DigestUtils.shaHex(request + ":" + communicationToken + ":" + salt + ":" + random);
 }
コード例 #24
0
  public String find(String fileContent) throws IOException {
    fileContent = LINE_BREAKS.matcher(fileContent).replaceAll("\n");

    return DigestUtils.shaHex(fileContent);
  }
コード例 #25
0
 /**
  * daoke 内部签名字符串
  *
  * @param text 需要签名的字符串
  * @return 签名结果
  */
 public static String sign(String text) {
   // 转成大写
   return DigestUtils.shaHex(text).toUpperCase();
 }