-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
232 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Implementar políticas de claves. Ver por ejemplo | ||
https://www.isode.com/whitepapers/password-policy.html |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# encoding: utf-8 | ||
|
||
require 'devise/registrations_controller' | ||
|
||
class Jn316Gen::RegistrationsController < ::Devise::RegistrationsController | ||
include Jn316Gen::LdapHelper | ||
|
||
def update | ||
if params[:usuario] && params[:usuario][:password] && | ||
params[:usuario][:password_confirmation] && | ||
params[:usuario][:current_password] && | ||
params[:usuario][:password] != '' && | ||
params[:usuario][:password_confirmation] == params[:usuario][:password] | ||
prob = '' | ||
if ldap_cambia_clave(current_usuario.nusuario, | ||
params[:usuario][:current_password], | ||
params[:usuario][:password], prob) | ||
flash[:notice] = 'Clave cambiada en directorio LDAP' | ||
else | ||
flash[:error] = 'No pudo cambiar clave en directorio LDAP: ' + prob | ||
redirect_to Rails.configuration.relative_url_root | ||
end | ||
end | ||
super | ||
rescue Exception => exception | ||
redirect_to Rails.configuration.relative_url_root | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#encoding: UTF-8 | ||
|
||
require 'digest/sha1' | ||
require 'base64' | ||
|
||
module Jn316Gen | ||
module LdapHelper | ||
|
||
# https://www.ietf.org/rfc/rfc4514.txt | ||
def escapa_ldap | ||
|
||
end | ||
|
||
def ldap_cambia_clave(nusuario, claveactual, nuevaclave, prob) | ||
if !ENV['JN316_CLAVE'] | ||
prob='Falta clave LDAP para cambiar clave' | ||
return nil | ||
end | ||
opcon = { | ||
host: Rails.application.config.x.jn316_servidor, | ||
port: Rails.application.config.x.jn316_puerto, | ||
auth: { | ||
method: :simple, | ||
username: "cn=#{nusuario},#{Rails.application.config.x.jn316_base}", | ||
password: claveactual | ||
} | ||
}.merge(Rails.application.config.x.jn316_opcon) | ||
ldap_con = Net::LDAP.new( opcon ) | ||
if !ldap_con.bind | ||
prob = 'Clave actual errada' | ||
return false | ||
end | ||
ldap_con.open do |ldap| | ||
dn="cn=#{nusuario},#{Rails.application.config.x.jn316_base}" | ||
hash = "{SHA}" + Base64.encode64( | ||
Digest::SHA1.digest(nuevaclave) | ||
).chomp! | ||
puts 'userPassword: '+hash+"\n" | ||
ldap.replace_attribute dn, :userPassword, hash | ||
end | ||
return true | ||
rescue Exception => exception | ||
prob = 'Problema conectando a servidor LDAP. Excepción: ' + | ||
exception.to_s | ||
return false | ||
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
es: | ||
devise: | ||
failure: | ||
usuario: | ||
invalid_login: 'Autenticación falló' |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AgregaFechaSinc < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :usuario, :ultimasincldap, :date | ||
end | ||
end |
Oops, something went wrong.