Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
537 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,94 @@ | |||
module Castronaut | |||
module Presenters | |||
|
|||
class ServiceValidate | |||
MissingCredentialsMessage = "Please supply a username and password to login." | |||
|
|||
attr_reader :controller, :your_mission | |||
attr_accessor :messages, :login_ticket | |||
|
|||
delegate :params, :request, :to => :controller | |||
delegate :cookies, :env, :to => :request | |||
|
|||
def initialize(controller) | |||
@controller = controller | |||
@messages = [] | |||
@your_mission = nil | |||
end | |||
|
|||
def service | |||
params['service'] | |||
end | |||
|
|||
def renewal | |||
params['renew'] | |||
end | |||
|
|||
def service_ticket | |||
params['ticket'] | |||
end | |||
|
|||
def proxy_callback_url | |||
params['pgtUrl'] | |||
end | |||
|
|||
def represent! | |||
|
|||
|
|||
|
|||
@login_ticket = params['lt'] | |||
|
|||
login_ticket_validation_result = Castronaut::Models::LoginTicket.validate_ticket(@login_ticket) | |||
|
|||
if login_ticket_validation_result && login_ticket_validation_result.invalid? | |||
messages << login_ticket_validation_result.message | |||
@login_ticket = Castronaut::Models::LoginTicket.generate_from(client_host).ticket | |||
@your_mission = lambda { controller.erb :login, :locals => { :presenter => self } } # TODO: STATUS 401 | |||
return self | |||
end | |||
|
|||
if username.blank? || password.blank? | |||
messages << MissingCredentialsMessage | |||
@login_ticket = Castronaut::Models::LoginTicket.generate_from(client_host).ticket | |||
@your_mission = lambda { controller.erb :login, :locals => { :presenter => self } } # TODO: STATUS 401 | |||
return self | |||
end | |||
|
|||
@login_ticket = Castronaut::Models::LoginTicket.generate_from(client_host).ticket | |||
|
|||
Castronaut.logger.info("#{self.class} - Logging in with username: #{username}, login ticket: #{login_ticket}, service: #{service}") | |||
|
|||
authentication_result = Castronaut::Adapters.selected_adapter.authenticate(username, password) | |||
|
|||
if authentication_result.valid? | |||
ticket_granting_ticket = Castronaut::Models::TicketGrantingTicket.generate_for(username, client_host) | |||
cookies[:tgt] = ticket_granting_ticket.to_cookie | |||
|
|||
if service.blank? | |||
messages << "You have successfully logged in." | |||
else | |||
service_ticket = Castronaut::Models::ServiceTicket.generate_ticket_for(service, client_host, ticket_granting_ticket) | |||
|
|||
if service_ticket && service_ticket.service_uri | |||
@your_mission = lambda { controller.redirect(service_ticket.service_uri, 303) } | |||
return self | |||
else | |||
messages << "The target service your browser supplied appears to be invalid. Please contact your system administrator for help." | |||
end | |||
end | |||
|
|||
else | |||
messages << authentication_result.message | |||
end | |||
|
|||
if messages.any? | |||
@your_mission = lambda { controller.erb :login, :locals => { :presenter => self } } | |||
end | |||
|
|||
self | |||
end | |||
|
|||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.