public List<JetspeedPrincipal> getAssociatedFrom(String principalFromName, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName){ Long defaultDomainId = getDefaultSecurityDomainId(); return getAssociatedFrom(principalFromName, from, to, associationName, defaultDomainId, defaultDomainId); } //
public List<String> getAssociatedNamesFrom(Long principalFromId, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName){ Long defaultDomainId = getDefaultSecurityDomainId(); return getAssociatedNamesFrom(principalFromId, from, to, associationName, defaultDomainId, defaultDomainId); }
public List<String> getAssociatedNamesTo(String principalToName, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName){ Long defaultDomainId = getDefaultSecurityDomainId(); return getAssociatedNamesTo(principalToName, from, to, associationName, defaultDomainId, defaultDomainId); }
public void revokeAllPermissions(JetspeedPrincipal principal) throws SecurityException { Long principalId = null; Criteria criteria = new Criteria(); if (principal.isTransient() || principal.getId() == null) { Long securityDomain = ((principal.getDomainId() != null) ? principal.getDomainId() : getDefaultSecurityDomainId()); principalId = getPrincipalId(principal.getName(), principal.getType().getName(), securityDomain); } else { principalId = principal.getId(); } criteria.addEqualTo("principalId", principalId); Query query = QueryFactory.newQuery(JetspeedPrincipalPermission.class,criteria); try { getPersistenceBrokerTemplate().deleteByQuery(query); // evict from principal cache to notify jspmCache.evictPrincipal(principalId); } catch (Exception pbe) { KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager", "revokeAllPermissions", pbe.getMessage()); logger.error(msg, pbe); throw new SecurityException(msg, pbe); } }
associatedTo = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query)); Long principalToId = getPrincipalId(principalToName, to.getName(), toSecurityDomain); jspmCache.putAssociationQuery(cacheKey, principalToId, extractPrincipalIds(associatedTo), fromSecurityDomain, toSecurityDomain, new ArrayList<JetspeedPrincipal>(associatedTo));
public List<JetspeedPrincipal> getPrincipals(String nameFilter, JetspeedPrincipalType type) { return getPrincipals(nameFilter, type, getDefaultSecurityDomainId()); }
public void addDomain(SecurityDomain domain) throws SecurityException { if (domainExists(domain)) { throw new SecurityException(SecurityException.SECURITY_DOMAIN_EXISTS.create(domain.getName())); } try { getPersistenceBrokerTemplate().store(domain); // evict from and put in cache to notify jspmCache.evictDomain(domain.getDomainId()); jspmCache.putDomain(domain.getDomainId(), domain); } catch (Exception pbe) { KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager", "addDomain", pbe.getMessage()); logger.error(msg, pbe); throw new SecurityException(msg, pbe); } }
@SuppressWarnings("unchecked") public List<JetspeedPrincipal> getAssociatedFrom(Long principalFromId, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName, Long fromSecurityDomain, Long toSecurityDomain) { Criteria criteria = new Criteria(); criteria.addEqualTo("associationsTo.associationName", associationName); criteria.addEqualTo("associationsTo.from.id", principalFromId); criteria.addEqualTo("associationsTo.from.type", from.getName()); criteria.addEqualTo("type", to.getName()); criteria.addEqualTo("associationsTo.from.domainId", fromSecurityDomain); criteria.addEqualTo("domainId", toSecurityDomain); // check cache String cacheKey = "getAssociatedFrom:"+criteria; List<JetspeedPrincipal> associatedFrom = (List<JetspeedPrincipal>)jspmCache.getAssociationQuery(cacheKey); if (associatedFrom != null) { return new ArrayList<JetspeedPrincipal>(associatedFrom); } // perform query Query query = QueryFactory.newQuery(PersistentJetspeedPrincipal.class, criteria); associatedFrom = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query)); // put result in cache jspmCache.putAssociationQuery(cacheKey, principalFromId, extractPrincipalIds(associatedFrom), fromSecurityDomain, toSecurityDomain, new ArrayList<JetspeedPrincipal>(associatedFrom)); // return result return associatedFrom; }
public void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference> associations) throws SecurityException { if (principal.getDomainId() == null && principal instanceof TransientJetspeedPrincipal) { ((TransientJetspeedPrincipal)principal).setDomainId(getDefaultSecurityDomainId()); } if (principalExists(principal)) { throw new SecurityException(SecurityException.PRINCIPAL_ALREADY_EXISTS.createScoped(principal.getType().getName(), principal.getName())); } try { getPersistenceBrokerTemplate().store(principal); // evict from and put in cache to notify jspmCache.evictPrincipal(principal.getId()); jspmCache.putPrincipal(principal.getId(), principal); } catch (Exception pbe) { KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager", "addPrincipal", pbe.getMessage()); logger.error(msg, pbe); throw new SecurityException(msg, pbe); } // Note: the (optional) required associations are expected to be stored by the calling JetspeedPrincipalManager }
public List<JetspeedPrincipal> getAssociatedTo(String principalToName, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName){ Long defaultDomainId = getDefaultSecurityDomainId(); return getAssociatedTo(principalToName, from, to, associationName, defaultDomainId, defaultDomainId); }
public void grantPermissionOnlyTo(PersistentJetspeedPermission permission, String principalType, List<JetspeedPrincipal> principals) throws SecurityException { grantPermissionOnlyTo(permission, principalType, principals, getDefaultSecurityDomainId()); }
public JetspeedPrincipal getPrincipal(String principalName, JetspeedPrincipalType type) { return getPrincipal(principalName, type, getDefaultSecurityDomainId()); }
public List<String> getPrincipalNames(String nameFilter, JetspeedPrincipalType type) { return getPrincipalNames(nameFilter, type, getDefaultSecurityDomainId()); }
public List<JetspeedPrincipal> getPrincipalsByAttribute(String attributeName, String attributeValue, JetspeedPrincipalType type) { return getPrincipalsByAttribute(attributeName, attributeValue, type, getDefaultSecurityDomainId()); }
public boolean principalExists(String principalName, JetspeedPrincipalType type) { return principalExists(principalName, type, getDefaultSecurityDomainId()); }
public List<PasswordCredential> getHistoricPasswordCredentials(User user){ return getHistoricPasswordCredentials(user,getDefaultSecurityDomainId()); }
public PasswordCredential getPasswordCredential(String userName){ return getPasswordCredential(userName,getDefaultSecurityDomainId()); }
protected boolean domainExists(SecurityDomain domain){ if (domain.getDomainId() != null){ return getDomain(domain.getDomainId()) != null; } else { return getDomainByName(domain.getName()) != null; } }
protected Long getDefaultSecurityDomainId() { if (defaultSecurityDomainId == null) { SecurityDomain d = getDomainByName(SecurityDomain.DEFAULT_NAME); if (d != null) { // cache real default security domain id defaultSecurityDomainId = d.getDomainId(); } else { throw new IllegalStateException("The default security domain could not be found."); } } return defaultSecurityDomainId; }
if (principal.isTransient() || principal.getId() == null) Long securityDomain = ((principal.getDomainId() != null) ? principal.getDomainId() : getDefaultSecurityDomainId()); principalId = getPrincipalId(principal.getName(), principal.getType().getName(), securityDomain); criteria.addEqualTo("name", permission.getName()); Query query = QueryFactory.newQuery(PersistentJetspeedPermissionImpl.class, criteria); PersistentJetspeedPermission p = (PersistentJetspeedPermission)getPersistenceBrokerTemplate().getObjectByQuery(query); if (p == null) try getPersistenceBrokerTemplate().deleteByQuery(query);