//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCacheCheck() public virtual void shouldCacheCheck() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.ListQueryParameterObject query = new org.camunda.bpm.engine.impl.db.ListQueryParameterObject(); ListQueryParameterObject query = new ListQueryParameterObject(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.AuthorizationCheck authCheck = query.getAuthCheck(); AuthorizationCheck authCheck = query.AuthCheck; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.HashMap<String, Object> expectedQueryParams = new java.util.HashMap<String, Object>(); Dictionary <string, object> expectedQueryParams = new Dictionary <string, object>(); expectedQueryParams["userId"] = AUTHENTICATED_USER_ID; expectedQueryParams["authGroupIds"] = AUTHENTICATED_GROUPS; // given when(mockedConfiguration.AuthorizationCheckRevokes).thenReturn(ProcessEngineConfiguration.AUTHORIZATION_CHECK_REVOKE_AUTO); when(mockedEntityManager.selectBoolean(eq("selectRevokeAuthorization"), eq(expectedQueryParams))).thenReturn(true); // if authorizationManager.configureQuery(query); authorizationManager.configureQuery(query); // then assertEquals(true, authCheck.RevokeAuthorizationCheckEnabled); verify(mockedEntityManager, times(1)).selectBoolean(eq("selectRevokeAuthorization"), eq(expectedQueryParams)); }
public async Task <IActionResult> OnPostAsync(string EventID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } if (!ModelState.IsValid) { return(Page()); } Team.EventID = EventID; Team.ExpPTS = Services.CalculateTeamMetrics.ComputedTeamScore(Team); _context.Team.Add(Team); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { EventID = Team.EventID, })); }
public async Task <ActionResult> OnGetQuickAddTeam(string EventID, string TeamNumber, string TeamName, string OfficialMatchID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } Team Team = new Team { EventID = EventID, TeamNumber = TeamNumber, TeamName = TeamName }; await _context.AddAsync(Team); await _context.SaveChangesAsync(); var _EventID = EventID; var _OfficialMatchID = OfficialMatchID; return(RedirectToPage("./Edit", new { EventID = _EventID, OfficialMatchID = _OfficialMatchID, })); }
public async Task <IActionResult> OnGetDelete(string EventID, string TeamID, string ScoutedMatchID) { if (EventID == null || TeamID == null || ScoutedMatchID == null) { return(NotFound()); } if (!AuthorizationCheck.ScoutedMatch(_context, ScoutedMatchID, User.Identity.Name)) { return(Forbid()); } ScoutedMatch ScoutedMatch = await _context.ScoutedMatch.FindAsync(ScoutedMatchID); if (ScoutedMatch != null) { Team ScoutedTeam = await _context.Team.FindAsync(TeamID); IList <int> Scores = await _context.ScoutedMatch.AsNoTracking().Where(s => s.TeamID == TeamID).Select(s => s.Score).ToListAsync(); Scores.Remove(ScoutedMatch.Score); ScoutedTeam.AvgPTS = Math.Round(Scores.Average(), 1); _context.Team.Update(ScoutedTeam); _context.ScoutedMatch.Remove(ScoutedMatch); await _context.SaveChangesAsync(); } var _EventID = EventID; var _TeamID = TeamID; return(RedirectToPage("./Index", new { EventID = _EventID, TeamID = _TeamID, })); }
public async Task <IActionResult> OnGetAsync(string EventID, string OfficialMatchID) { if (EventID == null || OfficialMatchID == null) { return(NotFound()); } if (!AuthorizationCheck.OfficialMatch(_context, OfficialMatchID, User.Identity.Name)) { return(Forbid()); } if (await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).CountAsync() < 4) { return(Forbid()); } eventID = EventID; OfficialMatch = await _context.OfficialMatch.FirstOrDefaultAsync(m => m.ID == OfficialMatchID); AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).OrderBy(t => t.TeamNumber.PadLeft(5)).ToListAsync(); if (OfficialMatch == null) { return(NotFound()); } return(Page()); }
public async Task <ActionResult> OnGetDelete(string EventID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } Event Event = await _context.Event.FindAsync(EventID); if (Event != null) { List <Team> RemovedTeams = await _context.Team.Where(t => t.EventID == EventID).ToListAsync(); List <OfficialMatch> RemovedOfficialMatches = await _context.OfficialMatch.Where(t => t.EventID == EventID).ToListAsync(); _context.Team.RemoveRange(RemovedTeams); _context.OfficialMatch.RemoveRange(RemovedOfficialMatches); _context.Event.Remove(Event); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string EventID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } if (!ModelState.IsValid) { return(Page()); } OfficialMatch.EventID = EventID; _context.OfficialMatch.Add(OfficialMatch); IList <Models.OfficialMatch> AuthorizedOfficialMatches = await _context.OfficialMatch.Where(s => s.EventID == EventID).ToListAsync(); AuthorizedOfficialMatches.Add(OfficialMatch); AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).ToListAsync(); IList <Team> TeamsWithScores = CalculateTeamMetrics.CalculateAllMetrics(AuthorizedTeams, AuthorizedOfficialMatches); _context.Team.UpdateRange(TeamsWithScores); await _context.SaveChangesAsync(); var _EventID = EventID; return(RedirectToPage("./Index", new { EventID = _EventID, })); }
public async Task <ActionResult> OnGetAsync(string EventID, string TeamID) { if (EventID == null || TeamID == null) { return(NotFound()); } if (!AuthorizationCheck.Team(_context, TeamID, User.Identity.Name)) { return(Forbid()); } eventID = EventID; teamID = TeamID; AuthorizedScoutedMatches = _context.ScoutedMatch.AsNoTracking().Where(s => s.TeamID == TeamID); QualificationScoutedMatches = await AuthorizedScoutedMatches.Where(s => s.MatchType == MatchType.Qualification).ToListAsync(); SemifinalsScoutedMatches = await AuthorizedScoutedMatches.Where(s => s.MatchType == MatchType.Semifinal).ToListAsync(); FinalsScoutedMatches = await AuthorizedScoutedMatches.Where(s => s.MatchType == MatchType.Final).ToListAsync(); PracticeScoutedMatches = await AuthorizedScoutedMatches.Where(s => s.MatchType == MatchType.Practice).ToListAsync(); NumberOfScoutedMatches = await AuthorizedScoutedMatches.CountAsync(); if (NumberOfScoutedMatches != 0) { HighestScore = await AuthorizedScoutedMatches.MaxAsync(s => s.Score); AverageScore = Math.Round(await AuthorizedScoutedMatches.AverageAsync(s => s.Score), 2); NumberOfPenalties = await AuthorizedScoutedMatches.SumAsync(s => s.MinorPenalties + s.MajorPenalties); } return(Page()); }
public async Task <ActionResult> OnGetDelete(string EventID, string OfficialMatchID) { if (EventID == null || OfficialMatchID == null) { return(NotFound()); } if (!AuthorizationCheck.OfficialMatch(_context, OfficialMatchID, User.Identity.Name)) { return(Forbid()); } OfficialMatch OfficialMatch = await _context.OfficialMatch.FindAsync(OfficialMatchID); IList <OfficialMatch> AuthorizedOfficialMatches = await _context.OfficialMatch.Where(s => s.EventID == EventID).ToListAsync(); AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).ToListAsync(); IList <Team> TeamsWithScores = CalculateTeamMetrics.CalculateAllMetrics(AuthorizedTeams, AuthorizedOfficialMatches); _context.Team.UpdateRange(TeamsWithScores); if (OfficialMatch != null) { _context.OfficialMatch.Remove(OfficialMatch); await _context.SaveChangesAsync(); } var _EventID = EventID; return(RedirectToPage("./Index", new { EventID = _EventID, })); }
public async Task <ActionResult> OnGetDelete(string EventID, string TeamID) { if (EventID == null || TeamID == null) { return(NotFound()); } if (!AuthorizationCheck.Team(_context, TeamID, User.Identity.Name)) { return(Forbid()); } IList <OfficialMatch> RemovedOfficialMatches = await _context.OfficialMatch.Where(o => o.Red1TeamID == TeamID || o.Red2TeamID == TeamID || o.Blue1TeamID == TeamID || o.Blue2TeamID == TeamID).ToListAsync(); IList <ScoutedMatch> RemovedScoutedMatches = await _context.ScoutedMatch.Where(m => m.TeamID == TeamID).ToListAsync(); Team Team = await _context.Team.FindAsync(TeamID); if (Team != null) { _context.Team.Remove(Team); _context.RemoveRange(RemovedOfficialMatches); _context.RemoveRange(RemovedScoutedMatches); await _context.SaveChangesAsync(); } var _EventID = EventID; return(RedirectToPage("./Index", new { EventID = _EventID, })); }
// authorization checks on queries //////////////////////////////// //public virtual void ConfigureQuery(ListQueryParameterObject query) //{ // AuthorizationCheck authCheck = query.AuthCheck; // authCheck.PermissionChecks.Clear(); // if (AuthCheckExecuted) // { // Authentication currentAuthentication = CurrentAuthentication; // authCheck.AuthUserId = currentAuthentication.UserId; // authCheck.AuthGroupIds = currentAuthentication.GroupIds; // EnableQueryAuthCheck(authCheck); // } // else // { // authCheck.AuthorizationCheckEnabled = false; // authCheck.AuthUserId = null; // authCheck.AuthGroupIds = null; // } //} public virtual void EnableQueryAuthCheck(AuthorizationCheck authCheck) { IList <string> authGroupIds = authCheck.AuthGroupIds; string authUserId = authCheck.AuthUserId; authCheck.AuthorizationCheckEnabled = true; authCheck.AuthGroupIds = FilterAuthenticatedGroupIds(authGroupIds); authCheck.RevokeAuthorizationCheckEnabled = IsRevokeAuthCheckEnabled(authUserId, authGroupIds) ?? false; }
//protected internal override void ConfigureQuery(ListQueryParameterObject query, Resources resource) //{ // ConfigureQuery(query, resource, "RES.ID_"); //} //public virtual void ConfigureQuery(ListQueryParameterObject query, Resources resource, string queryParam) //{ // ConfigureQuery(query, resource, queryParam, Permissions.Read); //} //public virtual void ConfigureQuery(ListQueryParameterObject query, Resources resource, string queryParam, Permissions permission) //{ // ConfigureQuery(query); // AddPermissionCheck(query, resource, queryParam, permission); //} //protected internal virtual void AddPermissionCheck(ListQueryParameterObject query,Resources resource, string queryParam, Permissions permission) //{ // CommandContext commandContext = CommandContext; // if (AuthorizationEnabled && CurrentAuthentication != null && commandContext.AuthorizationCheckEnabled) // { // PermissionCheck permCheck = NewPermissionCheck(); // permCheck.Resource = resource; // permCheck.ResourceIdQueryParam = queryParam; // permCheck.Permission = permission; // query.AuthCheck.AddAtomicPermissionCheck(permCheck); // } //} protected internal virtual void AddPermissionCheck(AuthorizationCheck authCheck, CompositePermissionCheck compositeCheck) { CommandContext commandContext = CommandContext; if (AuthorizationEnabled && CurrentAuthentication != null && commandContext.AuthorizationCheckEnabled) { authCheck.PermissionChecks = compositeCheck; } }
/// <summary> /// Returns whether the SiteMapNode is accessible to the current user. /// </summary> public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node) { // We are checking Rights, and other custom attributes here. // Roles may also be part of the SiteMapNode. Let the base class // check for that. If false, return false, otherwise, continue // with our checks. if (!base.IsAccessibleToUser(context, node)) { return(false); } bool primaryBlogInstanceOnly; if (!string.IsNullOrWhiteSpace(node["primaryBlogInstanceOnly"]) && bool.TryParse(node["primaryBlogInstanceOnly"], out primaryBlogInstanceOnly)) { if (primaryBlogInstanceOnly && !Blog.CurrentInstance.IsPrimary) { return(false); } } if (!Utils.StringIsNullOrWhitespace(node["rights"])) { // By default, all specified Rights must exist. // We allow this to be overridden via the "rightsAuthorizationCheck" // attribute. AuthorizationCheck authCheck = AuthorizationCheck.HasAll; if (!Utils.StringIsNullOrWhitespace(node["rightsAuthorizationCheck"])) { authCheck = Utils.ParseEnum <AuthorizationCheck>(node["rightsAuthorizationCheck"], AuthorizationCheck.HasAll); } string[] rightsRaw = node["rights"].Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); List <Rights> rightsToCheck = new List <Rights>(); foreach (string r in rightsRaw) { Rights right = Utils.ParseEnum <Rights>(r.Trim(), Rights.None); if (right != Rights.None) { rightsToCheck.Add(right); } } if (rightsToCheck.Count > 0) { return(Security.IsAuthorizedTo(authCheck, rightsToCheck.ToArray())); } } return(true); }
/// <summary> /// If the current user does not have the requested rights, either redirects to the login page, /// or throws a SecurityException. /// </summary> /// <param name="authCheck"></param> /// <param name="redirectIfUnauthorized"> /// If true and user does not have rights, redirects to the login page or homepage. /// If false and user does not have rights, throws a security exception. /// </param> /// <param name="rights"></param> public static void DemandUserHasRight(AuthorizationCheck authCheck, bool redirectIfUnauthorized, params Rights[] rights) { if (!IsAuthorizedTo(authCheck, rights)) { if (redirectIfUnauthorized) { RedirectForUnauthorizedRequest(); } else { throw new SecurityException("User doesn't have the right to perform this"); } } }
public IActionResult OnGet(string EventID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } eventID = EventID; return(Page()); }
public async Task <IActionResult> OnPostAsync(string EventID, string TeamID, string ScoutedMatchID) { if (!ModelState.IsValid) { return(Page()); } if (EventID == null || TeamID == null || ScoutedMatchID == null) { return(NotFound()); } if (!AuthorizationCheck.ScoutedMatch(_context, ScoutedMatchID, User.Identity.Name)) { return(Forbid()); } _context.Attach(ScoutedMatch).State = EntityState.Modified; eventID = EventID; teamID = TeamID; ScoutedMatch.TeamID = TeamID; ScoutedMatch.Score = CalculateTeamMetrics.ComputeScoutedMatchScore(ScoutedMatch); Team ScoutedTeam = await _context.Team.FindAsync(TeamID); try { await _context.SaveChangesAsync(); IList <int> Scores = await _context.ScoutedMatch.AsNoTracking().Where(s => s.TeamID == TeamID).Select(s => s.Score).ToListAsync(); ScoutedTeam.AvgPTS = Math.Round(Scores.Average(), 1); _context.Team.Update(ScoutedTeam); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ScoutedMatchExists(ScoutedMatch.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index", new { EventID = eventID, TeamID = teamID, })); }
public virtual bool IsAuthorized(string userId, IList <string> groupIds, IList <PermissionCheck> permissionChecks) { if (!AuthorizationEnabled) { return(true); } IList <string> filteredGroupIds = FilterAuthenticatedGroupIds(groupIds); bool isRevokeAuthorizationCheckEnabled = IsRevokeAuthCheckEnabled(userId, groupIds) ?? false; AuthorizationCheck authCheck = new AuthorizationCheck(userId, filteredGroupIds, permissionChecks, isRevokeAuthorizationCheckEnabled); //return DbEntityManager.SelectBoolean("isUserAuthorizedForResource", authCheck); throw new NotImplementedException(); }
public virtual bool isAuthorized(string userId, IList <string> groupIds, CompositePermissionCheck compositePermissionCheck) { foreach (PermissionCheck permissionCheck in compositePermissionCheck.AllPermissionChecks) { if (!isResourceValidForPermission(permissionCheck)) { throw LOG.invalidResourceForPermission(permissionCheck.Resource.resourceName(), permissionCheck.Permission.Name); } } IList <string> filteredGroupIds = filterAuthenticatedGroupIds(groupIds); bool isRevokeAuthorizationCheckEnabled = isRevokeAuthCheckEnabled(userId, groupIds); AuthorizationCheck authCheck = new AuthorizationCheck(userId, filteredGroupIds, compositePermissionCheck, isRevokeAuthorizationCheckEnabled); return(DbEntityManager.selectBoolean("isUserAuthorizedForResource", authCheck)); }
public Void execute(CommandContext commandContext) { AuthorizationManager authorizationManager = outerInstance.spyOnSession(commandContext, typeof(AuthorizationManager)); TaskQueryImpl taskQuery = (TaskQueryImpl)spy(outerInstance.processEngine.TaskService.createTaskQuery()); AuthorizationCheck authCheck = spy(new AuthorizationCheck()); when(taskQuery.AuthCheck).thenReturn(authCheck); taskQuery.list(); verify(authorizationManager, atLeastOnce()).filterAuthenticatedGroupIds(eq(testGroupIds)); verify(authCheck, atLeastOnce()).AuthGroupIds = (IList <string>)argThat(containsInAnyOrder(testGroupIds.ToArray())); return(null); }
public Void execute(CommandContext commandContext) { AuthorizationManager authorizationManager = outerInstance.spyOnSession(commandContext, typeof(AuthorizationManager)); TaskQueryImpl taskQuery = (TaskQueryImpl)spy(outerInstance.processEngine.TaskService.createTaskQuery()); AuthorizationCheck authCheck = spy(new AuthorizationCheck()); when(taskQuery.AuthCheck).thenReturn(authCheck); taskQuery.list(); verify(authorizationManager, atLeastOnce()).filterAuthenticatedGroupIds(eq(testGroupIds)); verify(authCheck).AuthGroupIds = eq(System.Linq.Enumerable.Empty <string>()); return(null); }
/// <summary> /// Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck. /// </summary> /// <param name="authCheck"></param> /// <param name="rights"></param> /// <returns></returns> public static bool IsAuthorizedTo(AuthorizationCheck authCheck, IEnumerable <Rights> rights) { if (rights.Count() == 0) { // Always return false for this. If there's a mistake where authorization // is being checked for on an empty collection, we don't want to return // true. return(false); } else { var roles = Security.GetCurrentUserRoles(); if (authCheck == AuthorizationCheck.HasAny) { foreach (var right in rights) { if (Right.HasRight(right, roles)) { return(true); } } return(false); } else if (authCheck == AuthorizationCheck.HasAll) { bool authCheckPassed = true; foreach (var right in rights) { if (!Right.HasRight(right, roles)) { authCheckPassed = false; break; } } return(authCheckPassed); } else { throw new NotSupportedException(); } } }
public Void execute(CommandContext commandContext) { AuthorizationManager authorizationManager = outerInstance.spyOnSession(commandContext, typeof(AuthorizationManager)); DbEntityManager dbEntityManager = outerInstance.spyOnSession(commandContext, typeof(DbEntityManager)); outerInstance.authorizationService.isUserAuthorized(testUserId, null, Permissions.READ, Resources.TASK); verify(authorizationManager, atLeastOnce()).filterAuthenticatedGroupIds(eq((IList <string>)null)); ArgumentCaptor <AuthorizationCheck> authorizationCheckArgument = ArgumentCaptor.forClass(typeof(AuthorizationCheck)); verify(dbEntityManager).selectBoolean(eq("isUserAuthorizedForResource"), authorizationCheckArgument.capture()); AuthorizationCheck authorizationCheck = authorizationCheckArgument.Value; assertTrue(authorizationCheck.AuthGroupIds.Count == 0); return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUseCfgValue_always() public virtual void shouldUseCfgValue_always() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.ListQueryParameterObject query = new org.camunda.bpm.engine.impl.db.ListQueryParameterObject(); ListQueryParameterObject query = new ListQueryParameterObject(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.camunda.bpm.engine.impl.db.AuthorizationCheck authCheck = query.getAuthCheck(); AuthorizationCheck authCheck = query.AuthCheck; // given when(mockedConfiguration.AuthorizationCheckRevokes).thenReturn(ProcessEngineConfiguration.AUTHORIZATION_CHECK_REVOKE_ALWAYS); // if authorizationManager.configureQuery(query); // then assertEquals(true, authCheck.RevokeAuthorizationCheckEnabled); verifyNoMoreInteractions(mockedEntityManager); }
// authorization checks on queries //////////////////////////////// public virtual void configureQuery(ListQueryParameterObject query) { AuthorizationCheck authCheck = query.AuthCheck; authCheck.PermissionChecks.clear(); if (AuthCheckExecuted) { Authentication currentAuthentication = CurrentAuthentication; authCheck.AuthUserId = currentAuthentication.UserId; authCheck.AuthGroupIds = currentAuthentication.GroupIds; enableQueryAuthCheck(authCheck); } else { authCheck.AuthorizationCheckEnabled = false; authCheck.AuthUserId = null; authCheck.AuthGroupIds = null; } }
public async Task <IActionResult> OnGetAsync(string EventID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } if (await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).CountAsync() < 4) { return(Forbid()); } eventID = EventID; AuthorizedTeams = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).AsQueryable <Team>().OrderBy(s => s.TeamNumber.PadLeft(5)).ToListAsync(); return(Page()); }
public async Task <ActionResult> OnGetAsync(string EventID) { if (EventID == null) { return(NotFound()); } if (!AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } eventID = EventID; await GetAndSeparateData(EventID); int BestRedScore = AuthorizedOfficialMatches.Max(m => m.RedScore).GetValueOrDefault(); int BestBlueScore = AuthorizedOfficialMatches.Max(m => m.BlueScore).GetValueOrDefault(); BestScore = System.Math.Max(BestRedScore, BestBlueScore); TeamCount = await _context.Team.AsNoTracking().Where(t => t.EventID == EventID).CountAsync(); try { int ScoresSum = 0; foreach (var Match in AuthorizedOfficialMatches) { ScoresSum += Match.RedScore.GetValueOrDefault(); ScoresSum += Match.BlueScore.GetValueOrDefault(); } AverageScore = ScoresSum / (AuthorizedOfficialMatches.Count() * 2); AverageScore = System.Math.Round(AverageScore, 2); MatchesPerTeam = AuthorizedOfficialMatches.Count() * 4 / AuthorizedTeams.Count; MatchesPerTeam = System.Math.Round(MatchesPerTeam, 2); } catch { AverageScore = 0; MatchesPerTeam = 0; } return(Page()); }
public async Task <IActionResult> OnGetAsync(string EventID, string TeamID) { if (EventID == null || TeamID == null) { return(NotFound()); } if (!AuthorizationCheck.Team(_context, TeamID, User.Identity.Name)) { return(Forbid()); } teamID = TeamID; eventID = EventID; Team = await _context.Team.FirstOrDefaultAsync(m => m.ID == TeamID); if (Team == null) { return(NotFound()); } return(Page()); }
public async Task <ActionResult> OnGetAsync() { if (!User.Identity.IsAuthenticated) { return(Forbid()); } AllEvents = await _context.Event.AsNoTracking().ToListAsync(); AuthorizedEvents = new List <Event>(); foreach (var Event in AllEvents) { if (AuthorizationCheck.Event(_context, Event.ID, User.Identity.Name)) { AuthorizedEvents.Add(Event); } } CurrentEvents = AuthorizedEvents.Where(e => e.StartDate <= DateTime.Today && e.EndDate >= DateTime.Today).ToList(); UpcomingEvents = AuthorizedEvents.Where(e => e.StartDate > DateTime.Today).ToList(); PastEvents = AuthorizedEvents.Where(e => e.EndDate < DateTime.Today).ToList(); return(Page()); }
// process definition query //////////////////////////////// public virtual void configureProcessDefinitionQuery(ProcessDefinitionQueryImpl query) { configureQuery(query, PROCESS_DEFINITION, "RES.KEY_"); if (query.StartablePermissionCheck) { AuthorizationCheck authorizationCheck = query.AuthCheck; if (!authorizationCheck.RevokeAuthorizationCheckEnabled) { CompositePermissionCheck permCheck = (new PermissionCheckBuilder()).atomicCheck(PROCESS_DEFINITION, "RES.KEY_", Permissions.CREATE_INSTANCE).build(); query.addProcessDefinitionCreatePermissionCheck(permCheck); } else { CompositePermissionCheck permissionCheck = (new PermissionCheckBuilder()).conjunctive().atomicCheck(PROCESS_DEFINITION, "RES.KEY_", READ).atomicCheck(PROCESS_DEFINITION, "RES.KEY_", Permissions.CREATE_INSTANCE).build(); addPermissionCheck(authorizationCheck, permissionCheck); } } }
public async Task <IActionResult> OnGetAsync(string EventID) { // Authorization checks if (!User.Identity.IsAuthenticated || !AuthorizationCheck.Event(_context, EventID, User.Identity.Name)) { return(Forbid()); } if (EventID == null) { return(NotFound()); } Event = await _context.Event.FirstOrDefaultAsync(m => m.ID == EventID); if (Event == null) { return(NotFound()); } return(Page()); }
/// <summary> /// Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck. /// </summary> /// <param name="authCheck"></param> /// <param name="rights"></param> /// <returns></returns> public static bool IsAuthorizedTo(AuthorizationCheck authCheck, IEnumerable<Rights> rights) { if (rights.Count() == 0) { // Always return false for this. If there's a mistake where authorization // is being checked for on an empty collection, we don't want to return // true. return false; } else { var roles = Security.GetCurrentUserRoles(); if (authCheck == AuthorizationCheck.HasAny) { foreach (var right in rights) { if (Right.HasRight(right, roles)) { return true; } } return false; } else if (authCheck == AuthorizationCheck.HasAll) { bool authCheckPassed = true; foreach (var right in rights) { if (!Right.HasRight(right, roles)) { authCheckPassed = false; break; } } return authCheckPassed; } else { throw new NotSupportedException(); } } }
/// <summary> /// Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck. /// </summary> /// <param name="authCheck"></param> /// <param name="rights"></param> /// <returns></returns> public static bool IsAuthorizedTo(AuthorizationCheck authCheck, params Rights[] rights) { return IsAuthorizedTo(authCheck, rights.ToList()); }