import liveDomains.*;
import java.io.*;
import java.net.*;
/**
* java管理windows live custom domains用户
* author:54powerman
* 54powerman@163.com
* http://54powerman.blog.sohu.com
* 无法传附件,如对感兴趣liveDomains api包请mail索取。
**/
public class LiveDomainsManage {
private String adminUser;
private String adminPassword;
private String loginUrl;
private String loginTicket;
private String loginData;
private ManageDomainSvcLocator service;
private ManageDomainSvcSoap_PortType client;
public LiveDomainsManage(String user,String pass)
{
adminUser=user;
adminPassword=pass;
service=new ManageDomainSvcLocator();
try{
client=service.getManageDomainSvcSoap12();
}
catch(javax.xml.rpc.ServiceException e)
{}
try{
loginUrl=client.getLoginUrl(adminUser);
String loginDataTemplate=client.getLoginDataTemplate();
loginData = loginDataTemplate.replaceAll("%NAME%", adminUser);
loginData = loginData.replaceAll("%PASSWORD%", adminPassword);
}
catch(java.rmi.RemoteException e)
{}
login();
}
private void login()
{
if(!validate())
{
loginTicket = postWebData(loginUrl, loginData);//登录凭证,这个凭证在后面的操作中会频繁使用
}
}
public void addUser(String user,String pass,boolean resetPassword)
{
try{
client.addUser(user,pass,resetPassword,loginTicket);
}
catch(java.rmi.RemoteException e){}
}
public void deleteUser(String user)
{
try{
client.deleteUser(user,loginTicket);
}
catch(java.rmi.RemoteException e){}
}
public String[] enumUsers(String domain)
{
try{
return client.enumUsers(domain,"",500,loginTicket);
}
catch(java.rmi.RemoteException e){return null;}
}
public boolean validate()
{
try{
return client.verifyAuthData(loginTicket);
}
catch(java.rmi.RemoteException e){return false;}
}
public UserState getUserState(String user)
{
try{
return client.getUserState(user,loginTicket);
}
catch(java.rmi.RemoteException e){return null;}
}
public static String postWebData(String urlString,String postParam) {
StringBuffer document = new StringBuffer();
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if(!postParam.trim().equals("")){
conn.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "GBK");
out.write(postParam);
out.flush();
out.close();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
while ( (line = reader.readLine()) != null) {
document.append(line + "/n");
}
reader.close();
}
catch (MalformedURLException e) {
System.out.println("Unable to connect to URL: " + urlString);
}
catch (IOException e) {
System.out.println("IOException when connecting to URL: " + urlString);
}
return document.toString();
}
public static void main(String[] args) throws Exception{
String adminUser="54powerman@163.com";
String adminPassword="xxxxxxxxxxxxxxx";
LiveDomainsManage liveDomainsManage=new LiveDomainsManage(adminUser,adminPassword);
String[] users=liveDomainsManage.enumUsers("usease.com");
for(int i=0;i<users.length;i++)
{
UserState userState=liveDomainsManage.getUserState(users[i]);
System.out.println(users[i]+"/t"+userState.toString());
}
}
}
运行结果:
admin@usease.com InUse
54powerman@usease.com InUse