Java 身份验证播放框架重定向到页面不';行不通

Java 身份验证播放框架重定向到页面不';行不通,java,jakarta-ee,playframework,playframework-1.x,Java,Jakarta Ee,Playframework,Playframework 1.x,我有登录页面,我添加了一些配置文件,所以在添加一些之后,我会为每个配置文件和HTML页面配置控制器。当我使用正确的用户名和密码时。重定向到每个配置文件的索引页面不起作用,它们将我重定向到登录页面 > 公共类安全性扩展了安全性{ static boolean authenticate(String login, String password) { return UserGcv.connect(login, password) != null; } static void onDis

我有登录页面,我添加了一些配置文件,所以在添加一些之后,我会为每个配置文件和HTML页面配置控制器。当我使用正确的用户名和密码时。重定向到每个配置文件的索引页面不起作用,它们将我重定向到登录页面

>

公共类安全性扩展了安全性{

static boolean authenticate(String login, String password) {

    return UserGcv.connect(login, password) != null;

}

static void onDisconnected() {
    Application.index();
}

static void onAuthenticated() {
    UserGcv user = UserGcv.find("byLogin", connected()).first();

    Cache.set("user_" + session.get("username"), user, "30min");


    switch (user.profil) {
        case ADMIN:
            Administration.showUsers();
            break;
        case DMC:
            Catalogs.consultArticle();
            break;
        case DCGP:
            DCGPArticle.consultArticleDCGP();
            break;
        case DCE:
            DCEArticle.consultArticleDCE();
            break;
        case Planificateur:
            Planificateur.composerVersion();
            break;
        case ValidAvantage:
            ValidateurAvantage.homeValidateur();
            break;
        case PARAMETRAGE:
            PARAMETRAGE.createParam();
            break;
        case ConfAvantage:
            ConfigAvantage.homeConfigurateur();
            break;

    }

} }
UserGCV.java

包装模型

@实体@Table(name=“user\u gcv”)@带有(Secure.class)公共类 UserGcv扩展模型{

@Column(name = "user_name")
public String userName;
@Column(name = "user_last_name")
public String userLastName;
@Column(name = "user_direction")
public String userDirection;
@Column(name = "user_phone_number")
public Integer userPhoneNumber;
@Column(name = "user_cin")
public Integer userCin;
@Column(name = "user_fonction")
public String userFonction;
@Column(name = "login")
public String login;
@Column(name = "password")
public String password;
@Column(name = "user_mail_address")
@Email
public String userMailAddress;
@Enumerated(EnumType.STRING)
public Profil profil;
@Column(name = "actif")
public int actif;
@OneToMany(mappedBy = "utilisateur")
List<Trace> traces = new ArrayList();

public UserGcv(Long id, String userName, String userLastName,
        String userDirection, Integer userPhoneNumber, Integer userCin,
        String userFonction, String login, String password,
        String userMailAddress, Profil profil, int actif) {
    this.id = id;
    this.userName = userName;
    this.userLastName = userLastName;
    this.userDirection = userDirection;
    this.userPhoneNumber = userPhoneNumber;
    this.userCin = userCin;
    this.userFonction = userFonction;
    this.login = login;
    this.password = password;
    this.userMailAddress = userMailAddress;
    this.profil = profil;
    this.actif = actif;

}

public UserGcv() {
}

public static UserGcv connect(String login, String password) {

    return find("select distinct u from UserGcv u where login=? and password=? and actif=?", login, password, 1).first();

}

public UserGcv(String login, String password) {
    this.login = login;
    this.password = password;

}
我在Secure.Security中对该方法进行了身份验证,它为url返回null

static void onAuthenticated() {

        UserGcv user = UserGcv.find("byLogin", connected()).first();
        Cache.set("user_" + session.get("username"), user, "60min");
        System.err.println("usecccccccccccccccccccccr"+user);
        switch (user.profil) {
            case ADMIN:
                Administration.showUsers();
                break;
            case DMC:
                Catalogs.consultArticle();
                break;
            case DCGP:
                DCGPArticle.consultArticleDCGP();
                break;
            case DCE:
                DCEArticle.consultArticleDCE();
                break;
            case Planificateur:
                Planificateur.composerVersion();
                break;
            case ValidAvantage:
                ValidateurAvantage.homeValidateur();
                break;
            case PARAMETRAGE:
                PARAMETRAGE.createParam();
                break;
            case ConfAvantage:
               ConfigAvantage.homeConfigurateur();
                break;
        }

问题是,当自定义安全类从Secure.security扩展时,他没有覆盖onAuthenticated方法,因此解决方案是将自定义onAuthenticated实现到默认类中

 public static class Security extends Controller {

        /**
         * @Deprecated
         *
         * @param username
         * @param password
         * @return
         */
        static boolean authentify(String username, String password) {
            throw new UnsupportedOperationException();
        }

        /**
         * This method is called during the authentication process. This is
         * where you check if the user is allowed to log in into the system.
         * This is the actual authentication process against a third party
         * system (most of the time a DB).
         *
         * @param username
         * @param password
         * @return true if the authentication process succeeded
         */
        static boolean authenticate(String username, String password) {
            return true;
        }

        /**
         * This method checks that a profile is allowed to view this
         * page/method. This method is called prior to the method's controller
         * annotated with the @Check method.
         *
         * @param profile
         * @return true if you are allowed to execute this controller method.
         */
        static boolean check(String profile) {
            return true;
        }

        /**
         * This method returns the current connected username
         *
         * @return
         */
        static String connected() {
            return session.get("username");
        }

        /**
         * Indicate if a user is currently connected
         *
         * @return true if the user is connected
         */
        static boolean isConnected() {
            return session.contains("username");
        }

        /**
         * This method is called after a successful authentication. You need to
         * override this method if you with to perform specific actions (eg.
         * Record the time the user signed in)
         */
        static void onAuthenticated() {

            UserGcv user = UserGcv.find("byLogin", connected()).first();

            Cache.set("user_" + session.get("username"), user, "60min");

            switch (user.profil) {
                case ADMIN:
                    Administration.showUsers();
                    break;
                case DMC:
                    Catalogs.consultArticle();
                    break;
                case DCGP:
                    DCGPArticle.consultArticleDCGP();
                    break;
                case DCE:
                    DCEArticle.consultArticleDCE();
                    break;
                case Planificateur:
                    Planificateur.composerVersion();
                    break;
                case PARAMETRAGE:
                    PARAMETRAGE.createParam();
                    break;
                case ConfAvantage:
                    ConfigAvantage.homeConfigurateur();
                    break;
                case ValidAvantage:
                    ValidateurAvantage.homeValidateur();
                    break;
                case PlanifDSC:
                    PlanifDSC.homePlanifDSC();
                    break;
            }
        }

我检查了在安全中进行身份验证的方法。安全性为URL返回null
    # Routes

    # Import Secure routes
    #*       /                                       module:secure 
GET  /                                           Secure.login 
POST     /                                       Secure.authenticate 
GET      /logout                                 Secure.logout

    # Home page
    #GET     /                                       Application.index

    # Administration page 
GET     /administration/user/edit/{id}         Administration.editUser 
GET     /administration/new                    Administration.newUser
 GET     /administration/user/save/{id}         Administration.save 
POST    /administration/new                    Administration.save 
GET     /administration/script                 Administration.telechargerScript GET     /administration/download      Administration.download 
GET     /administration/details            Administration.detailsVersion 
GET     /administration/traces             Administration.consulterTraces
 GET     /administration/historique       Administration.exportCSVFile

    # DMC page 
GET     /catalog/index                          Catalogs.index
 GET     /catalog/search                         Catalogs.searchArticle 
GET     /catalog/consult                        Catalogs.modifArticle 
GET     /catalog/search                         Catalogs.searchArticleDes
 GET     /pack/modify                            Catalogs.modifPack 
GET /pack/consult                           Catalogs.consultPack

    GET     /catalogues/getListArticle/?           Catalogs.getListArticle 
POST    /pack/new                              Catalogs.savePack

    # DCGP page 
GET     /dcepack/consultpackdce                 DCEPack.consultPackDCE 
GET     /dcgp/articles                          DCGP.allArticle 
GET     /dcgp/delete                            DCGP.deleteArticle 
GET     /dcgp/facture                           DCGP.generateFacture 
GET     /dcgp/modify                            DCGP.modifyArticle 
GET     /dcgp/valid                             DCGP.validPack 
GET     /dcgppack/consultpackdcgp               DCGPPack.consultPackDCGP

    # Planificateur page

GET     /Planificateur/composer          Planificateur.composerVersion 
GET     /Planificateur/planifierAvantage Planificateur.homePlanificateur

    # Parametrage page 
POST    /parametrage/new                              Parametrage.saveParam
    # Configurateur Avantage pages 
GET     /ConfigAvantage/homeConfigurateur     ConfigAvantage.homeConfigurateur GET     /ConfigAvantage/modifierAvantage/?   ConfigAvantage.modifierAvantage 
GET     /ConfigAvantage/searchPackToAffectation/?ConfigAvantage.searchPackToAffectation 
GET     /VersionAvantage/goToGPS                    VersionAvantage.goToGPS 
GET     /ConfigAvantage/viewAvantageDetails/?     ConfigAvantage.viewAvantageDetails 
GET     /ConfigAvantage/affectationPackView/?     ConfigAvantage.affectationPackView

    #Validateur Avantage Pages 
 GET    /ValidateurAvantage/homeValidateur         ValidateurAvantage.homeValidateur

    # Ignore favicon requests 
GET     /favicon.ico                            404

    # Map static resources from the /app/public folder to the /public path 
GET     /public/                                staticDir:public


    # Import CRUD routes
    *      /admin                                   module:crud

    # Catch all
*       /{controller}/{action}                  {controller}.{action}
static void onAuthenticated() {

        UserGcv user = UserGcv.find("byLogin", connected()).first();
        Cache.set("user_" + session.get("username"), user, "60min");
        System.err.println("usecccccccccccccccccccccr"+user);
        switch (user.profil) {
            case ADMIN:
                Administration.showUsers();
                break;
            case DMC:
                Catalogs.consultArticle();
                break;
            case DCGP:
                DCGPArticle.consultArticleDCGP();
                break;
            case DCE:
                DCEArticle.consultArticleDCE();
                break;
            case Planificateur:
                Planificateur.composerVersion();
                break;
            case ValidAvantage:
                ValidateurAvantage.homeValidateur();
                break;
            case PARAMETRAGE:
                PARAMETRAGE.createParam();
                break;
            case ConfAvantage:
               ConfigAvantage.homeConfigurateur();
                break;
        }
 public static class Security extends Controller {

        /**
         * @Deprecated
         *
         * @param username
         * @param password
         * @return
         */
        static boolean authentify(String username, String password) {
            throw new UnsupportedOperationException();
        }

        /**
         * This method is called during the authentication process. This is
         * where you check if the user is allowed to log in into the system.
         * This is the actual authentication process against a third party
         * system (most of the time a DB).
         *
         * @param username
         * @param password
         * @return true if the authentication process succeeded
         */
        static boolean authenticate(String username, String password) {
            return true;
        }

        /**
         * This method checks that a profile is allowed to view this
         * page/method. This method is called prior to the method's controller
         * annotated with the @Check method.
         *
         * @param profile
         * @return true if you are allowed to execute this controller method.
         */
        static boolean check(String profile) {
            return true;
        }

        /**
         * This method returns the current connected username
         *
         * @return
         */
        static String connected() {
            return session.get("username");
        }

        /**
         * Indicate if a user is currently connected
         *
         * @return true if the user is connected
         */
        static boolean isConnected() {
            return session.contains("username");
        }

        /**
         * This method is called after a successful authentication. You need to
         * override this method if you with to perform specific actions (eg.
         * Record the time the user signed in)
         */
        static void onAuthenticated() {

            UserGcv user = UserGcv.find("byLogin", connected()).first();

            Cache.set("user_" + session.get("username"), user, "60min");

            switch (user.profil) {
                case ADMIN:
                    Administration.showUsers();
                    break;
                case DMC:
                    Catalogs.consultArticle();
                    break;
                case DCGP:
                    DCGPArticle.consultArticleDCGP();
                    break;
                case DCE:
                    DCEArticle.consultArticleDCE();
                    break;
                case Planificateur:
                    Planificateur.composerVersion();
                    break;
                case PARAMETRAGE:
                    PARAMETRAGE.createParam();
                    break;
                case ConfAvantage:
                    ConfigAvantage.homeConfigurateur();
                    break;
                case ValidAvantage:
                    ValidateurAvantage.homeValidateur();
                    break;
                case PlanifDSC:
                    PlanifDSC.homePlanifDSC();
                    break;
            }
        }