1 package com.sslexplorer.policyframework; 2 3 import java.util.Calendar ; 4 import java.util.List ; 5 6 import com.sslexplorer.core.UserDatabaseManager; 7 import com.sslexplorer.realms.Realm; 8 import com.sslexplorer.security.Role; 9 import com.sslexplorer.security.User; 10 11 public class DefaultPolicy extends AbstractResource implements Policy { 12 13 private int type; 14 private boolean addToFavorite = false; 15 private int attachedUsers = 0; 16 private int attachedGroups = 0; 17 18 28 public DefaultPolicy(int uniqueId, String name, String description, int type, 29 Calendar dateCreated, Calendar dateAmended, int realmID) { 30 super(realmID, PolicyConstants.POLICY_RESOURCE_TYPE, uniqueId, name, description, dateCreated, dateAmended); 31 try { 32 List <Principal> principalsGrantedPolicy = PolicyDatabaseFactory.getInstance().getPrincipalsGrantedPolicy(this, UserDatabaseManager.getInstance().getRealm(realmID)); 33 for (Principal principal : principalsGrantedPolicy) { 34 if (principal instanceof User){ 35 attachedUsers ++; 36 } 37 else if (principal instanceof Role){ 38 attachedGroups ++; 39 } 40 } 41 } catch (Exception e) { 42 e.printStackTrace(); 44 } 45 } 46 47 52 public int getType() { 53 return type; 54 } 55 56 59 public void setType(int type) { 60 this.type = type; 61 } 62 63 public boolean isAddToFavorite() { 64 return addToFavorite; 65 } 66 67 public void setAddToFavorite(boolean addToFavorite) { 68 this.addToFavorite = addToFavorite; 69 } 70 71 public int getAttachedGroups() { 72 return attachedGroups; 73 } 74 75 public int getAttachedUsers() { 76 return attachedUsers; 77 } 78 } 79 | Popular Tags |