Giter VIP home page Giter VIP logo

deadbolt-2-scala-examples's Introduction

deadbolt-2-scala-examples

Example usages of Deadbolt 2's Scala API. Deadbolt 2 is an authorisation module for Play 2.

Deadbolt 2 comprises of several modules - a common core, and language-specific implementations for Java and Scala. Example applications and a user guide are also available.

All modules related to Deadbolt 2, including the user guide, are grouped together in the Deadbolt 2 Github super-module. Installation information, including Deadbolt/Play compatibility, can also be found here.

deadbolt-2-scala-examples's People

Contributors

intracer avatar schaloner avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

deadbolt-2-scala-examples's Issues

deadbolt-scala_2.11;2.5.0-SNAPSHOT: not found

[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: be.objectify#deadbolt-scala_2.11;2.5.0-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::

Difficulty while using play 2.3.10 for Scala with deadbolt 2.3.2

Hi,

I am using deadbolt-scala , version 2.3.2, with play-framework 2.3.10 (scala version: 2.11.7).

I would like to consult, in order to improve the following code. This is a repeatable issue I have in my code.

And the matter is:

When I use Deadbolt in my play framework controllers, sometimes the authorization check is nested inside the inner request. meaning, that in this part I would like to return Future[Result] and not Action[AnyContent].

Since using deadbolt "dynamic" method to add authorization check returns action[A], I need to use apply[request] to force returning Future[Result].

Also, when the original request asynchronous and has body, the returned type is of type Action[JsValue] , so I need to convert it to Action[AnyContent] using asInstanceOf (in order to use the right apply method that will return the expected Future[Result] type ).

This is not such a nice code, and using asInstanceOf[Request[AnyContent]] is a Scala anti-pattern, please advice me if there is a better way of achieving my goal.

Thanks.

Code Example:

def doRequest() = {
            Action.async(parse.json) {
                request => {
                    /** fetch auth_param here **/.flatMap(_ match {
                        case Some(fetched_param) =>
                            performOperationWhenValid(auth_param) 
                        case None =>
                            ..... 
                }.recover {
                    case e => doRecover(e)
                }
            }

    }

 def performOperationWhenValid(auth_param:String) = {
// Authorization check 
        val allow_or_forbid_action = Dynamic(auth_param:String, "",
            new FL_DeadboltHandler(Option(new AuthorizedDynamicResourceHandler))) {
            Action.async {
                request.body.validate[PerformOperationRequest].fold(
                    errors =>
                        Future.successful(BadRequest(formatErrorMessage(errors)))
                    ,
                    patch_request =>
                       /*** performOperation here after authorization check is passed successfully... ***/
            }
        }
        allow_or_forbid_action.apply(request.asInstanceOf[AnyContent])
    }

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.