1 16 package org.apache.cocoon.portal.security; 17 18 import java.util.Collection ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.cocoon.ojb.samples.bean.User; 23 import org.apache.ojb.broker.PersistenceBroker; 24 import org.apache.ojb.broker.PersistenceBrokerFactory; 25 import org.apache.ojb.broker.query.Criteria; 26 import org.apache.ojb.broker.query.Query; 27 import org.apache.ojb.broker.query.QueryByCriteria; 28 import org.osoco.cowarp.AbstractSecurityHandler; 29 import org.osoco.cowarp.ApplicationManager; 30 31 34 public class DBSecurityHandler 35 extends AbstractSecurityHandler { 36 37 40 public org.osoco.cowarp.User login(Map loginContext) throws Exception { 41 PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); 42 43 try { 44 Parameters para = (Parameters) loginContext.get(ApplicationManager.LOGIN_CONTEXT_PARAMETERS_KEY); 45 46 final Criteria criteria = new Criteria(); 47 criteria.addEqualTo("username", para.getParameter("name")); 48 criteria.addEqualTo("password", para.getParameter("password")); 49 final Query query = new QueryByCriteria(User.class, criteria); 50 final Collection c = broker.getCollectionByQuery(query); 51 52 if ( c.size() == 1 ) { 53 User u = (User)c.iterator().next(); 54 PortalUser pUser = new PortalUser(u.getUsername()); 55 pUser.setUid(u.getUid()); 56 pUser.setFirstname(u.getFirstname()); 57 pUser.setLastname(u.getLastname()); 58 pUser.setPassword(u.getPassword()); 59 pUser.setRole(u.getRole()); 60 if ( this.getLogger().isInfoEnabled() ) { 61 this.getLogger().info("Loggedin as: " + u.getFirstname() + " " + u.getLastname() + " (" + u.getUsername() + " " + u.getRole() +")"); 62 } 63 return pUser; 64 } 65 } finally { 66 broker.close(); 67 } 68 return null; 69 } 70 71 74 public void logout(Map context, org.osoco.cowarp.User user) { 75 } 77 } 78 | Popular Tags |