Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-09-2007, 03:10 AM
Senior Member
 
Posts: 55
Default [SOLVED] help about SoapProvisioning

Hello,
I am trying to use services of SoapProvisioning specialy : services of creating new account.
I try this but i have a java.lang.NullPointerException:
--------------------------------------------------------------
try
{
SoapProvisioning sp ;
sp.soapSetURI("http://10.22.28.14" + ZimbraServlet.USER_SERVICE_URI);
sp.soapAdminAuthenticate("admin","****");
sp.createAccount("new_user@domain.com", "password", null);
}
catch(Exception ex){ ex.printStackTrace(); }
---------------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old 05-09-2007, 03:11 AM
Moderator
 
Posts: 2,207
Default

Did you look at the other forum and the answer I gave you on that ?

Soap services are available on port 7070 : http://localhost:7070/service/soap/
Reply With Quote
  #3 (permalink)  
Old 05-09-2007, 03:51 AM
Senior Member
 
Posts: 55
Default

ok now the problem is in: sp.soapAdminAuthenticate
the error is:
-------------------------------------------------
log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.HttpClient).
log4j:WARN Please initialize the log4j system properly.
com.zimbra.soap.SoapFaultException: unknown document: AuthRequest
at com.zimbra.soap.Soap12Protocol.soapFault(Soap12Pro tocol.java:102)
at com.zimbra.soap.SoapTransport.extractBodyElement(S oapTransport.java:215)
at com.zimbra.soap.SoapTransport.parseSoapResponse(So apTransport.java:191)
at com.zimbra.soap.SoapHttpTransport.invoke(SoapHttpT ransport.java:214)
at com.zimbra.soap.SoapTransport.invoke(SoapTransport .java:231)
at com.zimbra.cs.account.soap.SoapProvisioning.invoke (SoapProvisioning.java:156)
at com.zimbra.cs.account.soap.SoapProvisioning.soapAd minAuthenticate(SoapProvisioning.java:128)
at com.zimbra.cs.account.soap.Test1.creer_compte(Test 1.java:23)
at com.zimbra.cs.account.soap.Test1.main(Test1.java:3 4)
----------------------------------------------------------------------
Reply With Quote
  #4 (permalink)  
Old 05-09-2007, 01:41 PM
Zimbra Employee
 
Posts: 1,434
Default admin auth requires admin port

If you're trying to auth as admin, you need to point SoapProvisioning at the admin port and URL, not the regular port/URL.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #5 (permalink)  
Old 05-09-2007, 01:51 PM
Senior Member
 
Posts: 55
Default

yes i try https://ip_zimbrahost:7071/service/admin/soap but also gives me exception
Reply With Quote
  #6 (permalink)  
Old 05-10-2007, 01:24 AM
Member
 
Posts: 11
Default

Code:
Hello,
I am trying to use services of SoapProvisioning specialy : services of creating new account.
I try this but i have a java.lang.NullPointerException:
--------------------------------------------------------------
try
		{	
			SoapProvisioning sp ;
			sp.soapSetURI("http://10.22.28.14" + ZimbraServlet.USER_SERVICE_URI);
			sp.soapAdminAuthenticate("admin","****");
			sp.createAccount("new_user@domain.com", "password", null);
		}
		catch(Exception ex){ ex.printStackTrace(); }
---------------------------------------------------------------------
You must change it for
Code:
"https://10.22.28.14:7071"+ZimbraServlet.ADMIN_SERVICE_URI

Last edited by mrojek; 05-10-2007 at 01:29 AM..
Reply With Quote
  #7 (permalink)  
Old 05-10-2007, 01:56 AM
Senior Member
 
Posts: 55
Default

also with : https://10.22.28.14:7071"+ZimbraServlet.ADMIN_SERVICE_URI
i had an exception in sp.soapAdminAuthenticate("admin","****") :
-----------------------------------------------------------------------
com.zimbra.cs.zclient.ZClientException: invoke sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target, server: 10.22.28.14
at com.zimbra.cs.zclient.ZClientException.IO_ERROR(ZC lientException.java:54)
------------------------------------------------------------------------

i try the uri "https://10.22.28.14:7071/service/admin/soap" in my browser
and i get the tomcat "error:HTTP Status 405 - HTTP method GET is not supported by this URL" is that normal ?
what wrong in my: sp.soapAdminAuthenticate("admin","****") ?
Reply With Quote
  #8 (permalink)  
Old 05-10-2007, 02:02 AM
Member
 
Posts: 11
Default

OK i have this same problem. You try connect by https it's secure connection with changing public key. You server hasn't got a certificate from trustet provider (for example verisign.com) or samthing like that and java don't trust this server you must add this certificate to java certificate file.
Reply With Quote
  #9 (permalink)  
Old 05-10-2007, 02:08 AM
Member
 
Posts: 11
Default

I use this simple java class:
Code:
import java.io.*;
import java.net.URL;

import java.security.*;
import java.security.cert.*;

import javax.net.ssl.*;

public class InstallCert {

    public static void main(String[] args) throws Exception {
	String host;
	int port;
	char[] passphrase;
	args = new String[1];
	args[0]="www.example.com:7071";
	if ((args.length == 1) || (args.length == 2)) {
	    String[] c = args[0].split(":");
	    host = c[0];
	    port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
	    String p = (args.length == 1) ? "changeit" : args[1];
	    passphrase = p.toCharArray();
	} else {
	    System.out.println("Usage: java InstallCert <host>[:port] [passphrase]");
	    return;
	}
//for my windows and java
	File file = new File("C:\\Program Files\\Java\\jre1.6.0\\lib\\security\\cacerts");
//	if (file.isFile() == false) {
//	    char SEP = File.separatorChar;
//	   
//	    File dir = new File(System.getProperty("java.home") + SEP
//		    + "lib" + SEP + "security");
//	    file = new File(dir, "jssecacerts");
//	    if (file.isFile() == false) {
//		file = new File(dir, "cacerts");
//	    }
//	}
	System.out.println("Loading KeyStore " + file + "...");
	InputStream in = new FileInputStream(file);
	KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
	ks.load(in, passphrase);
	in.close();

	SSLContext context = SSLContext.getInstance("TLS");
	TrustManagerFactory tmf =
	    TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
	tmf.init(ks);
	X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
	SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
	context.init(null, new TrustManager[] {tm}, null);
	SSLSocketFactory factory = context.getSocketFactory();
	
	System.out.println("Opening connection to " + host + ":" + port + "...");
	SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
	socket.setSoTimeout(10000);
	try {
	    System.out.println("Starting SSL handshake...");
	    socket.startHandshake();
	    socket.close();
	    System.out.println();
	    System.out.println("No errors, certificate is already trusted");
	} catch (SSLException e) {
	    System.out.println();
	    e.printStackTrace(System.out);
	}

	X509Certificate[] chain = tm.chain;
	if (chain == null) {
	    System.out.println("Could not obtain server certificate chain");
	    return;
	}

	BufferedReader reader =
		new BufferedReader(new InputStreamReader(System.in));

	System.out.println();
	System.out.println("Server sent " + chain.length + " certificate(s):");
	System.out.println();
	MessageDigest sha1 = MessageDigest.getInstance("SHA1");
	MessageDigest md5 = MessageDigest.getInstance("MD5");
	for (int i = 0; i < chain.length; i++) {
	    X509Certificate cert = chain[i];
	    System.out.println
	    	(" " + (i + 1) + " Subject " + cert.getSubjectDN());
	    System.out.println("   Issuer  " + cert.getIssuerDN());
	    sha1.update(cert.getEncoded());
	    System.out.println("   sha1    " + toHexString(sha1.digest()));
	    md5.update(cert.getEncoded());
	    System.out.println("   md5     " + toHexString(md5.digest()));
	    System.out.println();
	}

	System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
	String line = reader.readLine().trim();
	int k;
	try {
	    k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
	} catch (NumberFormatException e) {
	    System.out.println("KeyStore not changed");
	    return;
	}

	X509Certificate cert = chain[k];
	String alias = host + "-" + (k + 1);
	ks.setCertificateEntry(alias, cert);

	OutputStream out = new FileOutputStream("C:\\Program Files\\Java\\jre1.6.0\\lib\\security\\cacerts");
	ks.store(out, passphrase);
	out.close();

	System.out.println();
	System.out.println(cert);
	System.out.println();
	System.out.println
		("Added certificate to keystore 'jssecacerts' using alias '"
		+ alias + "'");
	 String gdzie = new String(System.getProperty("java.home//") +
			   "lib//"   + "security");
		    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
		    System.out.println(gdzie);
		    
    }
    
    private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
    
    private static String toHexString(byte[] bytes) {
	StringBuilder sb = new StringBuilder(bytes.length * 3);
	for (int b : bytes) {
	    b &= 0xff;
	    sb.append(HEXDIGITS[b >> 4]);
	    sb.append(HEXDIGITS[b & 15]);
	    sb.append(' ');
	}
	return sb.toString();
    }

    private static class SavingTrustManager implements X509TrustManager {
	
	private final X509TrustManager tm;
	private X509Certificate[] chain;
	
	SavingTrustManager(X509TrustManager tm) {
	    this.tm = tm;
	}
    
	public X509Certificate[] getAcceptedIssuers() {
	    throw new UnsupportedOperationException();
	}
    
	public void checkClientTrusted(X509Certificate[] chain, String authType)
		throws CertificateException {
	    throw new UnsupportedOperationException();
	}
    
	public void checkServerTrusted(X509Certificate[] chain, String authType)
		throws CertificateException {
	    this.chain = chain;
	    tm.checkServerTrusted(chain, authType);
	}
    }

}
It should work
Reply With Quote
  #10 (permalink)  
Old 05-10-2007, 02:55 AM
Senior Member
 
Posts: 55
Default

Thanks a lot it works very well now
and congratulation for your work.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.