Example #1
0
  public void maySetSAuthVersion(HttpRequest request) {
    if (request.hasNotHeader(Header.SAuth.Value.Authorization))
      request.setHeader(Header.SAuth.Value.Authorization);

    if (request.hasNotHeader(Header.SAuth.Value.Version))
      request.setHeader(Header.SAuth.Value.Version);
  }
Example #2
0
 public java.lang.String getSAuthNonce(HttpRequest request) {
   return request.getHeaderString(Header.SAuth.Nonce);
 }
Example #3
0
 public alto.lang.Header getSAuthVersionHeader(HttpRequest request) {
   return request.getHeader(Header.SAuth.Version);
 }
Example #4
0
 public void setSAuthSignature(HttpRequest request, long folded) {
   java.lang.String value = alto.io.u.Hex.encode(folded);
   request.setHeader(Header.SAuth.Signature, value);
 }
Example #5
0
 public long getSAuthSignatureLong(HttpRequest request) {
   java.math.BigInteger bint = request.getHeaderHex(Header.SAuth.Signature);
   if (null != bint) return bint.longValue();
   else return 0L;
 }
Example #6
0
 public alto.lang.Header getSAuthSignatureHeader(HttpRequest request) {
   return request.getHeader(Header.SAuth.Signature);
 }
Example #7
0
 public void setSAuthNonce(HttpRequest request, java.lang.String value) {
   request.setHeader(Header.SAuth.Nonce, value);
 }
Example #8
0
 public void setSAuthNonce(HttpRequest request) {
   request.setHeader(Header.SAuth.Nonce, alto.io.u.Prng.RandLongStringHex());
 }
Example #9
0
 public java.lang.String validateSAuthUIDHeaderString(HttpRequest request) {
   return request.validateHeaderString(Header.SAuth.UID);
 }
Example #10
0
 public alto.lang.Header getSAuthUIDHeader(HttpRequest request) {
   return request.getHeader(Header.SAuth.UID);
 }
Example #11
0
 public boolean hasNotSAuthUID(HttpRequest request) {
   return (request.hasNotHeader(Header.SAuth.UID));
 }
Example #12
0
 public java.lang.String validateSAuthVersionHeaderString(HttpRequest request) {
   java.lang.String re = request.validateHeaderString(Header.SAuth.Version);
   if (null != re && re.equals(Header.SAuth.Value.Version.toString())) {
     return re;
   } else throw new alto.sys.BadRequestException(re);
 }
Example #13
0
 public java.lang.String getSAuthVersion(HttpRequest request) {
   return request.getHeaderString(Header.SAuth.Version);
 }
Example #14
0
 public java.lang.String getSAuthNonceHeaderString(HttpRequest request) {
   alto.lang.Header header = request.getHeader(Header.SAuth.Nonce);
   if (null != header) return header.toString();
   else return null;
 }
Example #15
0
 public java.lang.String getSAuthUID(HttpRequest request) {
   return request.getHeaderString(Header.SAuth.UID);
 }
Example #16
0
 public java.lang.String validateSAuthNonceHeaderString(HttpRequest request) {
   java.lang.String re = request.validateHeaderString(Header.SAuth.Nonce);
   java.math.BigInteger value = request.getHeaderHex(Header.SAuth.Nonce);
   if (null != value && 14 < value.bitLength()) return re;
   else throw new alto.sys.BadRequestException(re);
 }
Example #17
0
 public void setSAuthUID(HttpRequest request, java.lang.String value) {
   request.setHeader(Header.SAuth.UID, value);
 }
Example #18
0
 public void maySetSAuthNonce(HttpRequest request) {
   if (request.hasNotHeader(Header.SAuth.Nonce))
     request.setHeader(Header.SAuth.Nonce, alto.io.u.Prng.RandLongStringHex());
 }
Example #19
0
 public void maySetSAuthUID(HttpRequest request, java.lang.String uid) {
   java.lang.String value = this.getSAuthUID(request);
   if (null == value || (!value.equals(uid))) request.setHeader(Header.SAuth.UID, uid);
 }
Example #20
0
 public boolean hasNotSAuthSignature(HttpRequest request) {
   return (request.hasNotHeader(Header.SAuth.Signature));
 }
Example #21
0
 public void setSAuthUID(HttpRequest request, Principal principal) {
   request.setHeader(Header.SAuth.UID, principal.getName());
 }
Example #22
0
 public java.lang.String getSAuthSignature(HttpRequest request) {
   return request.getHeaderString(Header.SAuth.Signature);
 }
Example #23
0
 public boolean hasNotSAuthNonce(HttpRequest request) {
   return (request.hasNotHeader(Header.SAuth.Nonce));
 }
Example #24
0
 public void setSAuthSignature(HttpRequest request, java.lang.String value) {
   request.setHeader(Header.SAuth.Signature, value);
 }
Example #25
0
 public alto.lang.Header getSAuthNonceHeader(HttpRequest request) {
   return request.getHeader(Header.SAuth.Nonce);
 }
Example #26
0
  public boolean sign(Principal.Authentic keys, HttpRequest request) {
    if (null != keys) {
      RSA rsa = new RSA(keys);
      request.maySetDate();
      request.maySetHost();
      request.setContentMD5();
      this.setSAuthVersion(request);
      this.setSAuthUID(request, keys.getUID());
      this.setSAuthNonce(request);

      java.lang.String requestline =
          request.validateMethod() + ' ' + request.validatePathComplete();
      java.lang.String headerHost = request.validateHostHeaderString();
      java.lang.String headerDate = request.validateDateHeaderString();
      java.lang.String headerSAuthVersion = this.validateSAuthVersionHeaderString(request);
      java.lang.String headerSAuthUID = this.validateSAuthUIDHeaderString(request);
      java.lang.String headerSAuthNonce = this.validateSAuthNonceHeaderString(request);

      java.lang.String headerContentType = null;
      java.lang.String headerContentLength = null;
      java.lang.String headerContentEncoding = null;
      java.lang.String headerContentRange = null;
      java.lang.String headerContentLocation = null;
      java.lang.String headerETag = null;
      java.lang.String headerLastModified = null;
      java.lang.String headerExpires = null;
      java.lang.String headerContentMD5 = null;

      SHA1 sha = new SHA1();
      sha.update(requestline);
      sha.update(headerHost);
      sha.update(headerDate);
      if (request.isContentLengthPositive()) {

        headerContentType = request.getContentTypeHeaderString();
        sha.update(headerContentType);

        headerContentLength = request.validateContentLengthHeaderString();
        sha.update(headerContentLength);

        headerContentEncoding = request.getContentEncodingHeaderString();
        sha.update(headerContentEncoding);

        headerContentRange = request.getContentRangeHeaderString();
        sha.update(headerContentRange);

        headerContentLocation = request.getContentLocationHeaderString();
        sha.update(headerContentLocation);

        headerETag = request.getETagHeaderString();
        sha.update(headerETag);

        headerLastModified = request.getLastModifiedHeaderString();
        sha.update(headerLastModified);

        headerExpires = request.getExpiresHeaderString();
        sha.update(headerExpires);

        headerContentMD5 = request.validateContentMD5HeaderString(); // (verifyContentMD5)
        sha.update(headerContentMD5);
      }
      sha.update(headerSAuthVersion);
      sha.update(headerSAuthUID);
      sha.update(headerSAuthNonce);

      long signature = Function.Xor.Hash64(rsa.sign(sha));

      this.setSAuthSignature(request, signature);
      return true;
    } else throw new alto.sys.Error.Argument();
  }
Example #27
0
 public boolean hasNotSAuthVersion(HttpRequest request) {
   return (request.hasNotHeader(Header.SAuth.Version));
 }