@Override
 public List<String> getDefaultRoles() {
   if (applicationData.getDefaultRoles() != null) {
     return Arrays.asList(applicationData.getDefaultRoles());
   } else {
     return Collections.emptyList();
   }
 }
  @Override
  public void addDefaultRole(String name) {
    if (getRole(name) == null) {
      addRole(name);
    }

    String[] defaultRoles = applicationData.getDefaultRoles();
    if (defaultRoles == null) {
      defaultRoles = new String[1];
    } else {
      defaultRoles = Arrays.copyOf(defaultRoles, defaultRoles.length + 1);
    }
    defaultRoles[defaultRoles.length - 1] = name;

    applicationData.setDefaultRoles(defaultRoles);
    updateApplication();
  }
  @Override
  public void updateDefaultRoles(String[] defaultRoles) {
    for (String name : defaultRoles) {
      if (getRole(name) == null) {
        addRole(name);
      }
    }

    applicationData.setDefaultRoles(defaultRoles);
    updateApplication();
  }
 @Override
 public List<RoleModel> getRoleMappings(UserModel user) {
   RelationshipQuery<Grant> query = getRelationshipManager().createRelationshipQuery(Grant.class);
   query.setParameter(Grant.ASSIGNEE, ((UserAdapter) user).getUser());
   List<Grant> grants = query.getResultList();
   List<RoleModel> set = new ArrayList<RoleModel>();
   for (Grant grant : grants) {
     if (grant.getRole().getPartition().getId().equals(applicationData.getId()))
       set.add(new RoleAdapter(grant.getRole(), getIdm()));
   }
   return set;
 }
 @Override
 public Set<String> getRoleMappingValues(UserModel user) {
   RelationshipQuery<Grant> query = getRelationshipManager().createRelationshipQuery(Grant.class);
   query.setParameter(Grant.ASSIGNEE, ((UserAdapter) user).getUser());
   List<Grant> grants = query.getResultList();
   HashSet<String> set = new HashSet<String>();
   for (Grant grant : grants) {
     if (grant.getRole().getPartition().getId().equals(applicationData.getId()))
       set.add(grant.getRole().getName());
   }
   return set;
 }
 @Override
 public List<RoleModel> getScopeMappings(UserModel agent) {
   RelationshipQuery<ScopeRelationship> query =
       getRelationshipManager().createRelationshipQuery(ScopeRelationship.class);
   query.setParameter(ScopeRelationship.CLIENT, ((UserAdapter) agent).getUser());
   List<ScopeRelationship> scope = query.getResultList();
   List<RoleModel> roles = new ArrayList<RoleModel>();
   for (ScopeRelationship rel : scope) {
     if (rel.getScope().getPartition().getId().equals(applicationData.getId()))
       roles.add(new RoleAdapter(rel.getScope(), getIdm()));
   }
   return roles;
 }
 @Override
 public Set<String> getScopeMappingValues(UserModel agent) {
   RelationshipQuery<ScopeRelationship> query =
       getRelationshipManager().createRelationshipQuery(ScopeRelationship.class);
   query.setParameter(ScopeRelationship.CLIENT, ((UserAdapter) agent).getUser());
   List<ScopeRelationship> scope = query.getResultList();
   HashSet<String> set = new HashSet<String>();
   for (ScopeRelationship rel : scope) {
     if (rel.getScope().getPartition().getId().equals(applicationData.getId()))
       set.add(rel.getScope().getName());
   }
   return set;
 }
 @Override
 public boolean isSurrogateAuthRequired() {
   return applicationData.isSurrogateAuthRequired();
 }
 @Override
 public void setEnabled(boolean enabled) {
   applicationData.setEnabled(enabled);
   updateApplication();
 }
 @Override
 public boolean isEnabled() {
   return applicationData.isEnabled();
 }
 @Override
 public void setName(String name) {
   applicationData.setResourceName(name);
   updateApplication();
 }
 @Override
 public String getName() {
   return applicationData.getResourceName();
 }
 @Override
 public String getId() {
   // for some reason picketlink queries by name when finding partition, don't know what ID is used
   // for now
   return applicationData.getName();
 }
 @Override
 public UserAdapter getApplicationUser() {
   return new UserAdapter(applicationData.getResourceUser(), realm.getIdm());
 }
 @Override
 public String getBaseUrl() {
   return applicationData.getBaseUrl();
 }
 @Override
 public void setSurrogateAuthRequired(boolean surrogateAuthRequired) {
   applicationData.setSurrogateAuthRequired(surrogateAuthRequired);
   updateApplication();
 }
 @Override
 public void setBaseUrl(String url) {
   applicationData.setBaseUrl(url);
   updateApplication();
 }
 @Override
 public String getManagementUrl() {
   return applicationData.getManagementUrl();
 }
 @Override
 public void setManagementUrl(String url) {
   applicationData.setManagementUrl(url);
   updateApplication();
 }