GithubHelp home page GithubHelp logo

edgeauth-token-java's Introduction

EdgeAuth-Token-Java: Akamai Edge Authorization Token for Java

Maven Central [Build Status License

EdgeAuth-Token-Java is Akamai Edge Authorization Token in the HTTP Cookie, Query String and Header for a client. You can configure it in the Property Manager at https://control.akamai.com. It's a behavior which is Auth Token 2.0 Verification.

EdgeAuth-Token-Java supports Java 8+.

Build

Click Here

Example

import com.akamai.edgeauth.EdgeAuth;
import com.akamai.edgeauth.EdgeAuthBuilder;
import com.akamai.edgeauth.EdgeAuthException;


public class EdgeAuthExample {
  public static void main(String[] args) {
    String hostname = "YourAkamaizedHostname";
    String ET_ENCRYPTION_KEY = "YourEncryptionKey";
    long duration = 500L; // 500 seconds

    // Below examples here ..
  }
}
  • ET_ENCRYPTION_KEY must be hexadecimal digit string with even-length.
  • Don't expose ET_ENCRYPTION_KEY on the public repository.

URL parameter option

try {
  EdgeAuth ea = new EdgeAuthBuilder()
      .key(ET_ENCRYPTION_KEY)
      .windowSeconds(duration)
      .escapeEarly(true)
      .build();

  /******** 
  1) Cookie 
  *********/
  String path = "/akamai/edgeauth";
  String token = ea.generateURLToken(path);
  String url = String.format("http(s)://%s%s", hostname, path);
  String cookie = String.format("%s=%s", ea.getTokenName(), token);
  // => Link or Request "url" /w "cookie"

  /************** 
  2) Query String 
  ***************/
  String path = "/akamai/edgeauth";
  String token = ea.generateURLToken(path);
  String url = String.format("http(s)://%s%s?%s=%s", hostname, path,
    ea.getTokenName(), token);
  // If url has a query string which isn't for the token, be aware of the string formatter and symbol(? and &).
  // => Link or Request "url" /w Query string
} catch (EdgeAuthException e) {
  e.printStackTrace();
}
  • 'Escape token input' option in the Property Manager corresponds to 'escapeEarly' in the code.
    Escape token input (on) == escapeEarly (true)
    Escape token input (off) == escapeEarly (false)
  • In [Example 2] for Query String, it's only okay for 'Ignore query string' option (on).
  • If you want to 'Ignore query string' option (off) using query string as your token, Please contact your Akamai representative.

ACL(Access Control List) parameter option

try {
  EdgeAuth ea = new EdgeAuthBuilder()
      .key(encrpytionKey)
      .windowSeconds(duration)
      .build();

  /******************
  3) Header using '*' 
  *******************/
  String acl = "/akamai/edgeauth/list/*"; //*/
  String token = ea.generateACLToken(acl);
  String url = String.format("http(s)://%s%s", hostname, "/akamai/edgeauth/list/something");
  String header = String.format("%s: %s", ea.getTokenName(), token);
  // => Link or Request "url" /w "header"

  /************************* 
  4) Cookie Delimited by '!'
  **************************/
  String acl2[] = { "/akamai/edgeauth", "/akamai/edgeauth/list/*" };
  String token = ea.generateACLToken(acl2);
  String url = String.format("http(s)://%s%s", hostname, "/akamai/edgeauth/list/something2");
  String cookie = String.format("%s=%s", ea.getTokenName(), token);
  // => Link or Request "url" /w "cookie"
} catch (EdgeAuthException e) {
  e.printStackTrace();
}
  • ACL can use the wildcard(*, ?) in the path.
  • Don't use '!' in your path because it's ACL Delimiter.
  • Use 'escapeEarly=false' as default setting but it doesn't matter turning on/off 'Escape token input' option in the Property Manager

Usage

EdgeAuth, EdgeAuthBuilder Class

Parameter Description
tokenType Select a preset. (Not Supported Yet)
tokenName Parameter name for the new token. [ Default: __token__ ]
key Secret required to generate the token. It must be hexadecimal digit string with even-length.
algorithm Algorithm to use to generate the token. ("sha1", "sha256", or "md5") [ Default: "sha256" ]
salt Additional data validated by the token but NOT included in the token body. (It will be deprecated)
ip IP Address to restrict this token to. (Troublesome in many cases (roaming, NAT, etc) so not often used)
payload Additional text added to the calculated digest.
sessionId The session identifier for single use tokens or other advanced cases.
startTime What is the start time? (Use EdgeAuth.NOW for the current time)
endTime When does this token expire? endTime overrides windowSeconds
windowSeconds How long is this token valid for?
fieldDelimiter Character used to delimit token body fields. [ Default: ~ ]
aclDelimiter Character used to delimit acl. [ Default: ! ]
escapeEarly Causes strings to be url encoded before being used.
verbose Print all parameters.

EdgeAuth Static Variable

public static final Long NOW = 0L; // When using startTime, 0L means "from NOW".

EdgeAuth's Method

Method Description
generateURLToken(String url) Single URL path.
generateACLToken(String acl) Single URL path - can use the wildcard (*, ?)
generateACLToken(String[] acl) Multi URL paths - can use the wildcard

Returns the authorization token string.

Test

"src/test" directory is only for the internal test.

Others

If you use the Segmented Media Protection behavior in AMD(Adaptive Media Delivery) Product, tokenName should be 'hdnts'.

License

Copyright 2018 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

edgeauth-token-java's People

Contributors

astinchoi avatar mgwoj avatar skearney-akamai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

edgeauth-token-java's Issues

cms-edgeauth.js compatibility with commander 7+

Hi,

The script is not compatible with commander 7+ versions (now it is on v8.0.0 as LTS)
You need to user commander 6.1.0 in order to use cms-edgeauth.js as it writed or add the method opt() to the "program." object to "program.opt()." to retreieve command variables...

var ea = new EdgeAuth({
tokenType: program.opts().token_type,
tokenName: program.opts().token_name,
key: program.opts().key,
algorithm: program.opts().algo,
salt: program.opts().salt,
startTime: program.opts().start_time,
endTime: program.opts().end_time,
windowSeconds: program.opts().window,
fieldDelimiter: program.opts().field_delimiter,
aclDelimiter: program.opts().acl_delimiter,
escapeEarly: program.opts().escape_early,
verbose: program.opts().verbose,
url: program.opts().url,
acl: program.opts().acl,
ip: program.opts().ip,
payload: program.opts().payload,
sessionId: program.opts().session_id
})

var token
if (program.acl) {
token = ea.generateACLToken(program.opts().acl)
} else { // program.url
token = ea.generateURLToken(program.opts().url)
}

Token validation

Hi Team,

How can I validate a token generated with any algo :sha256,MD..

Thanks

java.lang.UnsupportedClassVersionError: com/akamai/edgeauth/EdgeAuthException : Unsupported major.minor version 52.0:

Documentation is stating that EdgeAuth-Token-Java supports Java 1.6+.
However during testing we got this error when trying to generate the token using edgeauth-0.2.0.jar:
java.lang.UnsupportedClassVersionError: com/akamai/edgeauth/EdgeAuthException : Unsupported major.minor version 52.0:

After some research it appears that the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but we are trying to run it using a JDK 1.7 environment. The reported number is the required number, not the number we are using.

Could you please confirm that Java 1.7 is supported here ? or should we update documentation to indicates that Java 1.8 is required ?

CVE found

I am using this library to get AuthToken , but in maven central , I see there is a CVE found . Are there any plans to fix that .
CVE-2020-15250

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.