文本版|topic 高级搜索
   名人堂 帮助 论坛制度 意见反馈 | 首页 博客 周新贴 专题 求职 读书
RSS 底部
 
社区导航: 专家门诊   网络技术   操作系统   数据库   程序设计   系统应用   考试认证   CIO及信息化   站长交流   综合交流   下载基地  51CTO产品服务 设为首页 | 收藏本站
51CTO技术论坛» Mail服务器 » 金迪邮件底层技术探秘之四:用户统一认证、统一管理和单点登录调用接口       [ 打印]  [ 订阅]  [ 收藏]  [ 推荐给朋友]   [ 本帖文本页]

论坛跳转:
     
标题: 金迪邮件底层技术探秘之四:用户统一认证、统一管理和单点登录调用接口  ( 查看:834  回复:1 )   
 
驳客
助理工程师  点击可查看详细



论坛万户侯  
帖子 860
精华 0
无忧币 22002
积分 2076
阅读权限 40
注册日期 2006-3-24
最后登录 2008-8-28 离线

[查看资料]  [发短消息]  [Blog
[个人主页]    QQ       
发表于:2007-7-12 10:48   标题:金迪邮件底层技术探秘之四:用户统一认证、统一管理和单点登录调用接口
上一帖 |
注意将最上方的全角字符改为半角。

<%@ page contentType = ”text/html;charset=gb2312” %>
<%@ page import = ”java.util.*” %>
<%@ page import = ”java.text.*” %>
<%@ page import = ”com.turbomail.web.*” %>
<%@ page import = ”com.turbomail.util.*” %>
<%@ page import = ”com.turbomail.mime.*” %>
<%@ page import = ”java.sql.*” %>
<%@ page import = ”java.io.*” %>
<%
/*
操作说明:
1.增加用户,
URL: api?pwd=管理员密码&type=add&domain=域名&username=用户名&password=密码&maxsize=最大空间&maxsize=最大邮件数
返回值: 0 -- 成功, 非0 失败
2.删除用户
URL: api?pwd=管理员密码&type=delete&domain=域名&username=用户名
返回值: 0 -- 成功, 非0 失败
3.更改用户密码
URL: api?pwd=管理员密码&type=edit&domain=域名&username=用户名&password=新密码
返回值: 0 -- 成功, 非0 失败
4.获取用户新邮件数
URL: api?pwd=管理员密码&type=getnewmsg&domain=域名&username=用户名
返回值: 0 或正数 -- 用户新邮件数, 负数 失败
*/
%>

        //response.setContentType("text/html;charset=gb2312");
      
      String pwd = request.getParameter("pwd");
      if(pwd == null){
          pwd = "";
      }
        
      UserInfo userinfo = new UserInfo();
      userinfo.setUid("postmaster");
      userinfo.is_first = true;
      userinfo.domain = "root";
      userinfo.str_cn = "postmaster" + "@" + "root";
      String strCFPath = MailMain.s_config.getMailDirPath() +   System.getProperty("file.separator")
                                + "root" +   System.getProperty("file.separator")
                                + "postmaster" +   System.getProperty("file.separator") + "account.xml";
      
      userinfo.account = new UserAccount();
      try{
          if (MailMain.m_tmc.USER_AUTH_TYPE.equals("MYSQL")) {
              userinfo.account.mysqlInit("root", "postmaster",false);
          } else {
              userinfo.account.init(strCFPath);
          }
      }catch(Exception e){         
        e.printStackTrace() ;
           out.write("1" );
          return ;
      }
      
      if(!userinfo.account.password.equals (pwd)){
         out.write("2" );
          return ;
      }
%>

  try{
                String domain = request.getParameter("domain");
                if(domain == null){
              out.write("3" );
                    return ;
                }
               
                String username = request.getParameter("username");
                if(username == null){
              out.write("4" );
                    return ;
                }
                String password =  request.getParameter("password");
                if(password == null){
              password = "";
                }
               
                String maxsize =  request.getParameter("maxsize");
                if(maxsize == null){
              maxsize = "-1";
                }
                String maxmsgs =  request.getParameter("maxmsgs");      
                if(maxmsgs == null){
              maxmsgs = "-1";
                }      
               
                ua = new UserAccount();
  ua.username = new String(username);
  ua.password = new String(password);
  ua.usertype  = "U";
  ua.m_domain = new String(domain);
  ua.m_UserProfile = new UserProfile();
  
  ua.m_UserProfile.first_name = username;
  
  ua.m_UserProfile.last_name = "";
  ua.m_UserProfile.organiztion = "";
  ua.m_UserProfile.department = "";
  ua.m_UserProfile.address = "";
  ua.m_UserProfile.city = "";
  ua.m_UserProfile.postalcode = "";
  ua.m_UserProfile.telephone = "";
  ua.m_UserProfile.state_province = "";
  ua.m_UserProfile.country = "";
  ua.m_UserProfile.items = 50;
  
  ua.enable = "true";
  ua.enable_smtp = "true";
  ua.enable_pop3 = "true";
  ua.enable_imap4 = "true";
  ua.enable_webaccess = "true";
  ua.enable_localdomain = "false";
  ua.max_mailbox_size = Integer.parseInt(maxsize);
  ua.max_mailbox_msgs = Integer.parseInt(maxmsgs);      
                int iRet = 0;
                try {
      iRet = ua.makeUserAccount(MailMain.s_config.getMailDirPath());
  }catch(Exception e){
      e.printStackTrace();
      out.write("1" );
                    return ;
  }
  
  if(iRet != 0 ){
      out.write("1" );
               return ;
  }
         
           
        }catch(Exception ee){
            ee.printStackTrace();
            out.write("1" );
            return ;
        }
        
        out.write("0" );
        return ;
    }else if(type.equals("delete")){
        
        String username = request.getParameter("username");
        if(username == null){
            out.write("1" );
            return ;
        }
        
        String domain = request.getParameter("domain");
        if(domain == null){
            out.write("2" );
            return ;
        }
        String[] users = new String[1];
        users[0] = username;
        UserAccountAdmin.deleteUser(domain, users);
        
        out.write("0" );
        return ;
    }else if(type.equals("edit")){
        String username = request.getParameter("username");
        if(username == null){
            out.write("1" );
            return ;
        }
        
        String domain = request.getParameter("domain");
        if(domain == null){
            out.write("2" );
            return ;
        }
        
        UserAccount ua = null;
        
        ua = UserAccountAdmin.getUserAccount (domain,username);
        ua.m_domain = new String(domain);
        
        String password =  request.getParameter("password");
        if(password == null){
            password = "";
        }
        
        ua.password = password;
        int iRet = ua.saveProfile(true,false);
        
        if(iRet != 0){
            out.write("3" );
            return ;
        }
        
        out.write("0");
        return ;      
    }else if(type.equals("getnewmsg")){
       String username = request.getParameter("username");
        if(username == null){
            out.write("-1");
            return ;
        }
        
        String domain = request.getParameter("domain");
        if(domain == null){
            out.write("-2" );
            return ;
        }
        
        ArrayList hsFolders = MessageAdmin.getFolderList (domain,username,1);                                 
        Folder tempFolder = null;
        tempFolder = MessageAdmin.findFolder(hsFolders,"new");
        
        int iNewMsg = tempFolder.iNewMsg;     
        
        out.write((String.valueOf(iNewMsg)) );
        return ;        
    }

%>  




网络虽虚拟,技术无边界,来看看大家“真面目”!
2007-7-12 10:481楼
[ 顶部 ]
 
xuli868
新新人类  点击可查看详细



帖子 1
精华 0
无忧币 11
积分 1
阅读权限 20
注册日期 2007-7-15
最后登录 2007-7-16 离线

[查看资料]  [发短消息]  [Blog
       
发表于:2007-7-15 09:13   标题:谢谢~

谢谢楼主拉,找了好久这方面的资料都没找到
开心~



网络虽虚拟,技术无边界,来看看大家“真面目”!
2007-7-15 09:132楼
[ 顶部 ]
     
论坛跳转:  

| | |

| | |

标记已读 · 删除论坛Cookies · 文本版 · WAP
 
| 诚征版主 | 版主堂 | 意见建议 | 大史记 | 论坛地图
Copyright©2005-2008 51CTO.COM  Powered by Discuz!
本论坛言论纯属发布者个人意见,不代表51CTO网站立场!如有疑义,请与管理员联系。
京ICP备05051492号