当前位置: 首页>>代码示例>>Java>>正文


Java StartTlsRequest类代码示例

本文整理汇总了Java中javax.naming.ldap.StartTlsRequest的典型用法代码示例。如果您正苦于以下问题:Java StartTlsRequest类的具体用法?Java StartTlsRequest怎么用?Java StartTlsRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StartTlsRequest类属于javax.naming.ldap包,在下文中一共展示了StartTlsRequest类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateExtendedResponse005

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 * <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=""</p>
 * <p>The expected result is an exception.</p>
 */
public void testCreateExtendedResponse005() {
       StartTlsRequest str = new StartTlsRequest();
       try {
           str.createExtendedResponse("", null, 1, 2);
           fail("NamingException expected");
       } catch (NamingException e) {}
   }
 
开发者ID:shannah,项目名称:cn1,代码行数:14,代码来源:StartTlsRequestTest.java

示例2: testCreateExtendedResponse004

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 * <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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:StartTlsRequestTest.java

示例3: processContextAfterCreation

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
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");
	}

}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:37,代码来源:AbstractTlsDirContextAuthenticationStrategy.java

示例4: setup

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
@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 );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:11,代码来源:LdapTlsProtocolIT.java

示例5: processResponse

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
private void processResponse(LdapMessage response, Exception ex) {
    // unsolicited notification
    if (response.getMessageId() == 0) {
        notifyUnls(response);
        return;
    }

    Element element = requests.get(Integer.valueOf(response
            .getMessageId()));
    if (element == null
            && batchedSearchRequests.contains(Integer.valueOf(response
                    .getMessageId()))) {
        element = batchedSearchRequests.get(Integer.valueOf(response
                .getMessageId()));
        // error occurs when read response
        if (ex != null) {
            ((SearchOp) response.getResponseOp()).getSearchResult()
                    .setException(ex);
            batchedSearchRequests.remove(Integer.valueOf(response
                    .getMessageId()));
            return;
        }

        // wait time out
        if (element.response.getMessageId() != response.getMessageId()) {
            // ldap.31=Read LDAP response message time out
            ((SearchOp) response.getResponseOp()).getSearchResult()
                    .setException(
                            new IOException(Messages
                                    .getString("ldap.31"))); //$NON-NLS-1$);
            batchedSearchRequests.remove(Integer.valueOf(response
                    .getMessageId()));
            return;
        }

    }
    if (element != null) {
        element.response = response;
        element.ex = ex;
        // persistent search response || search response
        if (element.lock == null) {
            notifyPersistenSearchListener(element);

        } else {
            if (element.response.getOperationIndex() == LdapASN1Constant.OP_EXTENDED_RESPONSE
                    && ((ExtendedOp) element.response.getResponseOp())
                            .getExtendedRequest().getID().equals(
                                    StartTlsRequest.OID)) {
                /*
                 * When establishing TLS by StartTls extended operation,
                 * no
                 */
                isStopped = true;
            }

            /*
             * notify the thread which send request and wait for
             * response
             */
            synchronized (element.lock) {
                element.lock.notify();
            }
        } // end of if (element.lock == null) else
    } // end of if (element != null)

    else if (ex != null) {
        /*
         * may asn1 decode error or socket problem, can get message id,
         * so couldn't know which thread should be notified
         */
        // FIXME: any better way?
        close();
    }
    // FIXME message id not found and no exception, what shoud we do?

}
 
开发者ID:shannah,项目名称:cn1,代码行数:77,代码来源:LdapClient.java

示例6: connect

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 *  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);
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:69,代码来源:LDAPConnection.java

示例7: testExtendedOperation002

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 * <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();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:TestInitialLdapContext.java

示例8: testExtendedOperation002

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 * <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();
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:22,代码来源:TestInitialLdapContext.java

示例9: testGetID

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 * <p>Test method for 'javax.naming.ldap.StartTlsRequest.getID()'</p>
 * <p>Here we are testing if this method retrieves the StartTLS request's object identifier string.</p>
 * <p>The expected result is a string : "1.3.6.1.4.1.1466.20037".</p>
 */
public void testGetID() {
       assertEquals("1.3.6.1.4.1.1466.20037", StartTlsRequest.OID);
       assertSame(StartTlsRequest.OID, new StartTlsRequest().getID());
   }
 
开发者ID:shannah,项目名称:cn1,代码行数:10,代码来源:StartTlsRequestTest.java

示例10: testGetEncodedValue

import javax.naming.ldap.StartTlsRequest; //导入依赖的package包/类
/**
 * <p>Test method for 'javax.naming.ldap.StartTlsRequest.getEncodedValue()'</p>
 * <p>Here we are testing if this method retrieves the StartTLS request's ASN.1 BER encoded value.</p>
 * <p>The expected result is a null value.</p>
 */
public void testGetEncodedValue() {
       assertNull(new StartTlsRequest().getEncodedValue());
   }
 
开发者ID:shannah,项目名称:cn1,代码行数:9,代码来源:StartTlsRequestTest.java


注:本文中的javax.naming.ldap.StartTlsRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。