Changeset 47cd40b25bcf0af9685388fb11a88e17704eb4ad

Show
Ignore:
Timestamp:
05/11/08 14:08:27 (2 months ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1210507707 +0200
git-parent:

[e65784fd7de3b5d9a7a20d612f029671d98de9b0]

git-author:
Christopher Jung <bktheg@web.de> 1210507707 +0200
Message:

[ref] Authentifizierung in das Framework ausgelagert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/modules/LogoutController.java

    r34f5892 r47cd40b  
    2020 
    2121import net.driftingsouls.ds2.server.framework.Context; 
     22import net.driftingsouls.ds2.server.framework.authentication.AuthenticationManager; 
     23import net.driftingsouls.ds2.server.framework.authentication.DefaultAuthenticationManager; 
    2224import net.driftingsouls.ds2.server.framework.pipeline.generators.Action; 
    2325import net.driftingsouls.ds2.server.framework.pipeline.generators.ActionType; 
     
    5153        @Action(ActionType.DEFAULT) 
    5254        public void defaultAction() { 
    53                 getDB().createQuery("delete from Session where session= :sess or attach= :sess") 
    54                         .setString("sess", getContext().getSession()) 
    55                         .executeUpdate(); 
     55                AuthenticationManager manager = new DefaultAuthenticationManager(); 
     56                manager.logout(); 
    5657        } 
    5758} 
  • src/net/driftingsouls/ds2/server/modules/PortalController.java

    rf85a0d8 r47cd40b  
    4646import net.driftingsouls.ds2.server.framework.Context; 
    4747import net.driftingsouls.ds2.server.framework.Session; 
     48import net.driftingsouls.ds2.server.framework.authentication.AccountDisabledException; 
     49import net.driftingsouls.ds2.server.framework.authentication.AuthenticationException; 
     50import net.driftingsouls.ds2.server.framework.authentication.AuthenticationManager; 
     51import net.driftingsouls.ds2.server.framework.authentication.DefaultAuthenticationManager; 
     52import net.driftingsouls.ds2.server.framework.authentication.LoginDisabledException; 
     53import net.driftingsouls.ds2.server.framework.authentication.TickInProgressException; 
     54import net.driftingsouls.ds2.server.framework.authentication.WrongPasswordException; 
    4855import net.driftingsouls.ds2.server.framework.db.Database; 
    4956import net.driftingsouls.ds2.server.framework.db.SQLQuery; 
     
    5461import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 
    5562import net.driftingsouls.ds2.server.uilibs.PlayerList; 
     63import net.driftingsouls.ds2.server.user.authentication.AccountInVacationModeException; 
    5664 
    5765import org.apache.commons.lang.math.RandomUtils; 
     
    730738        @Action(ActionType.DEFAULT) 
    731739        public void loginAction() { 
    732                 Database database = getDatabase(); 
    733                 org.hibernate.Session db = getDB(); 
    734                 TemplateEngine t = getTemplateEngine(); 
     740                TemplateEngine t = getTemplateEngine(); 
     741                 
     742                AuthenticationManager manager = new DefaultAuthenticationManager(); 
    735743                 
    736744                parameterString("username"); 
     
    741749                String password = getString("password"); 
    742750                int usegfxpak = getInteger("usegfxpak") != 0 ? 1 : 0; 
    743                 boolean clear = false; 
    744                  
    745                 String disablelogin = database.first("SELECT disablelogin FROM config").getString("disablelogin"); 
    746                 if( !"".equals(disablelogin) ) { 
    747                         username = ""; 
    748                         password = ""; 
    749                         clear = true; 
    750                  
    751                         t.setVar(       "show.login.logindisabled", 1, 
    752                                                 "login.logindisabled.msg", Common._text(disablelogin) ); 
    753                 } 
    754  
    755                 if( !"".equals(username) && !"".equals(password) ) { 
    756                         String enc_pw = Common.md5(password); 
    757  
    758                         User user = (User)db.createQuery("from User where un=:username") 
    759                                 .setString("username", username) 
    760                                 .uniqueResult(); 
    761                          
    762                         if( user == null ) { 
     751                 
     752                if( !username.isEmpty() && !password.isEmpty() ) { 
     753                        try { 
     754                                Session session = manager.login(username, password, usegfxpak != 0); 
     755                                 
     756                                doLogin(session); 
     757                                 
     758                                return; 
     759                        } 
     760                        catch( LoginDisabledException e ) { 
     761                                t.setVar(       "show.login.logindisabled", 1, 
     762                                                        "login.logindisabled.msg", Common._text(e.getMessage()) ); 
     763                                 
     764                                return; 
     765                        } 
     766                        catch( AccountInVacationModeException e ) { 
     767                                t.setVar(        
     768                                                "show.login.vacmode", 1, 
     769                                                "login.vacmode.dauer", Common.ticks2Days(e.getDauer()), 
     770                                                "login.vacmode.username", username, 
     771                                                "login.vacmode.password", password); 
     772                                 
     773                                return; 
     774                        } 
     775                        catch( WrongPasswordException e ) { 
    763776                                t.setVar( "show.msg.login.wrongpassword",1 ); 
    764                                 Common.writeLog("login.log", Common.date("j.m.Y H:i:s")+": <"+getRequest().getRemoteAddress()+"> ("+username+") <"+username+"> Password <"+password+"> ***UNGUELTIGER ACCOUNT*** von Browser <"+getRequest().getUserAgent()+">\n"); 
    765                                 clear = false; 
    766                         } 
    767                         else { 
    768                         if( !user.getPassword().equals(enc_pw) ) { 
    769                                         t.setVar( "show.msg.login.wrongpassword",1 ); 
    770                                         user.setLoginFailedCount(user.getLoginFailedCount()+1); 
    771                                         Common.writeLog("login.log", Common.date("j.m.Y H:i:s")+": <"+getRequest().getRemoteAddress()+"> ("+user.getId()+") <"+username+"> Password <"+password+"> ***LOGIN GESCHEITERT*** von Browser <"+getRequest().getUserAgent()+">\n"); 
    772                                         clear = false; 
    773                                 } 
    774                                 else if( user.getDisabled() ) { 
    775                                         t.setVar("show.login.msg.accdisabled",1); 
    776                                         Common.writeLog("login.log", Common.date( "j.m.Y H:i:s")+": <"+getRequest().getRemoteAddress()+"> ("+user.getId()+") <"+username+"> Password <"+password+"> ***VAC LOGIN*** von Browser <"+getRequest().getUserAgent()+">\n"); 
    777          
    778                                         db.createQuery("delete from Session where id=?") 
    779                                                 .setInteger(0, user.getId()) 
    780                                                 .executeUpdate(); 
    781                                          
    782                                         clear = false; 
    783                                 } 
    784                                 else if( (user.getVacationCount() > 0) && (user.getWait4VacationCount() == 0) ) { 
    785                                         db.createQuery("delete from Session where id=?") 
    786                                                 .setInteger(0, user.getId()) 
    787                                                 .executeUpdate(); 
    788                                          
    789                                         t.setVar(        
    790                                                         "show.login.vacmode", 1, 
    791                                                         "login.vacmode.dauer", Common.ticks2Days(user.getVacationCount()), 
    792                                                         "login.vacmode.username", username, 
    793                                                         "login.vacmode.password", password); 
    794                                          
    795                                         clear = true; 
    796                                 } 
    797                                 else { 
    798                                         Session session = (Session)getDB().createQuery("from Session where id=? and tick!=0") 
    799                                                 .setInteger(0, user.getId()) 
    800                                                 .uniqueResult(); 
    801                  
    802                                         if( session != null ) { 
    803                                                 t.setVar("show.login.msg.tick",1); 
    804                                                 clear = false; 
    805                                         } 
    806                                         else{ 
    807                                                 doLogin(user, usegfxpak); 
    808          
    809                                                 clear = true; 
    810                                         } 
    811                                 } 
    812                         } 
    813                 } 
    814  
    815                 if( !clear ) { 
    816                         t.setVar(       "show.login", 1, 
    817                                                 "login.username", username ); 
    818                 } 
    819         } 
    820  
    821         private void doLogin(User user, int usegfxpak) { 
    822                 TemplateEngine t = getTemplateEngine(); 
    823                  
    824                 Common.writeLog("login.log",Common.date( "j.m.Y H:i:s")+": <"+getRequest().getRemoteAddress()+"> ("+user.getId()+") <"+user.getUN()+"> Login von Browser <"+getRequest().getUserAgent()+">\n"); 
    825  
    826                 getDB().createQuery("delete from Session where user=? and attach is null") 
    827                         .setEntity(0, user) 
    828                         .executeUpdate(); 
    829                  
    830                 Session session = new Session(user); 
    831                 session.setIP("<"+getRequest().getRemoteAddress()+">"); 
    832                 session.setUseGfxPak(usegfxpak != 0); 
    833                 getDB().persist(session); 
    834                  
    835                 getContext().commit(); 
     777                        } 
     778                        catch( AccountDisabledException e ) { 
     779                                t.setVar("show.login.msg.accdisabled",1); 
     780                        } 
     781                        catch( TickInProgressException e ) { 
     782                                t.setVar("show.login.msg.tick",1); 
     783                        } 
     784                        catch( AuthenticationException e ) { 
     785                                // EMPTY 
     786                        } 
     787                } 
     788 
     789                t.setVar(       "show.login", 1, 
     790                                        "login.username", username ); 
     791        } 
     792 
     793        private void doLogin(Session session) { 
     794                TemplateEngine t = getTemplateEngine(); 
    836795 
    837796                t.setVar(       "show.login.msg.ok", 1, 
    838797                                        "login.sess", session.getSession() ); 
    839798                 
     799                User user = (User)session.getUser(); 
     800                 
    840801                // Ueberpruefen ob das gfxpak noch aktuell ist 
    841                 if( (usegfxpak != 0) && !user.getUserImagePath().equals(BasicUser.getDefaultImagePath()) ) { 
     802                if( session.getUseGfxPak() && !user.getUserImagePath().equals(BasicUser.getDefaultImagePath()) ) { 
    842803                        t.setVar(       "login.checkgfxpak", 1, 
    843804                                                "login.checkgfxpak.path", user.getUserImagePath() ); 
  • src/net/driftingsouls/ds2/server/modules/admin/PlayerLoginSuper.java

    r283e6c7 r47cd40b  
    2323import net.driftingsouls.ds2.server.framework.ContextMap; 
    2424import net.driftingsouls.ds2.server.framework.Session; 
     25import net.driftingsouls.ds2.server.framework.authentication.AuthenticationException; 
     26import net.driftingsouls.ds2.server.framework.authentication.AuthenticationManager; 
     27import net.driftingsouls.ds2.server.framework.authentication.DefaultAuthenticationManager; 
    2528import net.driftingsouls.ds2.server.modules.AdminController; 
    2629 
     
    6265                        } 
    6366                         
    64                         Session session = new Session(userObj); 
    65                         session.setIP("<"+context.getRequest().getRemoteAddress()+">"); 
    66                         session.setUseGfxPak(false); 
    67                         if( usesessid != 0 ) { 
    68                                 session.setAttach(context.getSession()); 
     67                        try { 
     68                               AuthenticationManager manager = new DefaultAuthenticationManager(); 
     69                               Session session = manager.adminLogin(userObj, usesessid != 0); 
     70                                
     71                                echo.append("<a class=\"ok\" target=\"_blank\" href=\"./ds?sess="+session.getSession()+"&module=main\">Zum Account</a>\n"); 
    6972                        } 
    70                         context.getDB().save(session); 
    71                          
    72                         echo.append("<a class=\"ok\" target=\"_blank\" href=\"./ds?sess="+session.getSession()+"&module=main\">Zum Account</a>\n"); 
     73                        catch( AuthenticationException e ) { 
     74                                echo.append("<span style=\"color:red\">"+e.getMessage()+"</span>"); 
     75                                return; 
     76                        } 
    7377                } 
    7478        }