Sha256: 2527cb52ab2c354312d20653579a0e810a76adc2056264852be9485eee3477e3

Contents?: true

Size: 981 Bytes

Versions: 12

Compression:

Stored size: 981 Bytes

Contents

module SafetyPin
  class JCR
    include_class('java.lang.String') {|package,name| "J#{name}" }
    include_class 'javax.jcr.SimpleCredentials'
    include_class 'org.apache.jackrabbit.commons.JcrUtils'

    def self.login(opts = {})
      repository = JcrUtils.get_repository(parse_hostname(opts[:hostname]))
      creds = SimpleCredentials.new(opts[:username], JString.new(opts[:password]).to_char_array)
      @@session = repository.login(creds)
    end

    def self.logout
      session.logout
      not session.live?
    end

    def self.logged_in?
      session.live?
    end

    def self.logged_out?
      not logged_in?
    end

    def self.session
      @@session
    end

    def self.parse_hostname(hostname)
      if hostname.end_with?("/crx/server")
        hostname
      else
        hostname + "/crx/server"
      end
    end

    def self.dev_login
      login(:hostname => "http://localhost:4502", :username => "admin", :password => "admin")
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
safety-pin-0.1.2 lib/safety_pin/jcr.rb
safety-pin-0.1.1 lib/safety_pin/jcr.rb
safety-pin-0.1.0 lib/safety_pin/jcr.rb
safety-pin-0.0.9 lib/safety_pin/jcr.rb
safety_pin-0.0.8 lib/safety_pin/jcr.rb
safety_pin-0.0.7 lib/safety_pin/jcr.rb
safety_pin-0.0.6 lib/safety_pin/jcr.rb
safety_pin-0.0.5 lib/safety_pin/jcr.rb
safety_pin-0.0.4 lib/safety_pin/jcr.rb
safety_pin-0.0.3 lib/safety_pin/jcr.rb
safety_pin-0.0.2 lib/safety_pin/jcr.rb
safety_pin-0.0.1 lib/safety_pin/jcr.rb