Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Secure.java class of the play framework

Is it advisable to make changes in the methods of the Secure class of play framework? Or is there a way around it?

like image 463
developer_joe Avatar asked Dec 12 '22 11:12

developer_joe


1 Answers

Secure.class no. Security.class yes.

To make changes to the Secure.class. No, normally, it should be ok in most cases. But, you will have to extend Security class. There are several methods in this class that have to be overridden to fit your application.

static boolean authenticate(String username, String password);
static boolean check(String profile);
static String connected();
static void onAuthenticated();
static void onDisconnect();
static void onDisconnected();

EDIT : After reading all the comments and understanding Joe's real need, here is part of the solution.

  1. Create a normal login page. You can do this by adding the secure dependency in your dependencies.yml file. (Also run play dependencies)
  2. Extends Security for overriding of authenticate method.
  3. Also override onAuthenticate method to redirect toward the page of yuor choice using redirect()
  4. Create a new tag loginbox.html in tags folder. Code is pasted below.
  5. Use loginbox tag in your homepage : #{loginbox /}

That means :

  • You will have a login box on homepage.
  • When users login authenticate, they will be redirected to the page of your choice.
  • When users login fails, they will be redirected toward the login page and will see errors there.

loginbox.html

#{form @authenticate()}
    <label>Login</label>
    <input type="text" name="username" maxlength="80"/>

    <label>Password</label>
    <input type="password" name="password" maxlength="80"/>

    <input type="submit" class="rounded" value="Se connecter" />
#{/form}
like image 105
i.am.michiel Avatar answered Jan 30 '23 23:01

i.am.michiel