Package org.apache.hadoop.gateway.filter.rewrite.spi

Examples of org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext


    } else if( !ruleName.isEmpty() ) {
      stepHolder = rules.get( ruleName );
      effectiveRuleName = ruleName;
    }
    if( stepHolder != null ) {
      UrlRewriteContext context = new UrlRewriteContextImpl( environment, resolver, functions, direction, inputUri );
      try {
        UrlRewriteStepStatus stepStatus = stepHolder.process( context );
        if( UrlRewriteStepStatus.SUCCESS == stepStatus ) {
          outputUri = context.getCurrentUrl();
          if( ruleName == null ) {
            LOG.rewroteUrlViaImplicitRule( inputUri, direction, effectiveRuleName, outputUri );
          } else {
            LOG.rewroteUrlViaExplicitRule( inputUri, direction, effectiveRuleName, outputUri );
          }
View Full Code Here


    String encQuery = encoder.encode( "test-query".getBytes("utf-8" ) );
    encQuery = encQuery.replaceAll( "\\=", "" );
    String inString = "http://host:0/root/path?_=" + encQuery;
    Template inTemplate = Parser.parse( inString );

    UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
    Capture<Template> outTemplate = new Capture<Template>();
    context.setCurrentUrl( EasyMock.capture( outTemplate ) );
    EasyMock.replay( context );

    SecureQueryDecodeDescriptor descriptor = new SecureQueryDecodeDescriptor();
    SecureQueryDecodeProcessor processor = new SecureQueryDecodeProcessor();
    processor.initialize( environment, descriptor );
View Full Code Here

    String encQuery = encoder.encode( inQuery.getBytes( "utf-8" ) );
    encQuery = encQuery.replaceAll( "\\=", "" );
    String inString = "http://host:0/root/path?_=" + encQuery + "&clear-param=clear-value";
    Template inTemplate = Parser.parse( inString );

    UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
    Capture<Template> outTemplate = new Capture<Template>();
    context.setCurrentUrl( EasyMock.capture( outTemplate ) );
    EasyMock.replay( context );

    SecureQueryDecodeDescriptor descriptor = new SecureQueryDecodeDescriptor();
    SecureQueryDecodeProcessor processor = new SecureQueryDecodeProcessor();
    processor.initialize( environment, descriptor );
View Full Code Here

    UrlRewriteEnvironment environment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
    EasyMock.expect( environment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();   
    EasyMock.expect( environment.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( Arrays.asList( "test-cluster-name" ) ).anyTimes();

    Template inTemplate = Parser.parse( "http://host:0/root/path?query" );
    UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
    Capture<Template> outTemplate = new Capture<Template>();
    context.setCurrentUrl( EasyMock.capture( outTemplate ) );

    EasyMock.replay( environment, context );

    SecureQueryEncodeDescriptor descriptor = new SecureQueryEncodeDescriptor();
    SecureQueryEncodeProcessor processor = new SecureQueryEncodeProcessor();
View Full Code Here

    EasyMock.expect( gatewayServices.getService( GatewayServices.CRYPTO_SERVICE ) ).andReturn( cryptoService );

    UrlRewriteEnvironment encEnvironment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
    EasyMock.expect( encEnvironment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();   
    EasyMock.expect( encEnvironment.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster-name" ).anyTimes();
    UrlRewriteContext encContext = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( encContext.getCurrentUrl() ).andReturn( origTemplate );
    Capture<Template> encTemplate = new Capture<Template>();
    encContext.setCurrentUrl( EasyMock.capture( encTemplate ) );
    EasyMock.replay( gatewayServices, as, encEnvironment, encContext );

    SecureQueryEncryptDescriptor descriptor = new SecureQueryEncryptDescriptor();
    SecureQueryEncryptProcessor processor = new SecureQueryEncryptProcessor();
    processor.initialize( encEnvironment, descriptor );
    processor.process( encContext );

    assertThat( encTemplate, notNullValue() );
    query = encTemplate.getValue().getQuery().get( "_" );
    assertThat( query.getFirstValue().getPattern().length(), greaterThan( 1 ) );
    query = encTemplate.getValue().getQuery().get( "query-param-name" );
    assertThat( query, nullValue() );

    // Test decryption.  Results are left in decTemplate.

    gatewayServices = EasyMock.createNiceMock( GatewayServices.class );
    EasyMock.expect( gatewayServices.getService( GatewayServices.CRYPTO_SERVICE ) ).andReturn( cryptoService );
    as = EasyMock.createNiceMock( AliasService.class );
    EasyMock.expect( as.getPasswordFromAliasForCluster("test-cluster-name", "encryptQueryString")).andReturn( secret.toCharArray() ).anyTimes();

    UrlRewriteEnvironment decEnvironment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
    EasyMock.expect( decEnvironment.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE ) ).andReturn( gatewayServices ).anyTimes();   
    EasyMock.expect( decEnvironment.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( "test-cluster-name" ).anyTimes();
    Params decParams = EasyMock.createNiceMock( Params.class );
    EasyMock.expect( decParams.resolve( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE ) ).andReturn( Arrays.asList("test-cluster-name") ).anyTimes();
    UrlRewriteContext decContext = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( decContext.getCurrentUrl() ).andReturn( encTemplate.getValue() );
    EasyMock.expect( decContext.getParameters() ).andReturn( decParams );
    Capture<Template> decTemplate = new Capture<Template>();
    decContext.setCurrentUrl( EasyMock.capture( decTemplate ) );
    EasyMock.replay( gatewayServices, as, decEnvironment, decParams, decContext );

    SecureQueryDecryptDescriptor descriptor1 = new SecureQueryDecryptDescriptor();
    SecureQueryDecryptProcessor decProcessor = new SecureQueryDecryptProcessor();
    decProcessor.initialize( decEnvironment, descriptor1 );
View Full Code Here

        match = outbound.match( outputUri );
        break;
    }
    if( match != null ) {
      UrlRewriteFunctionResolver function = new UrlRewriteFunctionResolver( functions, resolver );
      UrlRewriteContext context = new UrlRewriteContextImpl( environment, function, direction, inputUri );
      try {
        UrlRewriteStepProcessorHolder stepHolder = match.getValue();
        UrlRewriteStepStatus stepStatus = stepHolder.process( context );
        if( UrlRewriteStepStatus.SUCCESS == stepStatus ) {
          outputUri = context.getCurrentUrl();
        } else {
          outputUri = null;
        }
      } catch( Exception e ) {
        //TODO: I18N Log stack trace properly.
View Full Code Here

    String encQuery = encoder.encode( "test-query".getBytes("utf-8" ) );
    encQuery = encQuery.replaceAll( "\\=", "" );
    String inString = "http://host:0/root/path?_=" + encQuery;
    Template inTemplate = Parser.parse( inString );

    UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
    Capture<Template> outTemplate = new Capture<Template>();
    context.setCurrentUrl( EasyMock.capture( outTemplate ) );
    EasyMock.replay( context );

    SecureQueryDecodeDescriptor descriptor = new SecureQueryDecodeDescriptor();
    SecureQueryDecodeProcessor processor = new SecureQueryDecodeProcessor();
    processor.initialize( environment, descriptor );
View Full Code Here

    String encQuery = encoder.encode( inQuery.getBytes( "utf-8" ) );
    encQuery = encQuery.replaceAll( "\\=", "" );
    String inString = "http://host:0/root/path?_=" + encQuery + "&clear-param=clear-value";
    Template inTemplate = Parser.parse( inString );

    UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
    Capture<Template> outTemplate = new Capture<Template>();
    context.setCurrentUrl( EasyMock.capture( outTemplate ) );
    EasyMock.replay( context );

    SecureQueryDecodeDescriptor descriptor = new SecureQueryDecodeDescriptor();
    SecureQueryDecodeProcessor processor = new SecureQueryDecodeProcessor();
    processor.initialize( environment, descriptor );
View Full Code Here

  @Test
  public void testSimpleQueryEncoding() throws Exception {
    UrlRewriteEnvironment environment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );

    Template inTemplate = Parser.parse( "http://host:0/root/path?query" );
    UrlRewriteContext context = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( context.getCurrentUrl() ).andReturn( inTemplate );
    Capture<Template> outTemplate = new Capture<Template>();
    context.setCurrentUrl( EasyMock.capture( outTemplate ) );

    EasyMock.replay( environment, context );

    SecureQueryEncodeDescriptor descriptor = new SecureQueryEncodeDescriptor();
    SecureQueryEncodeProcessor processor = new SecureQueryEncodeProcessor();
View Full Code Here

    // Test encryption.  Results are left in encTemplate

    UrlRewriteEnvironment encEnvironment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
    EasyMock.expect( encEnvironment.resolve( "cluster.name" ) ).andReturn( Arrays.asList( "test-cluster-name" ) ).anyTimes();
    UrlRewriteContext encContext = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( encContext.getCurrentUrl() ).andReturn( origTemplate );
    Capture<Template> encTemplate = new Capture<Template>();
    encContext.setCurrentUrl( EasyMock.capture( encTemplate ) );
    EasyMock.replay( encEnvironment, encContext );

    SecureQueryEncryptDescriptor descriptor = new SecureQueryEncryptDescriptor();
    SecureQueryEncryptProcessor processor = new SecureQueryEncryptProcessor();
    processor.initialize( encEnvironment, descriptor );
    processor.process( encContext );

    assertThat( encTemplate, notNullValue() );
    query = encTemplate.getValue().getQuery().get( "_" );
    assertThat( query.getFirstValue().getPattern().length(), greaterThan( 1 ) );
    query = encTemplate.getValue().getQuery().get( "query-param-name" );
    assertThat( query, nullValue() );

    // Test decryption.  Results are left in decTemplate.

    UrlRewriteEnvironment decEnvironment = EasyMock.createNiceMock( UrlRewriteEnvironment.class );
    EasyMock.expect( decEnvironment.resolve( "cluster.name" ) ).andReturn( Arrays.asList( "test-cluster-name" ) ).anyTimes();
    Params decParams = EasyMock.createNiceMock( Params.class );
    EasyMock.expect( decParams.resolve( "cluster.name" ) ).andReturn( Arrays.asList("test-cluster-name") ).anyTimes();
    UrlRewriteContext decContext = EasyMock.createNiceMock( UrlRewriteContext.class );
    EasyMock.expect( decContext.getCurrentUrl() ).andReturn( encTemplate.getValue() );
    EasyMock.expect( decContext.getParameters() ).andReturn( decParams );
    Capture<Template> decTemplate = new Capture<Template>();
    decContext.setCurrentUrl( EasyMock.capture( decTemplate ) );
    EasyMock.replay( decEnvironment, decParams, decContext );

    SecureQueryDecryptDescriptor descriptor1 = new SecureQueryDecryptDescriptor();
    SecureQueryDecryptProcessor decProcessor = new SecureQueryDecryptProcessor();
    decProcessor.initialize( decEnvironment, descriptor1 );
View Full Code Here

TOP

Related Classes of org.apache.hadoop.gateway.filter.rewrite.spi.UrlRewriteContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.