Beispiel #1
0
def user_details():
    user = cas.username

    ## Load config
    config = utils.loadConfig()

    ## Config the handler
    sp_handler = securepass.SecurePass(app_id=config['app_id'],
                                       app_secret=config['app_secret'],
                                       endpoint=config['endpoint'])

    if user is not None:
        try:
            spuser = sp_handler.user_info(user=user)
            session['username'] = user

            xattrs = sp_handler.users_xattr_list(user=user)

            ## need to understand if the xattr is in list
            if 'sshkey' in xattrs:
                sshkey = textwrap.wrap(xattrs['sshkey'], width=80)

            else:
                sshkey = ""

            return render_template('user.html',
                                   spuser=spuser,
                                   xattrs=xattrs,
                                   user=user,
                                   sshkey=sshkey)

        except:
            return "Bad thing happened!"

    return redirect('/login/')
    def __init__(self, conf=None):
        super(Identity, self).__init__()

        if conf is None:
            self.conf = CONF
        else:
            self.conf = conf

        LOG.warning("securepass init %s" % conf)

        LOG.warning("securepass app_id %s" % CONF.securepass.app_id)
        LOG.warning("securepass app_secret %s" % CONF.securepass.app_secret)

        # global securepass conf
        self.realm = CONF.securepass.realm
        self.sp_handler = securepass.SecurePass(
            app_id=CONF.securepass.app_id,
            app_secret=CONF.securepass.app_secret,
            endpoint=CONF.securepass.endpoint)
    def authenticate(self, username, password):

        try:
            endpoint = settings.SP_ENDPOINT
            autocreate = settings.SP_AUTOCREATE_USER
        except:
            endpoint = "https://beta.secure-pass.net/"
            autocreate = True

        sp_handle = securepass.SecurePass(app_id=settings.SP_APP_ID,
                                          app_secret=settings.SP_APP_SECRET,
                                          endpoint=endpoint)

        if sp_handle.user_auth(user=username, secret=password):

            try:
                mapping = User.objects.get(username=username)

            except User.DoesNotExist:
                # user will have an "unusable" password
                if autocreate:
                    mapping = User.objects.create_user(username, '')
                    mapping.save()
                else:
                    return None

            try:
                myuser = sp_handle.user_info(user=username)

                mapping.first_name = myuser['name']
                mapping.last_name = myuser['surname']
                mapping.is_active = myuser['enabled']
                mapping.email = myuser['email']

                mapping.save()
            except:
                return None

            return mapping

        else:
            return None
def user_ssh():
    user = cas.username
    form = SshKey(request.form)

    if request.method == 'POST' and form.validate():
        ## Load config
        config = utils.loadConfig()

        ## Config the handler
        sp_handler = securepass.SecurePass(app_id=config['app_id'],
                                           app_secret=config['app_secret'],
                                           endpoint=config['endpoint'])

        ## Set ssh key
        ## Need to trap SecurePass errors'
        sp_handler.users_xattr_set(user=user, attribute='sshkey', value=form.sshkey.data)

        return "SSH Key changed"

    return render_template('ssh_change.html', form=form, user=user)
Beispiel #5
0
def user_password():

    #if 'username' not in session:
    #        return redirect(url_for('user_details'))
    user = cas.username
    form = PasswordChange(request.form)

    if request.method == 'POST' and form.validate():
        ## Load config
        config = utils.loadConfig()

        ## Config the handler
        sp_handler = securepass.SecurePass(app_id=config['app_id'],
                                           app_secret=config['app_secret'],
                                           endpoint=config['endpoint'])

        ## Change password
        sp_handler.user_password_change(user=user, password=form.password.data)

        return "Password changed"

    return render_template('password_change.html', form=form, user=user)