Example #1
0
 def setUp(self):
     super(MyTardisResourceTestCase, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(username=self.username,
                                          password=self.password)
     test_auth_service = AuthService()
     test_auth_service._set_user_from_dict(self.user,
                                           user_dict={
                                               'first_name': 'Testing',
                                               'last_name': 'MyTardis API',
                                               'email':
                                               '*****@*****.**'
                                           },
                                           auth_method="None")
     self.user.user_permissions.add(
         Permission.objects.get(codename='change_dataset'))
     self.user.user_permissions.add(
         Permission.objects.get(codename='add_dataset_file'))
     self.user_profile = UserProfile(user=self.user).save()
     self.testexp = Experiment(title="test exp")
     self.testexp.approved = True
     self.testexp.created_by = self.user
     self.testexp.locked = False
     self.testexp.save()
     testacl = ObjectACL(content_type=self.testexp.get_ct(),
                         object_id=self.testexp.id,
                         pluginId=django_user,
                         entityId=str(self.user.id),
                         canRead=True,
                         canWrite=True,
                         canDelete=True,
                         isOwner=True,
                         aclOwnershipType=ObjectACL.OWNER_OWNED)
     testacl.save()
Example #2
0
 def setUp(self):
     super(MyTardisResourceTestCase, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(username=self.username,
                                          password=self.password)
     test_auth_service = AuthService()
     test_auth_service._set_user_from_dict(
         self.user,
         user_dict={'first_name': 'Testing',
                    'last_name': 'MyTardis API',
                    'email': '*****@*****.**'},
         auth_method="None")
     self.user.user_permissions.add(
         Permission.objects.get(codename='change_dataset'))
     self.user.user_permissions.add(
         Permission.objects.get(codename='add_dataset_file'))
     self.user_profile = UserProfile(user=self.user).save()
     self.testexp = Experiment(title="test exp")
     self.testexp.approved = True
     self.testexp.created_by = self.user
     self.testexp.locked = False
     self.testexp.save()
     testacl = ObjectACL(
         content_type=self.testexp.get_ct(),
         object_id=self.testexp.id,
         pluginId=django_user,
         entityId=str(self.user.id),
         canRead=True,
         canWrite=True,
         canDelete=True,
         isOwner=True,
         aclOwnershipType=ObjectACL.OWNER_OWNED)
     testacl.save()
def authenticate(username, first_name, last_name, email):
    #todo take attr array
    user_dict = {'id': username,
                 'first_name': first_name,
                 'last_name': last_name or '(none)',
                 'email': email}

    auth_service = AuthService()
    user = auth_service._get_or_create_user_from_dict(
        user_dict, auth_key)

    user.backend = 'django.contrib.auth.backends.ModelBackend'

    return user
Example #4
0
def authenticate(username, first_name, last_name, email):
    #todo take attr array
    user_dict = {
        'id': username,
        'first_name': first_name,
        'last_name': last_name or '(none)',
        'email': email
    }

    auth_service = AuthService()
    user = auth_service._get_or_create_user_from_dict(user_dict, auth_key)

    user.backend = 'django.contrib.auth.backends.ModelBackend'

    return user
 def setUp(self):
     super(MyTardisResourceTestCase, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(username=self.username,
                                          password=self.password)
     test_auth_service = AuthService()
     test_auth_service._set_user_from_dict(
         self.user,
         user_dict={'first_name': 'Testing',
                    'last_name': 'MyTardis API',
                    'email': '*****@*****.**'},
         auth_method="None")
     self.testgroup = Group(name="Test Group")
     self.testgroup.save()
     self.testgroup.user_set.add(self.user)
     self.testfacility = Facility(name="Test Facility",
                                  manager_group=self.testgroup)
     self.testfacility.save()
     self.testinstrument = Instrument(name="Test Instrument",
                                      facility=self.testfacility)
     self.testinstrument.save()
Example #6
0
 def setUp(self):
     super(MyTardisResourceTestCase, self).setUp()
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(username=self.username,
                                          password=self.password)
     test_auth_service = AuthService()
     test_auth_service._set_user_from_dict(
         self.user,
         user_dict={'first_name': 'Testing',
                    'last_name': 'MyTardis API',
                    'email': '*****@*****.**'},
         auth_method="None")
     self.user_profile = UserProfile(user=self.user).save()
     self.testgroup = Group(name="Test Group")
     self.testgroup.save()
     self.testgroup.user_set.add(self.user)
     self.testfacility = Facility(name="Test Facility",
                                  manager_group=self.testgroup)
     self.testfacility.save()
     self.testinstrument = Instrument(name="Test Instrument",
                                      facility=self.testfacility)
     self.testinstrument.save()
Example #7
0
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

from tardis.tardis_portal.auth.authservice import AuthService

GROUPS = "_group_list"

# The auth_service ``singleton``
auth_service = AuthService()


def login(request, user):
    from django.contrib.auth import login
    login(request, user)
    request.__class__.groups = auth_service.getGroups(request)
    request.session[GROUPS] = request.groups


class LazyGroups(object):
    def __get__(self, request, obj_type=None):
        if not hasattr(request, '_cached_groups'):
            if GROUPS in request.session:
                return request.session[GROUPS]
            request._cached_groups = auth_service.getGroups(request)