Giter Club home page Giter Club logo

obfuscated-ids's Introduction

Build status on https://travis-ci.com/ Codacy Badge

Obfuscated-IDs

Undisclose IDs with Obfuscated-IDs

Obfuscated-IDs is a java open-source library that allows you to easily avoid to expose the internal IDs of your database at web level.

Obfuscated-IDs is based on:

Overview

With a Spring Framework and Obfuscated-IDs i's possible to write a @Controller that automatically allows the code to use the real numeric ID while it is always shown in its disguised form at the outside. For instance, look at this @RestController.

    @RestController
    public class EchoController {

        @RequestMapping("/user/{obfuscatedUserId}/{message}")
        public String getCode(@PathVariable AutoObfuscatedId obfuscatedUserId, @PathVariable String message) {
            
            long id = obfuscatedId.id();
            
            // ...access the database with the numeric id
            User user = userRepo.findOne(id);
            
            return "User " + obfuscatedId + " says '" + message + "'";
        }

    }

It exposes a service that can be invoked like that...

    /user/2BHah7n8ziI/HelloWorld

But obfuscatedId.id() will return the corresponding numeric ID.

Quick Start

Add the following Maven dependency

<dependency>
    <groupId>com.danidemi.obfuscatedids</groupId>
    <artifactId>obfuscatedids-spring</artifactId>
    <version>0.0.1</version>
</dependency>

[!] Please, check on Maven Central the latest version.

Configure an IdObfuscator.

@Bean
public static IdObfuscator idObfuscator() {
    return new HashIdObfuscator();
}

Add a @RestControllerAdvice that enables the conversion of parameters of type AutoObfuscatedId.

@RestControllerAdvice
public static class Advice {

    @Autowired IdObfuscator obfuscator;

    @InitBinder
    public void addSupportForObfuscatedId(WebDataBinder binder) {
        binder.registerCustomEditor(AutoObfuscatedId.class, new AutoObfuscatedIdSupport(obfuscator));
    }

}

Write your controller.

@Autowired @Autowired IdObfuscator obfuscator;

@RequestMapping("/users")
public List<String> getUsers() {
    return asList(
        obfuscator.disguise( user1.getId() ),
        obfuscator.disguise( user2.getId() )
    );
}

@RequestMapping("/user/{obfuscatedDbId}")
public String getUser(@PathVariable AutoObfuscatedId obfuscatedDbId) {
    ...
}

Deploy

Maven GPG Plugin

Make sure GPG is correctly set up executing the following commnad.

mvn gpg:sign

If that returns this error...

gpg: no default secret key: unusable secret key
gpg: signing failed: unusable secret key

...then A GPG key is needed. If one is available you can import it with...

gpg --import ~/mygpgkey_pub.gpg
gpg --allow-secret-key-import --import ~/mygpgkey_sec.gpg

Rerun again mvn gpg:sign to check all is in place.

Sonatype OSS Repository Hosting

Make sure the Sonatype OSS Repository Hosting is properly set up checking that the Maven's settings.xml contains a reference to it.

cat ${user.home}/.m2/settings.xml

You should see something like that...

<server>
    <id>ossrh</id>
    <username>YOUR-OSSRH-USERNAME-HERE</username>
    <password>YOUR-OSSRH-PASSWORD-HERE</password>
</server>

Deploy A New Release

To deploy it should be enough to issue the following commands.

mvn clean release:clean 
mvn release:prepare
mvn release:perform

References

Projects

Manuals

Posts

obfuscated-ids's People

Contributors

danidemi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ziscloud

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.