changeset 51:a1498298d3ee

Security in progress
author wizard@linux-odin.local
date Mon, 01 Mar 2010 17:25:36 +0300 (2010-03-01)
parents 521c9c1a3ea1
children 15d720913562 cf23fd8423f4
files .includepath .project .settings/org.eclipse.core.resources.prefs .settings/org.eclipse.ltk.core.refactoring.prefs Lib/IMPL/SVN.pm Lib/IMPL/Security.pm Lib/IMPL/Security/Auth.pm Lib/IMPL/Security/Auth/AuthResult.pm Lib/IMPL/Security/Auth/Simple.pm Lib/IMPL/Security/AuthResult.pm Lib/IMPL/Security/Context.pm Lib/IMPL/Security/Role.pm Lib/IMPL/Security/Rule/RoleCheck.pm
diffstat 13 files changed, 229 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.includepath	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<includepath>
+  <includepathentry path="${resource_loc:/Impl/Lib}" />
+</includepath>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.project	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Impl</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.epic.perleditor.perlbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.epic.perleditor.perlnature</nature>
+	</natures>
+</projectDescription>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.settings/org.eclipse.core.resources.prefs	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,3 @@
+#Fri Feb 26 10:46:20 MSK 2010
+eclipse.preferences.version=1
+encoding/<project>=cp1251
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.settings/org.eclipse.ltk.core.refactoring.prefs	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,3 @@
+#Fri Feb 26 10:46:20 MSK 2010
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
--- a/Lib/IMPL/SVN.pm	Sat Feb 27 16:28:45 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-package IMPL::SVN;
-use strict;
-
-use base qw(IMPL::Object);
-use IMPL::Object::Property;
-
-BEGIN {
-    public virtual _direct property SvnClient => get;
-}
-
-sub UpdateBatch {
-    my ($this,$revstart,$revend) = @_;
-
-
-}
\ No newline at end of file
--- a/Lib/IMPL/Security.pm	Sat Feb 27 16:28:45 2010 +0300
+++ b/Lib/IMPL/Security.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -1,4 +1,24 @@
 package IMPL::Security;
+require IMPL::Security::Context;
+require IMPL::Security::Rule::RoleCheck;
+
+our @rules = (
+	\&IMPL::Security::Rule::RoleCheck::SatisfyAll
+);
+
+sub AccessCheck {
+	my ($self, $object, $desiredAccess, $context) = @_;
+	
+	$context = IMPL::Security::Context->contextCurrent;
+	
+	$_->() or return 0 foreach @{$self->Rules};
+	
+	return 1;
+}
+
+sub Rules {
+	return \@rules;
+}
 
 1;
 
@@ -8,6 +28,16 @@
 
 =head1 DESCRIPTION
 
+������ ��� �������������� ������������, ��������� �������� ������� ��� �����������
+� �������������� �������������.
+
+������ ��������������, ���������� �������� ������� �� ����������, ���������������
+������������, ��� ���� ��������� �������� ������������, ������� ��������
+������������� ������������ � ������ �������� �����.
+
+��� �������� ���� ������� ���������� ���������������� �������� ������ �������,
+���� ��� ������� ���������, �� ������ �����������.
+
 
 
 =cut
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Auth.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,36 @@
+package IMPL::Security::Auth;
+
+use constant {
+	SUCCESS => 1,
+	INCOMPLETE => 2,
+	FAIL => 3	
+};
+
+use base qw(Exporter);
+
+our @EXPORT_OK = qw(&SUCCESS &INCOMPLETE &FAI);
+our %EXPORT_TAGS = (Const => [qw(&SUCCESS &INCOMPLETE &FAI)]);
+
+1;
+
+__END__
+
+=pod
+
+=head1 DESCRIPTION
+
+�������� ������ ��� ����������� �������������.
+
+������� ����������� ������� �� ��������� �����
+
+1. ������ ���������� �� ������ ������ ��� ����������� � ���������� �����������.
+2. ������ �������� ������, ������� ������ �������������� ��� �������,
+���������� ��������������
+3. ������ �������������� ���������� ���������, �� ������ ��������
+���� ����������� �������� ������������, ���� ������������ ������� ��������������
+
+���������� �������� ������������ �������� ������ ��� ������� � ������ ��������������,
+� ������ ���������� ���������� �������� ������, �������� �������������, ��������� �����
+� �.�. 
+
+=cut
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Auth/AuthResult.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,15 @@
+package IMPL::Security::Auth::Result;
+use strict;
+
+use base qw(IMPL::Object);
+use IMPL::Class::Property;
+use IMPL::Class::Property::Direct;
+
+BEGIN {
+    public _direct property State => prop_get;
+    public _direct property ClientSecData => prop_get;
+    public _direct property AuthMod => prop_get;
+}
+
+
+1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Auth/Simple.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,27 @@
+package IMPL::Security::Auth::Simple;
+
+use base qw(IMPL::Security::Auth);
+use Digest::MD5;
+import IMPL::Security::Auth qw(:Const);
+
+sub DoAuth {
+	my ($this,$clientData,$serverData) = @_;
+
+	if (Digest::MD5::md5_hex($clientData) eq $serverData) {
+		return SUCCESS;
+	} elsee {
+		return FAIL;
+	}
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 DESCRIPTION
+
+������ ������� �����������
+
+=cut
\ No newline at end of file
--- a/Lib/IMPL/Security/AuthResult.pm	Sat Feb 27 16:28:45 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-package IMPL::Security::AuthResult;
-use strict;
-
-use base qw(IMPL::Object);
-use IMPL::Class::Property;
-use IMPL::Class::Property::Direct;
-
-BEGIN {
-    public _direct property State => prop_get;
-    public _direct property Session => prop_get;
-    public _direct property ClientSecData => prop_get;
-    public _direct property AuthMod => prop_get;
-}
-
-
-1;
--- a/Lib/IMPL/Security/Context.pm	Sat Feb 27 16:28:45 2010 +0300
+++ b/Lib/IMPL/Security/Context.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -8,12 +8,13 @@
 
 require IMPL::Security::Principal;
 
-my $current = __PACKAGE__->nobody;
+my $current;
 my $nobody;
 
 BEGIN {
     public property Principal => prop_get;
     public property AssignedRoles => prop_all;
+    public property AuthSession => prop_all;
 }
 
 sub Impersonate {
@@ -33,10 +34,17 @@
     }
 }
 
-sub nobody {
+sub contextNobody {
     my ($self) = @_;
     $nobody = $self->new(Principal => IMPL::Security::Principal->nobody, AssignedRoles => undef) unless $nobody;
     $nobody;
 }
 
+sub contextCurrent {
+	my ($self) = @_;
+	
+	$current = __PACKAGE__->nobody unless $current;
+	$current;
+}
+
 1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Role.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,67 @@
+package IMPL::Security::Role;
+
+use base qw(IMPL::Object);
+
+use IMPL::Class::Property;
+
+BEGIN {
+	public property roleName => prop_get;
+	public property parentRoles => prop_get;
+}
+
+sub CTOR {
+	my ($this,$name,$parentRoles) = @_;
+	
+	$this->roleName($name);
+	$this->parentRoles($parentRoles);
+}
+
+sub Satisfy {
+	my ($this,@roles) = @_;	
+	
+	return 1 unless $this->_FilterRoles( @roles );
+}
+
+sub _FilterRoles {
+	my ($this,@roles) = @_;
+	
+	@roles = grep not (ref $_ ? $this == $_ : $this->roleName eq $_), @roles;
+	
+	@roles = $_->_FilterRoles(@roles) or return foreach @{$this->parentRoles} ;
+	
+	return @roles;
+}
+
+
+1;
+
+__END__
+
+=pod
+
+=head1 DESCRIPTION
+
+����. ����� �������� � ���� ������� ����.
+������� ����� ��� �������� ������� ����������� ����� � ������� ����.
+
+=head1 MEMBERS
+
+=over
+
+=item C<roleName>
+
+��� ����, �� �������������
+
+=item C<parentRoles>
+
+������ ������������ �����
+
+=item C<Satisfy(@roles_list)>
+
+��������� ������� ����� ��������� ����� �� ������ @roles_list.
+����������� ������������� ��� ����� ��������, ��� � ���� �����.
+���������� 0 � ������ �������, 1 ��� ������� ����������� �����
+
+=back
+
+=cut
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Security/Rule/RoleCheck.pm	Mon Mar 01 17:25:36 2010 +0300
@@ -0,0 +1,16 @@
+package IMPL::Security::Rule::RoleCheck;
+
+require IMPL::Security::Role;
+
+sub SatisfyAll {
+	my ($secPackage,$object,$desiredAccess,$context) = @_;
+	
+	my $roleEffective = new IMPL::Security::Role ( effective => $context->AssignedRoles );
+	
+	return $roleEffective->Satisfy(ExtractRoles($object));
+}
+
+sub _ExtractRoles {
+	return ();
+}
+