Class: VertxWeb::CSRFHandler

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb

Overview

This handler adds a CSRF token to requests which mutate state. In order change the state a (XSRF-TOKEN) cookie is set with a unique token, that is expected to be sent back in a (X-XSRF-TOKEN) header. The behavior is to check the request body header and cookie for validity. This Handler requires session support, thus should be added somewhere below Session and Body handlers.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


23
24
25
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 23

def @@j_api_type.accept?(obj)
  obj.class == CSRFHandler
end

+ (::VertxWeb::CSRFHandler) create(secret = nil)

Instantiate a new CSRFHandlerImpl with a secret


 CSRFHandler.create("s3cr37")

Parameters:

  • secret (String) (defaults to: nil)
    server secret to sign the token.

Returns:

Raises:

  • (ArgumentError)


53
54
55
56
57
58
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 53

def self.create(secret=nil)
  if secret.class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::CSRFHandler.java_method(:create, [Java::java.lang.String.java_class]).call(secret),::VertxWeb::CSRFHandler)
  end
  raise ArgumentError, "Invalid arguments when calling create(#{secret})"
end

+ (Object) j_api_type



32
33
34
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 32

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



35
36
37
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 35

def self.j_class
  Java::IoVertxExtWebHandler::CSRFHandler.java_class
end

+ (Object) unwrap(obj)



29
30
31
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 29

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



26
27
28
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 26

def @@j_api_type.wrap(obj)
  CSRFHandler.new(obj)
end

Instance Method Details

- (void) handle(arg0 = nil)

This method returns an undefined value.

Parameters:

Raises:

  • (ArgumentError)


40
41
42
43
44
45
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 40

def handle(arg0=nil)
  if arg0.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:handle, [Java::IoVertxExtWeb::RoutingContext.java_class]).call(arg0.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling handle(#{arg0})"
end
Set the cookie name. By default XSRF-TOKEN is used as it is the expected name by AngularJS however other frameworks might use other names.

Parameters:

  • name (String) (defaults to: nil)
    a new name for the cookie.

Returns:

  • (self)

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 63

def set_cookie_name(name=nil)
  if name.class == String && !block_given?
    @j_del.java_method(:setCookieName, [Java::java.lang.String.java_class]).call(name)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_cookie_name(#{name})"
end
Set the cookie path. By default / is used.

Parameters:

  • path (String) (defaults to: nil)
    a new path for the cookie.

Returns:

  • (self)

Raises:

  • (ArgumentError)


73
74
75
76
77
78
79
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 73

def set_cookie_path(path=nil)
  if path.class == String && !block_given?
    @j_del.java_method(:setCookiePath, [Java::java.lang.String.java_class]).call(path)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_cookie_path(#{path})"
end

- (self) set_header_name(name = nil)

Set the header name. By default X-XSRF-TOKEN is used as it is the expected name by AngularJS however other frameworks might use other names.

Parameters:

  • name (String) (defaults to: nil)
    a new name for the header.

Returns:

  • (self)

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 84

def set_header_name(name=nil)
  if name.class == String && !block_given?
    @j_del.java_method(:setHeaderName, [Java::java.lang.String.java_class]).call(name)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_header_name(#{name})"
end

- (self) set_nag_https(nag = nil)

Should the handler give warning messages if this handler is used in other than https protocols?

Parameters:

  • nag (true, false) (defaults to: nil)
    true to nag

Returns:

  • (self)

Raises:

  • (ArgumentError)


94
95
96
97
98
99
100
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 94

def set_nag_https(nag=nil)
  if (nag.class == TrueClass || nag.class == FalseClass) && !block_given?
    @j_del.java_method(:setNagHttps, [Java::boolean.java_class]).call(nag)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_nag_https(#{nag})"
end

- (self) set_response_body(responseBody = nil)

Set the body returned by the handler when the XSRF token is missing or invalid.

Parameters:

  • responseBody (String) (defaults to: nil)
    the body of the response. If null, no response body will be returned.

Returns:

  • (self)

Raises:

  • (ArgumentError)


104
105
106
107
108
109
110
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 104

def set_response_body(responseBody=nil)
  if responseBody.class == String && !block_given?
    @j_del.java_method(:setResponseBody, [Java::java.lang.String.java_class]).call(responseBody)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_response_body(#{responseBody})"
end

- (self) set_timeout(timeout = nil)

Set the timeout for tokens generated by the handler, by default it uses the default from the session handler.

Parameters:

  • timeout (Fixnum) (defaults to: nil)
    token timeout

Returns:

  • (self)

Raises:

  • (ArgumentError)


114
115
116
117
118
119
120
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web/csrf_handler.rb', line 114

def set_timeout(timeout=nil)
  if timeout.class == Fixnum && !block_given?
    @j_del.java_method(:setTimeout, [Java::long.java_class]).call(timeout)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_timeout(#{timeout})"
end