Example #1
0
class PulpAuthentication():
    """ Authenticates against the Pulp server in the Pulp client
    config (/etc/pulp/client.conf) """
    supports_object_permissions = False
    supports_anonymous_user = False
    supports_inactive_user = False
    
    def __init__(self):
        self.server = get_pulp_server()
        self.userapi = UserAPI()
    
    def authenticate(self, username, password=None):
        """ authenticate a user """
        try:
            self.server.set_basic_auth_credentials(username, password)
            logging.info("Successfully logged in with password")
            cert = self.userapi.admin_certificate()
            bundle = SpongeBundle(username)
            bundle.write(cert)
            self.server = get_pulp_server(new=True)
            self.server.set_ssl_credentials(bundle.crtpath())
            udata = self.userapi.user(username)
            logger.info("%s logged in successfully" % username)
        except server.ServerRequestError, err:
            logger.warning("Login failure for %s: %s" % (username, err[1]))
            return None
        except Exception, err:
            logger.warning(traceback.format_exc())
            return None
Example #2
0
def get_pulp_server(user=None, new=False):
    """ set up a pulp client server instance """
    if new or not isinstance(server.active_server, server.Server):
        config = ConsumerConfig()
        pulpserver = server.PulpServer(config.server['host'],
                                       int(config.server['port']),
                                       config.server['scheme'],
                                       config.server['path'])
        server.set_active_server(pulpserver)

    if user:
        bundle = SpongeBundle(user)
        if os.path.exists(bundle.crtpath()):
            server.active_server.set_ssl_credentials(bundle.crtpath())
        else:
            raise IOError("No Pulp certificate found for %s at %s" %
                          (user, bundle.crtpath()))

        # make a quick and easy API call to verify that the session is
        # still active
        userapi = UserAPI()
        userapi.user(user)

    return server.active_server
Example #3
0
def delete(request, login=None):
    userapi = UserAPI()
    user = userapi.user(login)
    if request.method == 'POST':
        form = DeleteOkayForm(request.POST)
        if form.is_valid():
            try:
                userapi.delete(login=login)
                messages.success(request,
                                 "Deleted user %s (%s)" %
                                 (user['name'], user['login']))
                return \
                    HttpResponseRedirect(reverse('sponge.views.users.list'))
            except ServerRequestError, err:
                messages.error(request,
                               "Failed to delete user %s (%s): %s"
                               (user['name'], user['login'], err[1]))