Package com.foreach.cuke.rest.authentication

Examples of com.foreach.cuke.rest.authentication.Authentication


    if ( Arrays.asList( HttpMethod.POST, HttpMethod.PUT ).contains( httpMethod ) ) {
      headers.setContentType( MediaType.APPLICATION_FORM_URLENCODED );
    }
    headers.setAccept( Arrays.asList( MediaType.APPLICATION_JSON ) );

    Authentication defaultAuthentication = context.lookup( "rest.base.auth" );

    if ( defaultAuthentication != null ) {
      LOG.debug( "applying default request authentication {}", defaultAuthentication );
      defaultAuthentication.apply( uri, headers );
    }

    MultiValueMap<String, Object> values = new LinkedMultiValueMap<String, Object>();

    if ( dataTable != null ) {
      DataTable cleanedTable = fixTableHeader( dataTable );
      boolean hasTypeSpec = cleanedTable.topCells().size() > 2;

      for ( Map<String, String> row : cleanedTable.asMaps( String.class, String.class ) ) {
        String name = spel.getValueAsString( row.get( "name" ) );
        String value = spel.getValueAsString( row.get( "value" ) );
        String type = row.get( "type" );

        if ( type != null ) {
          type = spel.getValueAsString( type );
        }
        else {
          type = "data";
        }

        // Content-type is a special case
        if ( StringUtils.startsWithIgnoreCase( type, "query" ) ) {
          uri.queryParam( name, value );
        }
        else if ( StringUtils.equalsIgnoreCase( type, "header" ) ) {
          if ( StringUtils.equalsIgnoreCase( "content-type", name ) ) {
            headers.setContentType( MediaType.valueOf( value ) );
          }
          else {
            headers.add( name, value );
          }
        }
        else if ( StringUtils.startsWithIgnoreCase( type, "auth" )
            || ( !hasTypeSpec
            && ( StringUtils.equals( name, "auth" ) || StringUtils.equals( name, "authentication" ) ) )
            ) {
          Authentication authentication = context.lookup( value );

          if ( authentication == null ) {
            fail( "No authentication configured under variable " + value );
          }

          LOG.debug( "applying request authentication {}", authentication );
          authentication.apply( uri, headers );
        }
        else if ( StringUtils.equalsIgnoreCase( "content-type", name ) ) {
          headers.setContentType( MediaType.valueOf( value ) );
        }
        else if ( StringUtils.equalsIgnoreCase( type, "data" ) ) {
View Full Code Here


    HttpHeaders headers = new HttpHeaders();
    headers.setContentType( MediaType.APPLICATION_JSON );
    headers.setAccept( Arrays.asList( MediaType.APPLICATION_JSON ) );

    Authentication defaultAuthentication = context.lookup( "rest.base.auth" );

    if ( defaultAuthentication != null ) {
      LOG.debug( "applying default request authentication {}", defaultAuthentication );
      defaultAuthentication.apply( uri, headers );
    }

    HttpEntity<?> request = new HttpEntity<Object>( instance, headers );

    restRequest.execute(
View Full Code Here

  @Given("^(?:i )?(?:create |set )?(\\w+) authentication as \"([^\"]*)\" with parameters:$")
  public void authentication_as_with_parameters( String authenticationType,
                                                 String variableName,
                                                 Map<String, String> parameters ) throws Throwable {
    Authentication authentication =
        authenticationRepository.get( authenticationType, spel.replaceValues( parameters ) );

    context.put( variableName, authentication );
  }
View Full Code Here

        String base64Creds = Base64.encodeBytes( plainCredsBytes );

        headers.add( "Authorization", "Basic " + base64Creds );
      }
      else {
        Authentication defaultAuthentication = context.lookup( "rest.base.auth" );

        if ( defaultAuthentication != null ) {
          LOG.debug( "applying default request authentication {}", defaultAuthentication );
          defaultAuthentication.apply( uri, headers );
        }
      }

      // Build request
      for ( Map.Entry<String, String> parameter : parameters.entrySet() ) {
View Full Code Here

TOP

Related Classes of com.foreach.cuke.rest.authentication.Authentication

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.