logo
down
shadow

play action composition delegate to separate call


play action composition delegate to separate call

By : Thin
Date : November 19 2020, 01:01 AM
I wish did fix the issue. I am trying to use action composition in play to check the logged in user in each class methods, I can't find out how I can redirect the user to login screen if no session is present, , got it working with
return F.Promise.pure(redirect("/index"));
code :


Share : facebook icon twitter icon
Scala Play 2: action composition and BodyParser

Scala Play 2: action composition and BodyParser


By : Zhivko Zhivkov
Date : March 29 2020, 07:55 AM
this will help Answering my own question, still not sure if this is the most elegant but it works:
code :
def CheckLogin(bp: BodyParser[AnyContent] = parse.anyContent)(f: Context => Result) = {
    Action(bp) { request =>
    // ...
How to change the wrapped action call during action composition in play framework 2.0

How to change the wrapped action call during action composition in play framework 2.0


By : Archit0202
Date : March 29 2020, 07:55 AM
this one helps. I don't believe you can change the method the call gets delegate back to, but you can just do a redirect to your logout route.
code :
if (...)
   return delegate.call(ctx);
else
   return redirect(routes.Controller.logout()); //reverse-route to your logout() method
// -- Action.class
return Controller.doLogout(ctx);

// -- Controller.java
public static Result logout()
{
  // defined in your routes file but it just calls doLogout
  return doLogout(ctx());
}

public static Result doLogout(Context ctx)
{
  // this method does your actual "logout" process
  ctx.session().clear();
  return ...;
}
How to catch exception with action composition in Play 2.3.X

How to catch exception with action composition in Play 2.3.X


By : Aidy
Date : March 29 2020, 07:55 AM
Hope this helps After some investigation, the guilty is the Security action of Play. More details here : https://groups.google.com/forum/#!topic/play-framework/AY4NuQziYyM
Because I added my custom actions at AbstractController level and the @Authenticated(Authenticator.class) annotation at the controller level, the security action composition is the last one to be executed.
Play: How to implement action composition

Play: How to implement action composition


By : Ralf Hendel
Date : March 29 2020, 07:55 AM
it helps some times Function async is expecting a Future[SimpleResult], but the nested SecuredAction.async is returning an Action to the top SignedAction.async (notes that in your sample code you omit to declare requests as class and SignedAction is declared twice).
You can compose result of nested SecuredAction within SignedAction by applying it to the signed request.
code :
package controllers

import scala.concurrent.Future

import play.api._
import play.api.mvc._

case class SignedRequest[A](request: Request[A]) 
    extends WrappedRequest[A](request) {}

object SignedAction extends ActionBuilder[SignedRequest] {

  def invokeBlock[A](request: Request[A], 
    block: SignedRequest[A] => Future[Result]) = 
    block(new SignedRequest(request))

}     

case class SecuredRequest[A](request: Request[A]) 
    extends WrappedRequest[A](request) {}

object SecuredAction extends ActionBuilder[SecuredRequest] {

  def invokeBlock[A](request: Request[A], 
    block: SecuredRequest[A] => Future[Result]) = 
    block(new SecuredRequest(request))

}

object MyController extends Controller {
  def doSomething = SignedAction.async(parse.json) { signedReq =>
    SecuredAction.async(parse.json) { implicit securedReq =>
      Future.successful(Ok)
    } apply signedReq
  }
}
package controllers

import scala.concurrent.Future

import play.api._
import play.api.mvc._

case class SignedRequest[A](request: Request[A])
case class SecuredRequest[A](request: Request[A]) 

object MyController extends Controller {
  def Signed[A](bodyParser: BodyParser[A])(signedBlock: SignedRequest[A] => Future[Result]): Action[A] = Action.async(bodyParser) { req => 
    signedBlock(SignedRequest(req)) 
  }

  def Secured[A](bodyParser: BodyParser[A])(securedBlock: SecuredRequest[A] => Future[Result]): Action[A] = Action.async(bodyParser) { req => 
    securedBlock(SecuredRequest(req)) 
  }

  def doSomething = Signed(parse.json) { signedReq =>
    Secured(parse.json) { implicit securedReq =>
      Future.successful(Ok)
    } apply signedReq.request
  }
}
package controllers

import scala.concurrent.Future

import play.api._
import play.api.mvc._
import play.api.libs.json.JsValue

case class SignedRequest[A](request: Request[A])
case class SecuredRequest[A](request: Request[A]) 

object MyController extends Controller {
  def Signed[A](signedBlock: SignedRequest[A] => Future[Result])(implicit req: Request[A]): Future[Result] = signedBlock(SignedRequest(req))

  def Secured[A](signedBlock: SecuredRequest[A] => Future[Result])(implicit req: Request[A]): Future[Result] = signedBlock(SecuredRequest(req))

  def doSomething = Action.async(parse.json) { implicit req =>
    Signed[JsValue] { signedReq =>
      Secured[JsValue] { securedReq => Future.successful(Ok) } 
    }
  }
}
Scala Play Action Composition : Declare ActionBuilder that produces Action by combining several ActionFunction

Scala Play Action Composition : Declare ActionBuilder that produces Action by combining several ActionFunction


By : jgeller
Date : March 29 2020, 07:55 AM
it helps some times You can't do it with an object because an object can not be the result of an expression. But you can make it a def or val, and you can put that in a package object if you want, eg:
code :
package object security {
  val Protected = UserAction andThen CheckUserId
}
Related Posts Related Posts :
  • Stream corrupted exception - invalid code type AC [java]
  • Routing Sysout values to JTextArea
  • GWT RPC serialization for Dynamic Host Page
  • Best Approch of Returning Value from 'getter' Method
  • Understanding xml schemalocation
  • Checking if a PDF is PDF/A 1-a format or not using PDFBOX in java
  • Difference Between Variable and Identifier
  • How to compute two aggregate functions with Java streams?
  • Parse the value of the json to baseadapter in android?
  • JavaFX animation on raspberry pi
  • Solve "unchecked warning" in Java avoiding @suppressWarnings
  • How to specify a new name for a file while moving it to another directory in Java?
  • Popup window not showing up with spinner item selection?
  • how to iterate through json objects in java
  • Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor
  • Getting NoClassDefFoundError while running PMD task from Gradle
  • Matlab drag and drop file from windows explorer to figure (gui)
  • How does scala's actor model make use of C threads and native system threads?
  • Store java.util.Date as key in a Map based on reference equality instead of "value" equality
  • Error when logging into FTP from AsyncTask class using org.apache.commons.net.ftp.FTPClient
  • creating unique index in mongoDB
  • hibernate Query to find record based on substring
  • How many strings are in jvm string pool intern
  • Unable to initialize native-platform. on Jenkins
  • How to create a list of dummy files in Java?
  • Docker: Which approach is better? WAR embedded in image or base image + war?
  • java.lang.InternalError: CallerSensitive annotation expected at frame 1
  • How to write a method to read JSON files of different structures and return different POJO objects in Java?
  • Reference to Classes in Java
  • Unable to call function via companion object
  • REST: convert XML content passed with POST to a java object, attribute inside the element
  • Device not receive message from GCM
  • How to increase Openfire concurrent connection limit?
  • Android send custom parameter on AsyncTask
  • GWT - Get dom element's value from another page
  • How can i initialize an array in Java?
  • Is it possible to increase a java process's(when is running) size?
  • Getting Node Address instead of Value in Binary Search Tree
  • PdfByteContent not adding in iText pdf
  • Spring JpaRepository: delete() with subsequent save() in the same transaction
  • producer-consumer using arraydeque working only in breakpoint
  • Adding a JPanel to another JPanel
  • Comparison with operator ==, how does it work?
  • Error buildling with maven for openshift
  • What is the java equivilant to MySQL's smallint
  • proxy trouble on eclipse with https
  • Spring-Jdbc Template and Prepared statement
  • Mule - exception in Outbound endpoint Message payload is of type: byte[]
  • Modify package names for java classes generated from wsdl
  • How to download multiple images and have one progressBar using AsynTask (Android)
  • Implementing Service Provider, IdP and user in java with SAML (POC)
  • Why does my scanner repeat?
  • Can I forget ResultSetFuture in Cassandra java driver without facing memory leak?
  • XML to JAXB binding having nested elements?
  • Java: ToString() prints the same hashcode each time
  • Why am I getting a thread exception in my graphics program?
  • Can we read 4th byte from hexadecimal value?
  • How to create watermark in image just like Google maps watermarks
  • how come Thread class called inside another class?
  • AssertionError: Unexpected schema version 0: Unexpected schema version 0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org