|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.didisoft.pgp.net.LDAPClient
public class LDAPClient
Retrieves keys from LDAP servers that support the pgp ldap schema
Example usage:
import java.io.ByteArrayInputStream; import com.didisoft.pgp.net.LDAPClient; import com.didisoft.pgp.KeyStore; public class DemoLDAP { public static void demo() throws Exception { // connect to LDAP server that supports pgp schema LDAPClient ldap = new LDAPClient("127.0.0.1"); // search by part of the User Id ldap.setPartialMatchUserIds(true); byte[] keyBytes = ldap.getKeyByUserId("DidiSoft"); // String keyInAscii = new String(keyBytes, "ASCII"); if (keyBytes != null && keyBytes.length > 0) { KeyStore ks = new KeyStore(); // create an in-memory keystore ks.importKeyRing(new ByteArrayInputStream(keyBytes)); } } }
Field Summary | |
---|---|
static int |
DEFAULT_LDAP_PORT
|
Constructor Summary | |
---|---|
LDAPClient(java.lang.String host)
Creates a new instance of the class |
|
LDAPClient(java.lang.String host,
int port)
Creates a new instance of the class |
|
LDAPClient(java.lang.String host,
int port,
java.lang.String username,
java.lang.String password)
|
Method Summary | |
---|---|
byte[] |
getKeyByKeyId(long keyId)
Tries to retrieve a key from an LDAP server searching by Key Id. |
byte[] |
getKeyByKeyIdHex(java.lang.String keyIdHex)
Tries to retrieve a key from an LDAP server searching by hexadecimal Key Id. |
byte[] |
getKeyByUserId(java.lang.String userId)
Tries to retrieve a key from an LDAP server searching by User Id. |
boolean |
isPartialMatchUserIds()
Returns should keys be search by part of the User ID (true) or with the whole User ID only (false) |
static java.lang.String |
padLeft(int s,
int n)
|
void |
setPartialMatchUserIds(boolean partialMatch)
Sets should keys be search by part of the User ID (true) or with the whole User ID only (false) |
boolean |
submitKey(byte[] keyBytes)
Uploads an OpenPGP key bytes into an LDAP server that supports the pgp schema |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_LDAP_PORT
Constructor Detail |
---|
public LDAPClient(java.lang.String host)
host
- host or IP address of the LDAP server that supports PGP schemapublic LDAPClient(java.lang.String host, int port)
host
- host or IP address of the LDAP server that supports PGP schemaport
- port of the LDAP serverpublic LDAPClient(java.lang.String host, int port, java.lang.String username, java.lang.String password)
host
- host or IP address of the LDAP server that supports PGP schemaport
- port of the LDAP serverusername
- LDAP user account (for example: uid=John.Doe,ou=People,dc=example,dc=compassword
- LDAP user account passwordMethod Detail |
---|
public boolean isPartialMatchUserIds()
setPartialMatchUserIds(boolean)
public void setPartialMatchUserIds(boolean partialMatch)
partialMatch
- if true, User ID parameters can be specified with part of the User ID
when false the whole User ID must be specifiedisPartialMatchUserIds()
public byte[] getKeyByKeyIdHex(java.lang.String keyIdHex) throws java.io.IOException
keyIdHex
- key Id in hexadecimal format (like "B29931AC")
java.io.IOException
- in case of a network connection problem
Example usage:
LDAPClient ldap = new LDAPClient("localhost"); byte[] keyBytes = ldap.getKeyByKeyIdHex("b22a15dd"); if (keyBytes != null || keyBytes.length > 0) { KeyStore ks = new KeyStore(); // create an in-memory keystore ks.importKeyRing(new ByteArrayInputStream(keyBytes)); }
public byte[] getKeyByUserId(java.lang.String userId) throws java.io.IOException
userId
- Whole or part of one of the User Id's of the key
java.io.IOException
- in case of a network connection problemExample usage:
LDAPClient ldap = new LDAPClient("localhost");
ldap.getKeyByUserId("WellMed");
if (keyBytes != null || keyBytes.length > 0) {
KeyStore ks = new KeyStore(); // create an in-memory keystore
ks.importKeyRing(new ByteArrayInputStream(keyBytes));
}
public byte[] getKeyByKeyId(long keyId) throws java.io.IOException
keyId
- key Id
java.io.IOException
- in case of a network connection problempublic boolean submitKey(byte[] keyBytes) throws java.io.IOException
keyBytes
- OpenPGP key serialized as array of bytes
java.io.IOException
- in case of an error
Example:
LDAPClient ldap = new LDAPClient("127.0.0.1"); FileInputStream fIn = new FileInputStream("c:\\Test\\new3\\silverpub.asc"); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); int i = -1; while ((i = fIn.read()) != -1) { bOut.write(i); } boolean submitted = ldap.submitKey(bOut.toByteArray());
public static java.lang.String padLeft(int s, int n)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |