// CheckPermission checks the user/method/path combination from the request.
// Returns true (permission granted) or false (permission forbidden)
435190
func CheckPermission(e *casbin.Enforcer, r *revel.Request) bool {
	user := GetUserName(r)
	method := r.Method
	path := r.URL.Path
	return e.Enforce(user, path, method)
}
417746
func IsErrPermissionDenied(err error) bool {
	return err != nil && strings.Contains(err.Error(), errPermissionDenied)
}
642107
func (ph *permissionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// Check if the user has the right admin/user rights
	if ph.perm.Rejected(w, req) {
		// Let the user know, by calling the custom "permission denied" function
		ph.perm.DenyFunction()(w, req)
		// Reject the request by not calling the next handler below
		return
	}
	// Serve the requested page if permissions were granted
	ph.mux.ServeHTTP(w, req)
}
1244332
func (e *SyncedEnforcer) DeletePermission(permission ...string) bool {
	e.m.Lock()
	defer e.m.Unlock()
	return e.Enforcer.DeletePermission(permission...)
}
579408
func (perm *Permissions) ServeHTTP(w http.ResponseWriter, req *http.Request, next http.HandlerFunc) {
	// Check if the user has the right admin/user rights
	if perm.Rejected(w, req) {
		// Get and call the Permission Denied function
		perm.DenyFunction()(w, req)
		// Reject the request by not calling the next handler below
		return
	}

	// Call the next middleware handler
	next(w, req)
}
249090
func (api *API) GetCurrentUserPermissions() (*Permissions, error) {
	result := new(Permissions)
	url := createUrl(api, userPathSegment, "current_user_permissions")
	err := api.Client.Get(url, &result, http.StatusOK)
	if err != nil {
		return nil, err
	}
	return result, nil
}
407130
func (e *Enforcer) HasPermissionForUser(user string, permission ...string) bool {
	params := make([]interface{}, 0, len(permission)+1)

	params = append(params, user)
	for _, perm := range permission {
		params = append(params, perm)
	}

	return e.HasPolicy(params...)
}
1019505
func (c *CredentialsStore) CheckRequest(b BasicAuther) bool {
	username, password, ok := b.BasicAuth()
	if !ok || !c.Check(username, password) {
		return false
	}
	return true
}
172707
func NewFolderPermission(Action *FolderAction, Allow bool) *FolderPermission {
	s := new(FolderPermission)
	s.Action = Action
	s.Allow = Allow
	return s
}
922531
func (api Client) CheckRequest(req *http.Request) (context.Context, int, authFailure, error) {
	log.DebugR(req, "CheckRequest called", nil)

	ctx := req.Context()

	florenceToken := req.Header.Get(common.FlorenceHeaderKey)
	if len(florenceToken) < 1 {
		c, err := req.Cookie(common.FlorenceCookieKey)
		if err != nil {
			log.DebugR(req, err.Error(), nil)
		} else {
			florenceToken = c.Value
		}
	}

	authToken := req.Header.Get(common.AuthHeaderKey)

	isUserReq := len(florenceToken) > 0
	isServiceReq := len(authToken) > 0

	// if neither user nor service request, return unchanged ctx
	if !isUserReq && !isServiceReq {
		return ctx, http.StatusUnauthorized, errors.WithMessage(errUnableToIdentifyRequest, "no headers set on request"), nil
	}

	url := api.BaseURL + "/identity"

	logData := log.Data{
		"is_user_request":    isUserReq,
		"is_service_request": isServiceReq,
		"url":                url,
	}
	splitTokens(florenceToken, authToken, logData)

	log.DebugR(req, "calling AuthAPI to authenticate", logData)

	outboundAuthReq, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.ErrorR(req, err, logData)
		return ctx, http.StatusInternalServerError, nil, err
	}

	if isUserReq {
		outboundAuthReq.Header.Set(common.FlorenceHeaderKey, florenceToken)
	} else {
		outboundAuthReq.Header.Set(common.AuthHeaderKey, authToken)
	}

	if api.HTTPClient == nil {
		api.Lock.Lock()
		api.HTTPClient = rchttp.NewClient()
		api.Lock.Unlock()
	}

	resp, err := api.HTTPClient.Do(ctx, outboundAuthReq)
	if err != nil {
		log.ErrorR(req, err, logData)
		return ctx, http.StatusInternalServerError, nil, err
	}

	// Check to see if the user is authorised
	if resp.StatusCode != http.StatusOK {
		return ctx, resp.StatusCode, errors.WithMessage(errUnableToIdentifyRequest, "unexpected status code returned from AuthAPI"), nil
	}

	identityResp, err := unmarshalIdentityResponse(resp)
	if err != nil {
		log.ErrorR(req, err, logData)
		return ctx, http.StatusInternalServerError, nil, err
	}

	var userIdentity string
	if isUserReq {
		userIdentity = identityResp.Identifier
	} else {
		userIdentity = req.Header.Get(common.UserHeaderKey)
	}

	logData["user_identity"] = userIdentity
	logData["caller_identity"] = identityResp.Identifier
	log.DebugR(req, "identity retrieved, setting context values", logData)

	ctx = context.WithValue(ctx, common.UserIdentityKey, userIdentity)
	ctx = context.WithValue(ctx, common.CallerIdentityKey, identityResp.Identifier)

	return ctx, http.StatusOK, nil, nil
}
624074
func hasPermissionToDir(info os.FileInfo) bool {
	user, err := user.Current()
	if err != nil {
		return true
	}
	uid, _ := strconv.Atoi(user.Uid)
	// super-user
	if uid == 0 {
		return true
	}

	st, _ := info.Sys().(*syscall.Stat_t)
	if st == nil {
		return true
	}
	perm := info.Mode().Perm()
	// user (u)
	if perm&0100 != 0 && st.Uid == uint32(uid) {
		return true
	}

	gid, _ := strconv.Atoi(user.Gid)
	// other users in group (g)
	if perm&0010 != 0 && st.Uid != uint32(uid) && st.Gid == uint32(gid) {
		return true
	}
	// remaining users (o)
	if perm&0001 != 0 && st.Uid != uint32(uid) && st.Gid != uint32(gid) {
		return true
	}

	return false
}
354945
func (m *MockAuthorizer) HasPermission(arg0 permission.Access, arg1 names_v2.Tag) (bool, error) {
	ret := m.ctrl.Call(m, "HasPermission", arg0, arg1)
	ret0, _ := ret[0].(bool)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
121112
func (f *FolderConfiguration) CheckPath() error {
	fi, err := f.Filesystem().Stat(".")
	if err != nil {
		if !fs.IsNotExist(err) {
			return err
		}
		return ErrPathMissing
	}

	// Users might have the root directory as a symlink or reparse point.
	// Furthermore, OneDrive bullcrap uses a magic reparse point to the cloudz...
	// Yet it's impossible for this to happen, as filesystem adds a trailing
	// path separator to the root, so even if you point the filesystem at a file
	// Stat ends up calling stat on C:\dir\file\ which, fails with "is not a directory"
	// in the error check above, and we don't even get to here.
	if !fi.IsDir() && !fi.IsSymlink() {
		return ErrPathNotDirectory
	}

	_, err = f.Filesystem().Stat(f.MarkerName)
	if err != nil {
		if !fs.IsNotExist(err) {
			return err
		}
		return ErrMarkerMissing
	}

	return nil
}
445689
func NewFilePermission(Action *FileAction, Allow bool) *FilePermission {
	s := new(FilePermission)
	s.Action = Action
	s.Allow = Allow
	return s
}
1258766
func (c *Browser) GrantPermissionsWithParams(v *BrowserGrantPermissionsParams) (*gcdmessage.ChromeResponse, error) {
	return gcdmessage.SendDefaultRequest(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Browser.grantPermissions", Params: v})
}
1348734
func (r *ServerService) Permissions() *ServerPermissionsCall {
	c := &ServerPermissionsCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	return c
}
971154
func (meta Meta) HasPermission(mode roles.PermissionMode, context *qor.Context) bool {
	if meta.Permission == nil {
		return true
	}
	var roles = []interface{}{}
	for _, role := range context.Roles {
		roles = append(roles, role)
	}
	return meta.Permission.HasPermission(mode, roles...)
}