Git Product home page Git Product logo

jingle-mod's Introduction

jingle-demo

Install and run

  • Import each directory into Eclipse as a seperate project
  • In the jingle-mod directory, run com.jingle.Server.java

(unfortunately only runs from within Eclipse)

How to use

Point a REST client to the base url: https://localhost:8443 and use the following end points.

POST /signup - requires 'username', 'firstname, 'lastname', 'email' and 'password' - returns new user.)

POST /login - requires 'username' and 'password' - returns authentication key.

PUT /edit - requires 'userid' and 'authkey', with all other params being optional - returns updated user.

DELETE /delete - requires 'userid' and 'authkey' - returns whether successful or not

GET /user - requires either 'userid' or 'username' - returns user

Role Management Implementation

I would create a repository containing containing different Roles, with either a one-to-many relationship with Users, or a many-to-many relationship (using a middleman join table, allowing a user to have many roles.) Each Role class could contain a list of methods which the User is permitted to do.

Roles could then inherit from each other, so a Guest role would have a certain subset of permitted operations. Member could then inherit all the methods from Guest and implement a further set of methods. Admin could then inherit all the methods from from Member and so on.

Before running any operations, a check would be made to see what roles the user has/belongs to, and whether the current operation is available to them. This could be as simple as saving a list of permitted operations in a repository/class and checking against it every time an operation is made.

For example:

delete(long id) {
  if(currUser.getRole().allowedToDelete() == true) {
    //delete
  } else {
    // throw Exception
  }
}

Alternatively, each role could be an interface which reveals all it's available methods. An admin might implement public void deleteUser(long id) with the full functionality, whereas the Guest role implements delete, but it just immediately throws an Exception.

A member might implement both public void deleteUser(long id) and public void deleteUser(long id, String authkey), with the first method throwing an exception and the second one actually deleting (but requiring the authKey).

 delete(long id) {
   try {
     currUser.getRole().operations().delete(id);
   } catch (UnauthorisedRoleException e) {
     // Handle
   }
 }

This could then be extended further with whole subsets of methods only being available to the relevant Roles.

jingle-mod's People

Contributors

jguthrie100 avatar

Watchers

 avatar  avatar

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.