import liveDomains.*;
import java.io.*;
import java.net.*;
/**
* java管理windows live custom domains使用者
* author:54powerman
* 無法傳附件,如對感興趣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)
{}
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)
client.addUser(user,pass,resetPassword,loginTicket);
catch(java.rmi.RemoteException e){}
public void deleteUser(String user)
client.deleteUser(user,loginTicket);
public String[] enumUsers(String domain)
return client.enumUsers(domain,"",500,loginTicket);
catch(java.rmi.RemoteException e){return null;}
public boolean validate()
return client.verifyAuthData(loginTicket);
catch(java.rmi.RemoteException e){return false;}
public UserState getUserState(String user)
return client.getUserState(user,loginTicket);
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 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());
}
運作結果: