Java 类javax.naming.ldap.StartTlsResponse 实例源码

项目:cn1    文件:StartTlsResponseTest.java   
public void testAll() {
    assertEquals("1.3.6.1.4.1.1466.20037", StartTlsResponse.OID);

    StartTlsResponse str = new MockStartTlsResponse();

    assertEquals(StartTlsResponse.OID, str.getID());
    assertNull(str.getEncodedValue());
}
项目:cn1    文件:StartTlsRequestTest.java   
/**
 * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
 * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
 * In this case we are testing the extended response with the argument ID="1.3.6.1.4.1.1466.20037" and the others arguments should be ignored.</p>
 * <p>Notice here that this package does not have a provider so an implementation does not exist, so this test must not fail with a provider 
 * and fail with no provider.</p>
 * <p>The expected result is a Tls response.</p>
 */
public void testCreateExtendedResponse004() throws Exception {
    StartTlsRequest str = new StartTlsRequest();
    String ID = "1.3.6.1.4.1.1466.20037";
    int t1 = 210, t2 = 650;
    byte[] t0 = ID.getBytes();

    StartTlsResponse x = (StartTlsResponse) str.createExtendedResponse(ID,
            t0, t1, t2);
    assertEquals(MockStartTlsResponse.class, x.getClass());
}
项目:freeVM    文件:StartTlsResponseTest.java   
public void testAll() {
    assertEquals("1.3.6.1.4.1.1466.20037", StartTlsResponse.OID);

    StartTlsResponse str = new MockStartTlsResponse();

    assertEquals(StartTlsResponse.OID, str.getID());
    assertNull(str.getEncodedValue());
}
项目:freeVM    文件:StartTlsRequestTest.java   
/**
 * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
 * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
 * In this case we are testing the extended response with the argument ID="1.3.6.1.4.1.1466.20037" and the others arguments should be ignored.</p>
 * <p>Notice here that this package does not have a provider so an implementation does not exist, so this test must not fail with a provider 
 * and fail with no provider.</p>
 * <p>The expected result is a Tls response.</p>
 */
public void testCreateExtendedResponse004() throws Exception {
    StartTlsRequest str = new StartTlsRequest();
    String ID = "1.3.6.1.4.1.1466.20037";
    int t1 = 210, t2 = 650;
    byte[] t0 = ID.getBytes();

    StartTlsResponse x = (StartTlsResponse) str.createExtendedResponse(ID,
            t0, t1, t2);
    assertEquals(MockStartTlsResponse.class, x.getClass());
}
项目:freeVM    文件:StartTlsResponseTest.java   
public void testAll() {
    assertEquals("1.3.6.1.4.1.1466.20037", StartTlsResponse.OID);

    StartTlsResponse str = new MockStartTlsResponse();

    assertEquals(StartTlsResponse.OID, str.getID());
    assertNull(str.getEncodedValue());
}
项目:freeVM    文件:StartTlsRequestTest.java   
/**
 * <p>Test method for 'javax.naming.ldap.StartTlsRequest.createExtendedResponse(String, byte[], int, int)'</p>
 * <p>Here we are testing if this method creates an extended response object that corresponds to the LDAP StartTLS extended request.
 * In this case we are testing the extended response with the argument ID="1.3.6.1.4.1.1466.20037" and the others arguments should be ignored.</p>
 * <p>Notice here that this package does not have a provider so an implementation does not exist, so this test must not fail with a provider 
 * and fail with no provider.</p>
 * <p>The expected result is a Tls response.</p>
 */
public void testCreateExtendedResponse004() throws Exception {
    StartTlsRequest str = new StartTlsRequest();
    String ID = "1.3.6.1.4.1.1466.20037";
    int t1 = 210, t2 = 650;
    byte[] t0 = ID.getBytes();

    StartTlsResponse x = (StartTlsResponse) str.createExtendedResponse(ID,
            t0, t1, t2);
    assertEquals(MockStartTlsResponse.class, x.getClass());
}
项目:spring-ldap    文件:AbstractTlsDirContextAuthenticationStrategy.java   
public final DirContext processContextAfterCreation(DirContext ctx, String userDn, String password)
        throws NamingException {

    if (ctx instanceof LdapContext) {
        final LdapContext ldapCtx = (LdapContext) ctx;
        final StartTlsResponse tlsResponse = (StartTlsResponse) ldapCtx.extendedOperation(new StartTlsRequest());
        try {
            if (hostnameVerifier != null) {
                tlsResponse.setHostnameVerifier(hostnameVerifier);
            }
            tlsResponse.negotiate(sslSocketFactory); // If null, the default SSL socket factory is used
            applyAuthentication(ldapCtx, userDn, password);

            if (shutdownTlsGracefully) {
                // Wrap the target context in a proxy to intercept any calls
                // to 'close', so that we can shut down the TLS connection
                // gracefully first.
                return (DirContext) Proxy.newProxyInstance(DirContextProxy.class.getClassLoader(), new Class<?>[] {
                        LdapContext.class, DirContextProxy.class }, new TlsAwareDirContextProxy(ldapCtx,
                        tlsResponse));
            }
            else {
                return ctx;
            }
        }
        catch (IOException e) {
            LdapUtils.closeContext(ctx);
            throw new UncategorizedLdapException("Failed to negotiate TLS session", e);
        }
    }
    else {
        throw new IllegalArgumentException(
                "Processed Context must be an LDAPv3 context, i.e. an LdapContext implementation");
    }

}
项目:pentaho-kettle    文件:LdapTlsProtocolIT.java   
@Before
public void setup() throws NamingException {
  mockLogChannelInterface = mock( LogChannelInterface.class );
  mockVariableSpace = mock( VariableSpace.class );
  mockLdapMeta = mock( LdapMeta.class );
  mockInitialLdapContext = mock( InitialLdapContext.class );
  mockStartTlsResponse = mock( StartTlsResponse.class );
  when( mockInitialLdapContext.extendedOperation( any( StartTlsRequest.class ) ) ).thenReturn(
    mockStartTlsResponse );
}
项目:Openfire    文件:JiveInitialLdapContext.java   
public StartTlsResponse getTlsResponse() {
    return tlsResp;
}
项目:Openfire    文件:JiveInitialLdapContext.java   
public void setTlsResponse(StartTlsResponse tlsResp) {
    this.tlsResp = tlsResp;
}
项目:g3server    文件:JiveInitialLdapContext.java   
public StartTlsResponse getTlsResponse() {
    return tlsResp;
}
项目:g3server    文件:JiveInitialLdapContext.java   
public void setTlsResponse(StartTlsResponse tlsResp) {
    this.tlsResp = tlsResp;
}
项目:read-open-source-code    文件:LDAPConnection.java   
/**
 *  Connect to LDAP server
 *  @param username : username
 *  @param password : password
 *  @throws KettleException
 */
public void connect(String username, String password) throws KettleException {

  getEnv().put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  getEnv().put("java.naming.ldap.derefAliases", getDerefAliases());
  getEnv().put(Context.REFERRAL, getReferral());

  if (getHostName().indexOf("ldap://") >= 0)
    getEnv().put(Context.PROVIDER_URL, getHostName() + ":" + getPort());
  else
    getEnv().put(Context.PROVIDER_URL, "ldap://" + getHostName() + ":" + getPort());

  if (getProtocol() == PROTOCOL_LDAP_SSL) {
    getEnv().put(javax.naming.Context.SECURITY_PROTOCOL, "ssl");

    // setup factory for SSL; for TLS, we specify this factory in the StartTlsResponse.negotiate(factory) call
    getEnv().put("java.naming.ldap.factory.socket",
        "org.pentaho.di.trans.steps.ldapinput.store.CustomdSocketFactory");
  }

  if (getProtocol() != PROTOCOL_LDAP) { // if SSL or TLS
      if (isTrustAllCertificates()) {
        CustomSocketFactory.configure();
      } else {
        CustomSocketFactory.configure(getTrustStorePath(), getTrustStorePassword());
      }
  }

  if (!Const.isEmpty(username)) {
    this.username = username;
    getEnv().put(Context.SECURITY_PRINCIPAL, username);
    getEnv().put(Context.SECURITY_CREDENTIALS, password);
    getEnv().put(Context.SECURITY_AUTHENTICATION, "simple");
  } else {
    getEnv().put(Context.SECURITY_AUTHENTICATION, "none");
  }

  try {
    /* Establish LDAP association */
    this.ctx = new InitialLdapContext(getEnv(), null);
    if (getInitialContext() == null) {
      throw new KettleException(BaseMessages.getString(PKG, "LDAPInput.Error.UnableToConnectToServer"));
    }

    if (getProtocol() == PROTOCOL_LDAP_TLS) {
      /* Requesting to start TLS on an LDAP association */
      StartTlsRequest tlsRequest = new StartTlsRequest();
      this.tls = (StartTlsResponse) getInitialContext().extendedOperation(tlsRequest);
      /* Starting TLS */
      this.tls.negotiate((SSLSocketFactory) CustomSocketFactory.getDefault());
    }

    if (log.isBasic())
      log.logBasic(BaseMessages.getString(PKG, "LDAPInput.Log.ConnectedToServer", getHostName(),
          Const.NVL(getUserName(), "")));
    if (log.isDetailed())
      log.logDetailed(BaseMessages.getString(PKG, "LDAPInput.ClassUsed.Message", getInitialContext().getClass()
          .getName()));

  } catch (Exception e) {
    throw new KettleException(BaseMessages.getString(PKG, "LDAPinput.Exception.ErrorConnecting", e.getMessage()), e);
  }
}
项目:openfire    文件:JiveInitialLdapContext.java   
public StartTlsResponse getTlsResponse() {
    return tlsResp;
}
项目:openfire    文件:JiveInitialLdapContext.java   
public void setTlsResponse(StartTlsResponse tlsResp) {
    this.tlsResp = tlsResp;
}
项目:kettle-4.4.0-stable    文件:LDAPConnection.java   
/**
 *  Connect to LDAP server
 *  @param username : username
 *  @param password : password
 *  @throws KettleException
 */
public void connect(String username, String password) throws KettleException {

  getEnv().put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  getEnv().put("java.naming.ldap.derefAliases", getDerefAliases());
  getEnv().put(Context.REFERRAL, getReferral());

  if (getHostName().indexOf("ldap://") >= 0)
    getEnv().put(Context.PROVIDER_URL, getHostName() + ":" + getPort());
  else
    getEnv().put(Context.PROVIDER_URL, "ldap://" + getHostName() + ":" + getPort());

  if (getProtocol() == PROTOCOL_LDAP_SSL) {
    getEnv().put(javax.naming.Context.SECURITY_PROTOCOL, "ssl");

    // setup factory for SSL; for TLS, we specify this factory in the StartTlsResponse.negotiate(factory) call
    getEnv().put("java.naming.ldap.factory.socket",
        "org.pentaho.di.trans.steps.ldapinput.store.CustomdSocketFactory");
  }

  if (getProtocol() != PROTOCOL_LDAP) { // if SSL or TLS
      if (isTrustAllCertificates()) {
        CustomSocketFactory.configure();
      } else {
        CustomSocketFactory.configure(getTrustStorePath(), getTrustStorePassword());
      }
  }

  if (!Const.isEmpty(username)) {
    this.username = username;
    getEnv().put(Context.SECURITY_PRINCIPAL, username);
    getEnv().put(Context.SECURITY_CREDENTIALS, password);
    getEnv().put(Context.SECURITY_AUTHENTICATION, "simple");
  } else {
    getEnv().put(Context.SECURITY_AUTHENTICATION, "none");
  }

  try {
    /* Establish LDAP association */
    this.ctx = new InitialLdapContext(getEnv(), null);
    if (getInitialContext() == null) {
      throw new KettleException(BaseMessages.getString(PKG, "LDAPInput.Error.UnableToConnectToServer"));
    }

    if (getProtocol() == PROTOCOL_LDAP_TLS) {
      /* Requesting to start TLS on an LDAP association */
      StartTlsRequest tlsRequest = new StartTlsRequest();
      this.tls = (StartTlsResponse) getInitialContext().extendedOperation(tlsRequest);
      /* Starting TLS */
      this.tls.negotiate((SSLSocketFactory) CustomSocketFactory.getDefault());
    }

    if (log.isBasic())
      log.logBasic(BaseMessages.getString(PKG, "LDAPInput.Log.ConnectedToServer", getHostName(),
          Const.NVL(getUserName(), "")));
    if (log.isDetailed())
      log.logDetailed(BaseMessages.getString(PKG, "LDAPInput.ClassUsed.Message", getInitialContext().getClass()
          .getName()));

  } catch (Exception e) {
    throw new KettleException(BaseMessages.getString(PKG, "LDAPinput.Exception.ErrorConnecting", e.getMessage()), e);
  }
}
项目:kettle-trunk    文件:LDAPConnection.java   
/**
 *  Connect to LDAP server
 *  @param username : username
 *  @param password : password
 *  @throws KettleException
 */
public void connect(String username, String password) throws KettleException {

  getEnv().put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  getEnv().put("java.naming.ldap.derefAliases", getDerefAliases());
  getEnv().put(Context.REFERRAL, getReferral());

  if (getHostName().indexOf("ldap://") >= 0)
    getEnv().put(Context.PROVIDER_URL, getHostName() + ":" + getPort());
  else
    getEnv().put(Context.PROVIDER_URL, "ldap://" + getHostName() + ":" + getPort());

  if (getProtocol() == PROTOCOL_LDAP_SSL) {
    getEnv().put(javax.naming.Context.SECURITY_PROTOCOL, "ssl");

    // setup factory for SSL; for TLS, we specify this factory in the StartTlsResponse.negotiate(factory) call
    getEnv().put("java.naming.ldap.factory.socket",
        "org.pentaho.di.trans.steps.ldapinput.store.CustomdSocketFactory");
  }

  if (getProtocol() != PROTOCOL_LDAP) { // if SSL or TLS
      if (isTrustAllCertificates()) {
        CustomSocketFactory.configure();
      } else {
        CustomSocketFactory.configure(getTrustStorePath(), getTrustStorePassword());
      }
  }

  if (!Const.isEmpty(username)) {
    this.username = username;
    getEnv().put(Context.SECURITY_PRINCIPAL, username);
    getEnv().put(Context.SECURITY_CREDENTIALS, password);
    getEnv().put(Context.SECURITY_AUTHENTICATION, "simple");
  } else {
    getEnv().put(Context.SECURITY_AUTHENTICATION, "none");
  }

  try {
    /* Establish LDAP association */
    this.ctx = new InitialLdapContext(getEnv(), null);
    if (getInitialContext() == null) {
      throw new KettleException(BaseMessages.getString(PKG, "LDAPInput.Error.UnableToConnectToServer"));
    }

    if (getProtocol() == PROTOCOL_LDAP_TLS) {
      /* Requesting to start TLS on an LDAP association */
      StartTlsRequest tlsRequest = new StartTlsRequest();
      this.tls = (StartTlsResponse) getInitialContext().extendedOperation(tlsRequest);
      /* Starting TLS */
      this.tls.negotiate((SSLSocketFactory) CustomSocketFactory.getDefault());
    }

    if (log.isBasic())
      log.logBasic(BaseMessages.getString(PKG, "LDAPInput.Log.ConnectedToServer", getHostName(),
          Const.NVL(getUserName(), "")));
    if (log.isDetailed())
      log.logDetailed(BaseMessages.getString(PKG, "LDAPInput.ClassUsed.Message", getInitialContext().getClass()
          .getName()));

  } catch (Exception e) {
    throw new KettleException(BaseMessages.getString(PKG, "LDAPinput.Exception.ErrorConnecting", e.getMessage()), e);
  }
}
项目:spring-ldap    文件:AbstractTlsDirContextAuthenticationStrategy.java   
public TlsAwareDirContextProxy(LdapContext target, StartTlsResponse tlsResponse) {
    this.target = target;
    this.tlsResponse = tlsResponse;
}
项目:openfire-bespoke    文件:JiveInitialLdapContext.java   
public StartTlsResponse getTlsResponse() {
    return tlsResp;
}
项目:openfire-bespoke    文件:JiveInitialLdapContext.java   
public void setTlsResponse(StartTlsResponse tlsResp) {
    this.tlsResp = tlsResp;
}
项目:cn1    文件:TestInitialLdapContext.java   
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.extendedOperation(ExtendedRequest)'
 * </p>
 * <p>
 * Here we are testing if this method correctly executes the given
 * operation. Here we send a non-null ExtendedRequest.
 * </p>
 * <p>
 * The expected result is an ExtendedResponse.
 * </p>
 */
public void testExtendedOperation002() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    InitialLdapContext x = new InitialLdapContext();
    StartTlsResponse f = (StartTlsResponse)x.extendedOperation(new StartTlsRequest());
    assertNotNull(f);
    x.close();
}
项目:freeVM    文件:TestInitialLdapContext.java   
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.extendedOperation(ExtendedRequest)'
 * </p>
 * <p>
 * Here we are testing if this method performs an extended operation. Here
 * we send a not null extended operation.
 * </p>
 * <p>
 * The expected result is an Extended Response.
 * </p>
 */
public void testExtendedOperation002() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    InitialLdapContext x = new InitialLdapContext();
    StartTlsResponse f = (StartTlsResponse)x.extendedOperation(new StartTlsRequest());
    assertNotNull(f);
    x.close();
}
项目:freeVM    文件:TestInitialLdapContext.java   
/**
 * <p>
 * Test method for
 * 'javax.naming.ldap.InitialLdapContext.extendedOperation(ExtendedRequest)'
 * </p>
 * <p>
 * Here we are testing if this method correctly executes the given
 * operation. Here we send a non-null ExtendedRequest.
 * </p>
 * <p>
 * The expected result is an ExtendedResponse.
 * </p>
 */
public void testExtendedOperation002() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                    "org.apache.harmony.jndi.tests.javax.naming.spi.mock.ldap.MockContextFactory");
    InitialLdapContext x = new InitialLdapContext();
    StartTlsResponse f = (StartTlsResponse)x.extendedOperation(new StartTlsRequest());
    assertNotNull(f);
    x.close();
}