authenicateservicebean.java.svn-base

来自「EJB3 Annotation Sample」· SVN-BASE 代码 · 共 69 行

SVN-BASE
69
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.s7turn.security.session;import com.s7turn.security.entity.Account;import com.s7turn.security.entity.AccountRole;import java.rmi.RemoteException;import java.util.List;import javax.ejb.Stateless;import javax.persistence.EntityManager;import javax.persistence.NoResultException;import javax.persistence.PersistenceContext;import javax.persistence.Query;/** * * @author Long */@Statelesspublic class AuthenicateServiceBean implements AuthenicateServiceRemote, AuthenicateServiceLocal {    @PersistenceContext(unitName="s7turn-pu")    private EntityManager em;        public String[] authenicate(String userName, String passwd) throws RemoteException {        Query query = em.createNamedQuery("Account.findByLongIdAndPassword");        query.setParameter("loginId", userName);        System.out.println("authenicate service called.");        //Todo: check the password should be md5 first.                query.setParameter("password", passwd);        try{            Account account = (Account) query.getSingleResult();            System.out.println("authenicate service found the user.");            if( account != null )            {                Query roleRquery = em.createNamedQuery("AccountRole.findByAccount");                roleRquery.setParameter("account", account);                List<AccountRole> ss = roleRquery.getResultList();                String[] roles = new String[ ss.size() ];                int i = 0;                for( AccountRole r : ss ){                    roles[i] = r.getRole().getRoleName();                    i ++;                }                System.out.println("authenicate found the roles.");                return roles;            }            System.out.println("authenicate not found the roles.");            return new String[]{ "registered", "general" };                                 }catch(NoResultException ne)        {            //return new String[]{ "registered", "general" };             ne.printStackTrace();            System.out.println("exception." + ne);        }        return new String[0];    }        // Add business logic below. (Right-click in editor and choose    // "EJB Methods > Add Business Method" or "Web Service > Add Operation") }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?