play-authenticate
An authentication plugin for Play Framework 2.x (Java)
Play! Authenticate
we are working on a Java application built with PlayFramework and deploying it to Heroku. We integrate our login mechanism with Facebook through Play Authenticate, but since this morning, we are not able to log in. We get some secure certificate exception that looks like the attached one.
We were wondering if that might be due some change in the environment, since we don't recall changing any related application code. Is there something we can check?
Thanks in advance,
2013-02-20T17:33:32+00:00 app[web.1]: play.api.Application$$anon$1: Execution exception[[RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty]]
2013-02-20T17:33:32+00:00 app[web.1]:
2013-02-20T17:33:32+00:00 app[web.1]: at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10-2.1.0.jar:2.1.0]
2013-02-20T17:33:32+00:00 app[web.1]: at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.jar:2.1.0]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:508) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:759) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:727) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1118) ~[netty-3.5.9.Final.jar:na]
2013-02-20T17:33:32+00:00 app[web.1]: at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
2013-02-20T17:33:32+00:00 app[web.1]: at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10-2.1.0.jar:2.1.0]
2013-02-20T17:33:32+00:00 app[web.1]: at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.jar:2.1.0]
2013-02-20T17:33:32+00:00 app[web.1]: Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.validator.PKIXValidator.(PKIXValidator.java:75) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.validator.Validator.getInstance(Validator.java:178) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:270) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:225) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
2013-02-20T17:33:32+00:00 app[web.1]: at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at java.security.cert.PKIXBuilderParameters.(PKIXBuilderParameters.java:104) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at java.security.cert.PKIXParameters.(PKIXParameters.java:120) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.validator.PKIXValidator.(PKIXValidator.java:73) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1147) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.validator.Validator.getInstance(Validator.java:178) ~[na:1.6.0_27]
2013-02-20T17:33:32+00:00 app[web.1]: at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:129) ~[na:1.6.0_27]
Source: (StackOverflow)
So I have play 2.0.4 project that I am trying to push to heroku. The project uses the play authenticate plugin and everything works as expected locally so I tried to push it to heroku.
I have spent hours trying to get this to work now but with little luck.
So I have modified my application.conf:
#db.default.driver=org.h2.Driver
db.default.url="the url for my postgres database"
# db.default.user=sa
# db.default.password=
Modified my Procfile:
web: target/start -Dhttp.port=${PORT} -Dplay.version=2.0.4 -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL ${JAVA_OPTS}
Included postgresl in my app dependencies:
val appDependencies = Seq(
"be.objectify" %% "deadbolt-2" % "1.1.3-SNAPSHOT",
"com.feth" %% "play-authenticate" % "0.2.2-SNAPSHOT",
"postgresql" % "postgresql" % "9.1-901.jdbc4"
)
I have a database evolution in conf/evolutions/1.sql:
# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions
# --- !Ups
create table journey (
id bigint not null,
s_lat varchar(255),
s_lon varchar(255),
e_lat varchar(255),
e_lon varchar(255),
start_loc varchar(255),
end_loc varchar(255),
participant_type varchar(255),
date varchar(255),
time varchar(255),
user varchar(255),
constraint pk_journey primary key (id))
;
create table linked_account (
id bigint not null,
user_id bigint,
provider_user_id varchar(255),
provider_key varchar(255),
constraint pk_linked_account primary key (id))
;
create table security_role (
id bigint not null,
role_name varchar(255),
constraint pk_security_role primary key (id))
;
create table token_action (
id bigint not null,
token varchar(255),
target_user_id bigint,
type varchar(2),
created timestamp,
expires timestamp,
constraint ck_token_action_type check (type in ('EV','PR')),
constraint uq_token_action_token unique (token),
constraint pk_token_action primary key (id))
;
create table users (
id bigint not null,
email varchar(255),
name varchar(255),
last_login timestamp,
active boolean,
email_validated boolean,
constraint pk_users primary key (id))
;
create table user_permission (
id bigint not null,
value varchar(255),
constraint pk_user_permission primary key (id))
;
create table users_security_role (
users_id bigint not null,
security_role_id bigint not null,
constraint pk_users_security_role primary key (users_id, security_role_id))
;
create table users_user_permission (
users_id bigint not null,
user_permission_id bigint not null,
constraint pk_users_user_permission primary key (users_id, user_permission_id))
;
create sequence journey_seq;
create sequence linked_account_seq;
create sequence security_role_seq;
create sequence token_action_seq;
create sequence users_seq;
create sequence user_permission_seq;
alter table linked_account add constraint fk_linked_account_user_1 foreign key (user_id) references users (id) on delete restrict on update restrict;
create index ix_linked_account_user_1 on linked_account (user_id);
alter table token_action add constraint fk_token_action_targetUser_2 foreign key (target_user_id) references users (id) on delete restrict on update restrict;
create index ix_token_action_targetUser_2 on token_action (target_user_id);
alter table users_security_role add constraint fk_users_security_role_users_01 foreign key (users_id) references users (id) on delete restrict on update restrict;
alter table users_security_role add constraint fk_users_security_role_securi_02 foreign key (security_role_id) references security_role (id) on delete restrict on update restrict;
alter table users_user_permission add constraint fk_users_user_permission_user_01 foreign key (users_id) references users (id) on delete restrict on update restrict;
alter table users_user_permission add constraint fk_users_user_permission_user_02 foreign key (user_permission_id) references user_permission (id) on delete restrict on update restrict;
# --- !Downs
SET REFERENTIAL_INTEGRITY FALSE;
drop table if exists journey;
drop table if exists linked_account;
drop table if exists security_role;
drop table if exists token_action;
drop table if exists users;
drop table if exists users_security_role;
drop table if exists users_user_permission;
drop table if exists user_permission;
SET REFERENTIAL_INTEGRITY TRUE;
drop sequence if exists journey_seq;
drop sequence if exists linked_account_seq;
drop sequence if exists security_role_seq;
drop sequence if exists token_action_seq;
drop sequence if exists users_seq;
drop sequence if exists user_permission_seq;
I perform the following commands and to try and push to heroku (whilst in my repo directory):
git init
git add .
git commit -m "init"
git push heroku master
The logs look like this when trying to load the application:
2013-05-04T00:57:46.690449+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Djava.rmi.server.useCodebaseOnly=true
2013-05-04T00:57:47.503897+00:00 app[web.1]: Play server process ID is 2
2013-05-04T00:57:49.206353+00:00 app[web.1]: [[37minfo[0m] play - database [default] connected at jdbc:postgresql://ec2-54-235-155-40.compute-1.amazonaws.com:5432/d8837fesm242q7
2013-05-04T00:57:53.439981+00:00 app[web.1]: Oops, cannot start the server.
2013-05-04T00:57:53.439981+00:00 app[web.1]: Position: 23
2013-05-04T00:57:53.439981+00:00 app[web.1]: Query was:
2013-05-04T00:57:53.439981+00:00 app[web.1]: javax.persistence.PersistenceException: Query threw SQLException:ERROR: relation "security_role" does not exist
2013-05-04T00:57:53.439981+00:00 app[web.1]: Bind values:[]
2013-05-04T00:57:53.439981+00:00 app[web.1]: from security_role t0
.....MORE LOGS ....
2013-05-04T00:57:53.442045+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: relation "security_role" does not exist
2013-05-04T00:57:53.442283+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
2013-05-04T00:57:53.442149+00:00 app[web.1]: Position: 23
.... MORE LOGS .....
2013-05-04T00:57:55.121895+00:00 heroku[web.1]: State changed from starting to crashed
2013-05-04T00:57:55.110448+00:00 heroku[web.1]: Process exited with status 255
2013-05-04T01:01:06.387417+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=serene-crag-5945.herokuapp.com fwd="82.24.103.61" dyno= connect= service= status=503 bytes=
I feel like I have tried everything at this point including resetting the heroku database. I have tried pushing the application without the default evolution and I still get the same error. I'm not sure if it has something do with the play-authenticate module as the error would suggest but I doubt it because it works locally using the H2 database without error.
Source: (StackOverflow)
I am trying to create a relationship between the User model of the play-authenticate module and my model - Books. I am using play 2.0.4 and I have integrated play-authenticate into my project. In my controllers/Application I have the getLocalUser method:
public static User getLocalUser(final Session session) {
final User localUser = User.findByAuthUserIdentity(PlayAuthenticate
.getUser(session));
return localUser;
}
I am trying override Model's method in my Books model to save the user who adds/modify book records.
public void save() {
User logged = Application.getLocalUser(session());
if (logged != null) {
this.createUser = logged;
this.modifyUser = logged;
}
super.save();
}
public void update(Object o) {
User logged = Application.getLocalUser(session());
if (logged != null) {
this.modifyUser = logged;
}
super.update(o);
}
The error I get when I do this, which I do not understand is:
The method session() is undefined for the type Books.
I'm not sure how this can be as I do have access to the controller/application methods because of my import:
import controllers.Application;
Update:
*
public static Result createBook() {
Form<Book> filledForm = bookForm.bindFromRequest();
if(filledForm.hasErrors()) {
return badRequest(
views.html.bookCreator.render(Book.all(), filledForm)
);
}
else {
Book.create(filledForm.get());
//Book.save(getLocalUser(session()));
return redirect(routes.Application.createSuccess());
}
}*
Source: (StackOverflow)
When calling
MyAuthProvider.handleSignup(ctx());
Play returns IllegalStateException: No value
This only happens if I call myAccount.save() before calling.
myAccount is an entity model that I create first before I let the system handle the signup and create a user. I use Ebeans.
Thread:
! @6faie6mj9 - Internal server error, for (POST) [/signup] ->
play.api.Application$$anon$1: Execution exception[[IllegalStateException: No value]]
at play.api.Application$class.handleError(Application.scala:289) ~ [play_2.10.jar:2.1.3]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:143) [play_2.10.jar:2.1.3]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:139) [play_2.10.jar:2.1.3]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.3]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.3]
java.lang.IllegalStateException: No value
at play.libs.F$None.get(F.java:547) ~[play_2.10.jar:2.1.3]
at play.data.Form.get(Form.java:525) ~[play-java_2.10.jar:2.1.3]
at com.feth.play.module.pa.providers.password.UsernamePasswordAuthProvider.getSignup(UsernamePasswordAuthProvider.java:153) ~[play-authenticate_2.10-0.2.5-SNAPSHOT.jar:0.2.5-SNAPSHOT]
at com.feth.play.module.pa.providers.password.UsernamePasswordAuthProvider.authenticate(UsernamePasswordAuthProvider.java:84) ~[play-authenticate_2.10-0.2.5-SNAPSHOT.jar:0.2.5-SNAPSHOT]
at com.feth.play.module.pa.PlayAuthenticate.handleAuthentication(PlayAuthenticate.java:442) ~[play-authenticate_2.10-0.2.5-SNAPSHOT.jar:0.2.5-SNAPSHOT]
at com.feth.play.module.pa.providers.password.UsernamePasswordAuthProvider.handleSignup(UsernamePasswordAuthProvider.java:145) ~[play-authenticate_2.10-0.2.5-SNAPSHOT.jar:0.2.5-SNAPSHOT]
Source: (StackOverflow)
It seems the "play-authentication" plugin is not installed if i follow instructions at github https://github.com/joscha/play-authenticate/blob/master/samples/java/Getting%20Started.md
my eclipse IDE cannot find packages starting with "com.feth".
i add the dependencies to Scala.build as described in readme above, then run clean and dependencies then compile..but the com.feth packages are not found. which means the play-auth plugin was not installed correctly.
i wonder if there is a way to install the play-authenticate module correctly . am i missing something in the beside what is mentioned in readme above?
it seems both dependencies of deadbolt-2 and play-authenticate are not resolved and installed. i also remarked a '%%' in the dependencies declaration in Scala.Build. but even if i use a single '%' the dependencies are not resolved and plugins are not installed.
any help is much appreciated
my /project/Scala.Build file is below:
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "r2s2"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"play-aws" % "play-aws_2.9.1" % "0.1",
"be.objectify" %% "deadbolt-2" % "1.1.3-SNAPSHOT",
"com.feth" %% "play-authenticate" % "0.2.3-SNAPSHOT"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
resolvers += Resolver.url("Objectify Play Repository", url("http://schaloner.github.com/releases/"))(Resolver.ivyStylePatterns),
resolvers += Resolver.url("Objectify Play Repository", url("http://schaloner.github.com/snapshots/"))(Resolver.ivyStylePatterns),
resolvers += Resolver.url("play-easymail (release)", url("http://joscha.github.com/play-easymail/repo/releases/"))(Resolver.ivyStylePatterns),
resolvers += Resolver.url("play-easymail (snapshot)", url("http://joscha.github.com/play-easymail/repo/snapshots/"))(Resolver.ivyStylePatterns),
resolvers += Resolver.url("play-authenticate (release)", url("http://joscha.github.com/play-authenticate/repo/releases/"))(Resolver.ivyStylePatterns),
resolvers += Resolver.url("play-authenticate (snapshot)", url("http://joscha.github.com/play-authenticate/repo/snapshots/"))(Resolver.ivyStylePatterns),
resolvers += "Local Play Repository" at "/home/othman/play-2.0.4/repository/local"
)
}
Source: (StackOverflow)
At the moment we're running our Play app on port 9000 with Apache as a front-end HTTP server like so:
<VirtualHost *:80>
ServerName vms.gltd.net
ProxyPass /http-bind http://vms.gltd.net:5280/http-bind/
ProxyPassReverse /http-bind http://vms.gltd.net:5280/http-bind/
ProxyPass / http://vms.gltd.net:9000/
ProxyPassReverse / http://vms.gltd.net:9000/
</VirtualHost>
However when a user signs up Play Authenticate uses the port from play.mvc.Http.Request which is 9000 not 80.
Is there a way to override the port Play Authenticate uses or do we have to move our Play app to its own server and run it on port 80?
thanks,
-Leon
Source: (StackOverflow)
I am planning to replace existing custom authentication with play-authenticate. The REST API returns a token back to the client after successful login and all the subsequent requests add that token as a query parameter.
Looking at the play-authenticate code, user details seem to be stored in the Play Session.
However, I am not sure if the client will use cookies at all. The old version compares the token to the stored value in order to authenticate each request. Obviously I can extend the PlayAuthenticate and override getUser etc methods. Is there a better way to achieve this?
Source: (StackOverflow)
I have integrated the Play-Authenticate module in my Play 2.0.4 project. There are two views to my project, a conventional web view and a mobile view. When the application logs out it just returns to the index page. In the routes table I see that the logout functionality points towards this:
GET /logout com.feth.play.module.pa.controllers.Authenticate.logout
Which looks like this in the module code:
public static Result logout() {
noCache(response());
return PlayAuthenticate.logout(session());
}
The way the application works is there is a main.scala.html file with the css/js links that the web application needs and a mobile_main.scala.html page with the css/js that the contents of the mobile templates use. The problem I am having is that when I sign out of the application (either mobile or web) I get redirected to the index of the web application - index.scala.html. Is there anyway to change this so that I can be directed to the mobile index page when appropriate?
Thanks
Edit: This also applies to the page the application returns to after a successful login.
Ok after looking a bit further I traced the problem back to Global.java. I think I need to change the methods below to solve my problem. So that I can load a different page depending on an argument passed perhaps.
@Override
public Call login() {
// Your login page
return routes.Application.login();
}
@Override
public Call afterAuth() {
// The user will be redirected to this page after authentication
// if no original URL was saved
return routes.Application.index();
}
@Override
public Call afterLogout() {
return routes.Application.index();
}
Source: (StackOverflow)
I am having below class to check the incoming request.
public class SecuredAction extends Action.Simple
{
@Override
public Promise<Result> call(Context ctx) throws Throwable
{
// Not doing anything now. Just interrupting it
return delegate.call(ctx);
}
}
And I am applying it on another controller like
@With(SecuredAction.class)
public class TestController extends BasicController {
public Result method1(){}
public Result method2(){}
--
}
Problem is, in case of multiple requests coming from browser, the requests are getting corrupted / responses are getting mixed up.. In above case, calls to both method1 and method2 are going through only one of them when @With(SecuredAction.class) is used. I am not seeing this issue if this annotation is removed. Is it something to do with Context? Is it not hread safe? What is the right way to do? Any help please?
Source: (StackOverflow)
Does anybody know if there's play framework module that allows you to authorize pages dynamically in Java?
I'm using the play-authenticate/deadbolt modules (http://joscha.github.io/play-authenticate/ and https://github.com/schaloner/deadbolt-2) for the the authentication/authorization mechanism. However, deadbolt doesn't have a straight forward sample on how to implement authorization per page or resource. It does have the ability to create dynamic constrains but the docs are limited and don't tell you if you can create per page authorization using a model or something else.
I'm thinking of creating a model "Page" that allows you to keep track of all the permissions per page dynamically. Is there a better way ?
Thanks.
Source: (StackOverflow)
I am using the play-authenticate plugin in my play-framework project. I want to be able to use the user ID (of the user currently logged in) from the User.java model class of the plugin.
@Id
public Long id;
I want to do this so that when users are creating entries in a separate model class I can store the user who has created these entries. Is there functionality in place to access this information or would I need to write an additional method in the User class to return the active user?
package controllers;
import java.text.SimpleDateFormat;
import java.util.Date;
import models.*;
import models.User;
import play.Routes;
import play.data.Form;
import play.mvc.*;
import play.mvc.Http.Response;
import play.mvc.Http.Session;
import providers.MyUsernamePasswordAuthProvider;
import providers.MyUsernamePasswordAuthProvider.MyLogin;
import providers.MyUsernamePasswordAuthProvider.MySignup;
import play.data.*;
import views.html.*;
import play.*;
import be.objectify.deadbolt.actions.Restrict;
import com.feth.play.module.pa.PlayAuthenticate;
import com.feth.play.module.pa.providers.password.UsernamePasswordAuthProvider;
public class Application extends Controller {
/*Part of the Play-Authenticate authentication plugin for the Play Framework.*/
public static final String FLASH_MESSAGE_KEY = "message";
public static final String FLASH_ERROR_KEY = "error";
public static final String USER_ROLE = "user";
public static User getLocalUser(final Session session) {
final User localUser = User.findByAuthUserIdentity(PlayAuthenticate
.getUser(session));
return localUser;
}
/*Source: https://github.com/joscha/play-authenticate*/
@Restrict(Application.USER_ROLE)
public static Result restricted() {
final User localUser = getLocalUser(session());
return ok(journeyManagement.render(localUser));
}
/*Source: https://github.com/joscha/play-authenticate*/
@Restrict(Application.USER_ROLE)
public static Result profile() {
final User localUser = getLocalUser(session());
return ok(profile.render(localUser));
}
/*Source: https://github.com/joscha/play-authenticate*/
public static Result login() {
return ok(login.render(MyUsernamePasswordAuthProvider.LOGIN_FORM));
}
/*Source: https://github.com/joscha/play-authenticate*/
public static Result doLogin() {
com.feth.play.module.pa.controllers.Authenticate.noCache(response());
final Form<MyLogin> filledForm = MyUsernamePasswordAuthProvider.LOGIN_FORM
.bindFromRequest();
if (filledForm.hasErrors()) {
// User did not fill everything properly
return badRequest(login.render(filledForm));
} else {
// Everything was filled
return UsernamePasswordAuthProvider.handleLogin(ctx());
}
}
/*Source: https://github.com/joscha/play-authenticate*/
public static Result signup() {
return ok(signup.render(MyUsernamePasswordAuthProvider.SIGNUP_FORM));
}
/*Source: https://github.com/joscha/play-authenticate*/
public static Result jsRoutes() {
return ok(
Routes.javascriptRouter("jsRoutes",
controllers.routes.javascript.Signup.forgotPassword()))
.as("text/javascript");
}
/*Source: https://github.com/joscha/play-authenticate*/
public static Result doSignup() {
com.feth.play.module.pa.controllers.Authenticate.noCache(response());
final Form<MySignup> filledForm = MyUsernamePasswordAuthProvider.SIGNUP_FORM
.bindFromRequest();
if (filledForm.hasErrors()) {
// User did not fill everything properly
return badRequest(signup.render(filledForm));
} else {
// Everything was filled
// do something with your part of the form before handling the user
// signup
return UsernamePasswordAuthProvider.handleSignup(ctx());
}
}
/*Source: https://github.com/joscha/play-authenticate*/
public static String formatTimestamp(final long t) {
return new SimpleDateFormat("yyyy-dd-MM HH:mm:ss").format(new Date(t));
}
}
Update:
package models;
import play.mvc.Http.Session;
import controllers.*;
import java.util.*;
import play.db.ebean.*;
import play.data.validation.Constraints.*;
import javax.persistence.*;
import play.data.format.*;
import com.avaje.ebean.*;
import java.text.*;
@Entity
public class Journey extends Model {
public SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("hh:mm");
public SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yy");
@Id
public Long id;
@Required
public String start_loc;
@Required
public String end_loc;
@Required
public String participant_type;
@Required
public String date = simpleDateFormat.format(new Date());
@Required
public String time = simpleTimeFormat.format(new Date());
@ManyToOne
public User createUser;
@ManyToOne
public User modifyUser;
public static Finder<Long,Journey> find = new Finder(
Long.class, Journey.class
);
public static List<Journey> all() {
return find.all();
}
public static void create(Journey journey) {
journey.save();
}
public static void delete(Long id) {
find.ref(id).delete();
}
public static List<Journey> searchByAddress(String address) {
return find.where().ilike("start_loc", "%"+address+"%").findList();
}
public void save() {
User logged = Application.getLocalUser(session());
if (logged != null) {
this.createUser = logged;
this.modifyUser = logged;
}
super.save();
}
public void update(Object o) {
User logged = Application.getLocalUser(session());
if (logged != null) {
this.modifyUser = logged;
}
super.update(o);
}
}
Source: (StackOverflow)
I'm using Play-Authenticate to enable users to login using Google account. Login is working fine. Now, I want to show the profile picture of logged in user.
I see that there is a 'picture' field in the provider.
com.feth.play.module.pa.providers.oauth2.google.GoogleAuthUser
How can I access this field in my controller so that I can show the picture in my views?
Source: (StackOverflow)
I have a working web application that uses the deadbolt module.
Every thing is working fine except that I am unable to add the restrict tag to a view script. I have tried..
@@Restrict( @@Group( "user" ) ) {
<p> Howdy </p>
}
#{deadbolt.restrict roles:[['user']]}
<p> Howdy </p>
#{/deadbolt.restrict}
Both of the above simply get displayed on the page, as text, without interpolation.
However the following works correctly....
@subjectNotPresent() {
Howdy
}
tia, Chet
Source: (StackOverflow)