1 16 17 package org.apache.jetspeed.services.security.nosecurity; 18 19 import org.apache.turbine.services.TurbineBaseService; 20 import org.apache.turbine.services.TurbineServices; 21 import org.apache.turbine.services.InitializationException; 22 23 import org.apache.jetspeed.services.security.PortalAuthentication; 24 import org.apache.jetspeed.services.security.LoginException; 25 26 import org.apache.jetspeed.services.JetspeedSecurity; 27 import org.apache.jetspeed.om.security.JetspeedUser; 28 29 import org.apache.jetspeed.services.security.FailedLoginException; 30 import org.apache.jetspeed.services.rundata.JetspeedRunDataService; 31 import org.apache.jetspeed.services.rundata.JetspeedRunData; 32 import org.apache.jetspeed.services.security.nosecurity.FakeJetspeedUser; 33 import org.apache.turbine.services.rundata.RunDataService; 34 35 43 public class NoAuthentication 44 extends TurbineBaseService 45 implements PortalAuthentication 46 { 47 48 private JetspeedRunDataService m_runDataService = null; 49 50 63 public JetspeedUser login(String username, String password) 64 throws LoginException 65 { 66 if (false) throw new FailedLoginException("Invalid user id or password"); 68 69 FakeJetspeedUser user = new FakeJetspeedUser(username, true); 71 72 putUserIntoContext(user); 74 75 return user; 76 77 } 79 85 public JetspeedUser getAnonymousUser() 86 throws LoginException 87 { 88 FakeJetspeedUser user = new FakeJetspeedUser(JetspeedSecurity.getAnonymousUserName(), false); 90 91 putUserIntoContext(user); 93 94 return user; 95 96 } 98 107 public void logout() 108 throws LoginException 109 { 110 getAnonymousUser(); 112 113 } 115 124 public synchronized void init() 125 throws InitializationException 126 { 127 super.init(); 128 129 m_runDataService = 130 (JetspeedRunDataService)TurbineServices.getInstance() 131 .getService(RunDataService.SERVICE_NAME); 132 133 } 135 137 protected JetspeedRunData getRunData() 138 { 139 JetspeedRunData rundata = null; 140 if (m_runDataService != null) 141 { 142 rundata = m_runDataService.getCurrentRunData(); 143 } 144 return rundata; 145 } 146 147 protected JetspeedUser getUserFromContext() 148 { 149 JetspeedRunData rundata = getRunData(); 150 JetspeedUser user = null; 151 if (rundata != null) 152 { 153 user = (JetspeedUser)rundata.getUser(); 154 } 155 return user; 156 } 157 158 protected JetspeedRunData putUserIntoContext(JetspeedUser user) 159 { 160 JetspeedRunData rundata = getRunData(); 161 if (rundata != null) 162 { 163 rundata.setUser(user); 164 rundata.save(); 165 } 166 return rundata; 167 } 168 } 169 170 | Popular Tags |