コード例 #1
0
ファイル: Utils.java プロジェクト: canhpv/ecms
 /**
  * Can edit current portal.
  *
  * @param remoteUser the remote user
  * @return true, if successful
  * @throws Exception the exception
  */
 public static boolean canEditCurrentPortal(String remoteUser) throws Exception {
   if (remoteUser == null) return false;
   IdentityRegistry identityRegistry =
       Util.getUIPortalApplication().getApplicationComponent(IdentityRegistry.class);
   Identity identity = identityRegistry.getIdentity(remoteUser);
   if (identity == null) return false;
   UIPortal uiPortal = Util.getUIPortal();
   // this code only work for single edit permission
   String editPermission = uiPortal.getEditPermission();
   MembershipEntry membershipEntry = MembershipEntry.parse(editPermission);
   return identity.isMemberOf(membershipEntry);
 }
コード例 #2
0
 private boolean hasPermission(String userName, Value[] roles) throws Exception {
   IdentityRegistry identityRegistry = getApplicationComponent(IdentityRegistry.class);
   if (IdentityConstants.SYSTEM.equalsIgnoreCase(userName)) {
     return true;
   }
   Identity identity = identityRegistry.getIdentity(userName);
   if (identity == null) {
     return false;
   }
   for (int i = 0; i < roles.length; i++) {
     String role = roles[i].getString();
     if ("*".equalsIgnoreCase(role)) return true;
     MembershipEntry membershipEntry = MembershipEntry.parse(role);
     if (membershipEntry == null) return false;
     if (identity.isMemberOf(membershipEntry)) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
 public boolean hasPermission(Identity identity, String expPerm) {
   String currentUser = identity.getUserId();
   if (superUser_.equals(currentUser)) {
     return true;
   }
   if (expPerm == null) {
     return false;
   }
   if (EVERYONE.equals(expPerm)) {
     return true;
   }
   Permission permission = new Permission();
   permission.setPermissionExpression(expPerm);
   String groupId = permission.getGroupId();
   if ((currentUser == null || currentUser.equals(IdentityConstants.ANONIM))
       && groupId.equals(guestGroup_)) {
     return true;
   }
   String membership = permission.getMembership();
   return identity.isMemberOf(groupId, membership);
 }