Esempio n. 1
0
func (s *Store) CreateSchemas() error {
	if _, err := s.db.Exec(accountSchema); err != nil {
		log.Warnf("Error creating schema %s: %s", accountSchema, err)
		return err
	}
	return nil
}
Esempio n. 2
0
func (c ClaimsCarrier) String() string {
	result, err := json.Marshal(c)
	if err != nil {
		log.Warnf(`Could not marshal ClaimsCarrier "%v": "%v".`, c, err)
		return ""
	}
	return string(result)
}
Esempio n. 3
0
func (s *Store) CreateSchemas() error {
	for _, schema := range schemata {
		if _, err := s.db.Exec(schema); err != nil {
			log.Warnf("Error creating schema %s: %s", schema, err)
			return err
		}
	}
	return nil
}
Esempio n. 4
0
func NewContextFromAuthorization(ctx context.Context, req *http.Request, j *hjwt.JWT, p policy.Storage) context.Context {
	bearer := osin.CheckBearerAuth(req)
	if bearer == nil {
		log.Warn("No authorization bearer given.")
		return NewContextFromAuthValues(ctx, nil, nil, nil)
	}

	t, err := j.VerifyToken([]byte(bearer.Code))
	if err != nil {
		log.Warnf(`Token validation errored: "%v".`, err)
		return NewContextFromAuthValues(ctx, nil, nil, nil)
	} else if !t.Valid {
		log.Warn("Token is invalid.")
		return NewContextFromAuthValues(ctx, nil, nil, nil)
	}

	claims := hjwt.ClaimsCarrier(t.Claims)
	user := claims.GetSubject()
	if user == "" {
		log.Warnf(`sub claim may not be empty, to: "%v".`, t.Claims)
		return NewContextFromAuthValues(ctx, nil, nil, nil)
	}

	policies, err := p.FindPoliciesForSubject(user)
	if err != nil {
		log.Warnf(`Policies for "%s" could not be retrieved: "%v"`, user, err)
		return NewContextFromAuthValues(ctx, nil, nil, nil)
	}

	//	user, err := s.Get(id)
	//	if err != nil {
	//		log.Warnf("Subject not found in store: %v %v", t.Claims, err)
	//		return NewContextFromAuthValues(ctx, nil, nil, nil)
	//	}

	return NewContextFromAuthValues(ctx, claims, t, policies)
}
Esempio n. 5
0
func (c ClaimsCarrier) getAsTime(key string) time.Time {
	ret := &time.Time{}
	if s, ok := c[key]; ok {
		if r, ok := s.(time.Time); ok {
			return r
		} else if p, ok := s.(string); ok {
			if err := ret.UnmarshalJSON([]byte(`"` + p + `"`)); err != nil {
				log.Warnf(`Could not unmarshal time field: "%v".`, c, err)
				return *ret
			}
			return *ret
		}
	}
	return *ret
}