Changeset 47cd40b25bcf0af9685388fb11a88e17704eb4ad
- Timestamp:
- 05/11/08 14:08:27 (2 months ago)
- git-parent:
- Files:
-
- src/META-INF/services/net.driftingsouls.ds2.server.framework.authentication.LoginEventListener (added)
- src/net/driftingsouls/ds2/server/framework/authentication/AccountDisabledException.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/AuthenticationException.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/AuthenticationManager.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/DefaultAuthenticationManager.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/LoginDisabledException.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/LoginEventListener.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/TickInProgressException.java (added)
- src/net/driftingsouls/ds2/server/framework/authentication/WrongPasswordException.java (added)
- src/net/driftingsouls/ds2/server/modules/LogoutController.java (modified) (2 diffs)
- src/net/driftingsouls/ds2/server/modules/PortalController.java (modified) (4 diffs)
- src/net/driftingsouls/ds2/server/modules/admin/PlayerLoginSuper.java (modified) (2 diffs)
- src/net/driftingsouls/ds2/server/user/authentication/AccountInVacationModeException.java (added)
- src/net/driftingsouls/ds2/server/user/authentication/VacationCheckLoginEventListener.java (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/net/driftingsouls/ds2/server/modules/LogoutController.java
r34f5892 r47cd40b 20 20 21 21 import net.driftingsouls.ds2.server.framework.Context; 22 import net.driftingsouls.ds2.server.framework.authentication.AuthenticationManager; 23 import net.driftingsouls.ds2.server.framework.authentication.DefaultAuthenticationManager; 22 24 import net.driftingsouls.ds2.server.framework.pipeline.generators.Action; 23 25 import net.driftingsouls.ds2.server.framework.pipeline.generators.ActionType; … … 51 53 @Action(ActionType.DEFAULT) 52 54 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(); 56 57 } 57 58 } src/net/driftingsouls/ds2/server/modules/PortalController.java
rf85a0d8 r47cd40b 46 46 import net.driftingsouls.ds2.server.framework.Context; 47 47 import net.driftingsouls.ds2.server.framework.Session; 48 import net.driftingsouls.ds2.server.framework.authentication.AccountDisabledException; 49 import net.driftingsouls.ds2.server.framework.authentication.AuthenticationException; 50 import net.driftingsouls.ds2.server.framework.authentication.AuthenticationManager; 51 import net.driftingsouls.ds2.server.framework.authentication.DefaultAuthenticationManager; 52 import net.driftingsouls.ds2.server.framework.authentication.LoginDisabledException; 53 import net.driftingsouls.ds2.server.framework.authentication.TickInProgressException; 54 import net.driftingsouls.ds2.server.framework.authentication.WrongPasswordException; 48 55 import net.driftingsouls.ds2.server.framework.db.Database; 49 56 import net.driftingsouls.ds2.server.framework.db.SQLQuery; … … 54 61 import net.driftingsouls.ds2.server.framework.templates.TemplateEngine; 55 62 import net.driftingsouls.ds2.server.uilibs.PlayerList; 63 import net.driftingsouls.ds2.server.user.authentication.AccountInVacationModeException; 56 64 57 65 import org.apache.commons.lang.math.RandomUtils; … … 730 738 @Action(ActionType.DEFAULT) 731 739 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(); 735 743 736 744 parameterString("username"); … … 741 749 String password = getString("password"); 742 750 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 ) { 763 776 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(); 836 795 837 796 t.setVar( "show.login.msg.ok", 1, 838 797 "login.sess", session.getSession() ); 839 798 799 User user = (User)session.getUser(); 800 840 801 // 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()) ) { 842 803 t.setVar( "login.checkgfxpak", 1, 843 804 "login.checkgfxpak.path", user.getUserImagePath() ); src/net/driftingsouls/ds2/server/modules/admin/PlayerLoginSuper.java
r283e6c7 r47cd40b 23 23 import net.driftingsouls.ds2.server.framework.ContextMap; 24 24 import net.driftingsouls.ds2.server.framework.Session; 25 import net.driftingsouls.ds2.server.framework.authentication.AuthenticationException; 26 import net.driftingsouls.ds2.server.framework.authentication.AuthenticationManager; 27 import net.driftingsouls.ds2.server.framework.authentication.DefaultAuthenticationManager; 25 28 import net.driftingsouls.ds2.server.modules.AdminController; 26 29 … … 62 65 } 63 66 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"); 69 72 } 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 } 73 77 } 74 78 }
