001/* 002 * Copyright 2018 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.userdirectory.rights; 017 018import java.util.Collections; 019import java.util.HashMap; 020import java.util.Map; 021import java.util.Set; 022 023import org.ametys.core.group.GroupIdentity; 024import org.ametys.core.right.AccessController; 025import org.ametys.core.user.UserIdentity; 026import org.ametys.plugins.frontedition.AmetysFrontEditionHelper; 027import org.ametys.plugins.userdirectory.page.UserPage; 028 029/** 030 * This controller will grant the right "Front_Edition_Access_Right" on the {@link UserPage} to any connected user 031 */ 032public class EditionFOAccessController implements AccessController 033{ 034 public AccessResult getPermission(UserIdentity user, Set<GroupIdentity> userGroups, String rightId, Object object) 035 { 036 if (AmetysFrontEditionHelper.FRONT_EDITION_RIGHT_ID.equals(rightId) && object instanceof UserPage) 037 { 038 return AccessResult.USER_ALLOWED; 039 } 040 else 041 { 042 return AccessResult.UNKNOWN; 043 } 044 } 045 046 public AccessResult getReadAccessPermission(UserIdentity user, Set<GroupIdentity> userGroups, Object object) 047 { 048 return AccessResult.UNKNOWN; 049 } 050 051 public Map<String, AccessResult> getPermissionByRight(UserIdentity user, Set<GroupIdentity> userGroups, Object object) 052 { 053 AccessResult accessResult = getPermission(user, userGroups, AmetysFrontEditionHelper.FRONT_EDITION_RIGHT_ID, object); 054 if (accessResult == AccessResult.UNKNOWN) 055 { 056 return Collections.EMPTY_MAP; 057 } 058 else 059 { 060 Map<String, AccessResult> permissions = new HashMap<>(); 061 permissions.put(AmetysFrontEditionHelper.FRONT_EDITION_RIGHT_ID, accessResult); 062 return permissions; 063 } 064 } 065 066 public AccessResult getPermissionForAnonymous(String rightId, Object object) 067 { 068 return AccessResult.UNKNOWN; 069 } 070 071 public AccessResult getReadAccessPermissionForAnonymous(Object object) 072 { 073 return AccessResult.UNKNOWN; 074 } 075 076 public AccessResult getPermissionForAnyConnectedUser(String rightId, Object object) 077 { 078 if (AmetysFrontEditionHelper.FRONT_EDITION_RIGHT_ID.equals(rightId) && object instanceof UserPage) 079 { 080 return AccessResult.ANY_CONNECTED_ALLOWED; 081 } 082 else 083 { 084 return AccessResult.UNKNOWN; 085 } 086 } 087 088 public AccessResult getReadAccessPermissionForAnyConnectedUser(Object object) 089 { 090 return AccessResult.UNKNOWN; 091 } 092 093 public Map<UserIdentity, AccessResult> getPermissionByUser(String rightId, Object object) 094 { 095 return Collections.EMPTY_MAP; 096 } 097 098 public Map<UserIdentity, AccessResult> getReadAccessPermissionByUser(Object object) 099 { 100 return Collections.EMPTY_MAP; 101 } 102 103 public Map<GroupIdentity, AccessResult> getPermissionByGroup(String rightId, Object object) 104 { 105 return Collections.EMPTY_MAP; 106 } 107 108 public Map<GroupIdentity, AccessResult> getReadAccessPermissionByGroup(Object object) 109 { 110 return Collections.EMPTY_MAP; 111 } 112 113 public boolean hasUserAnyPermissionOnWorkspace(Set<Object> workspacesContexts, UserIdentity user, Set<GroupIdentity> userGroups, String rightId) 114 { 115 // We do not want that this accesscontroller give access to the backoffice (even if #isSupported would not match in this case) 116 return false; 117 } 118 119 public boolean hasUserAnyReadAccessPermissionOnWorkspace(Set<Object> workspacesContexts, UserIdentity user, Set<GroupIdentity> userGroups) 120 { 121 return false; 122 } 123 124 public boolean hasAnonymousAnyPermissionOnWorkspace(Set<Object> workspacesContexts, String rightId) 125 { 126 // We do not want that this accesscontroller give access to the backoffice (even if #isSupported would not match in this case) 127 return false; 128 } 129 130 public boolean hasAnonymousAnyReadAccessPermissionOnWorkspace(Set<Object> workspacesContexts) 131 { 132 return false; 133 } 134 135 public boolean hasAnyConnectedUserAnyPermissionOnWorkspace(Set<Object> workspacesContexts, String rightId) 136 { 137 // We do not want that this accesscontroller give access to the backoffice (even if #isSupported would not match in this case) 138 return false; 139 } 140 141 public boolean hasAnyConnectedUserAnyReadAccessPermissionOnWorkspace(Set<Object> workspacesContexts) 142 { 143 return false; 144 } 145 146 public boolean isSupported(Object object) 147 { 148 return object instanceof UserPage; 149 } 150 151}