Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Java library for Macaroons.

License

NotificationsYou must be signed in to change notification settings

pvriel/macaroons4J

Repository files navigation

Project Status: ActiveCoverage

A Java library forMacaroons.
The aim of this library is to provide an easy-to-use, yet versatile (e.g., support for structural caveats) library for developers.


How to add this dependency to your project

We now useGitHub packages instead of JitPack.


Basic usage example

Working with Macaroons in general

StringhintTargetLocation ="https://google.com";byte[]macaroonIdentifier =UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8);StringmacaroonSecret ="A secret, only known to the target location";Macaroonmacaroon =newSimpleMacaroon(macaroonSecret,macaroonIdentifier,hintTargetLocation);VerificationContextcontext =newVerificationContext();HashSet<VerificationContext>validContexts =macaroon.verify(macaroonSecret,context);assert(validContexts.size() >=1);

Working with first-party caveats

byte[]firstPartyCaveatIdentifier =UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8);// Create a custom FirstPartyCaveat subclass and define its verification process.FirstPartyCaveattimeConstraint =newFirstPartyCaveat(firstPartyCaveatIdentifier) {@Overrideprotectedvoidverify(@NotNullMacaroonmacaroon,@NotNullVerificationContextcontext)throwsIllegalStateException {/*            macaroon: the Macaroon instance that is being verified.            context: the context in which the caveat should hold.         */context.addRangeConstraint("time",Pair.of(5,10));    }};macaroon.addCaveat(timeConstraint);validContexts =macaroon.verify(macaroonSecret,context);assert(validContexts.size() >=1);context =newVerificationContext();context.addRangeConstraint("time",Pair.of(11,15));/*    No possible solutions here: context only valid in 'time' range 11 - 15, while the constraint is only valid between 5 - 10.    There is no overlapping between the two ranges. */validContexts =macaroon.verify(macaroonSecret,context);assert(validContexts.size() ==0);

Working with third-party caveats

StringthirdPartyCaveatRootKey ="Another secret, shared with the third-party";byte[]thirdPartyCaveatIdentifier ="user is Alice";StringhintDischargeLocation ="https://oauthprovider.com";ThirdPartyCaveatthirdPartyCaveat =newThirdPartyCaveat(thirdPartyCaveatRootKey,thirdPartyCaveatIdentifier,hintDischargeLocation);macaroon.addCaveat(thirdPartyCaveat);macaroon.verify(macaroonSecret,newVerificationContext());// Exception thrown: no discharge Macaroon bound.// You can add additional caveats to the discharge Macaroons, but we are not doing that here.MacaroondischargeMacaroon =newSimpleMacaroon(thirdPartyCaveatRootKey,thirdPartyCaveatIdentifier,hintDischargeLocation);macaroon.bindMacaroonForRequest(dischargeMacaroon);validContexts =macaroon.verify(macaroonSecret,newVerificationContext());assert(validContexts.size() >=1);

Contact

Found a bug, problem, ... or do you have a question about this library?
Do not hesitate to contact me as soon as possible!

About

A Java library for Macaroons.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages


[8]ページ先頭

©2009-2025 Movatter.jp