public SecurityAttributeTypes getSecurityAttributeTypes() { return jp.getType().getAttributeTypes(); }
/** * <p> * Given a subject, finds all principals of the given JetspeedPrincipalType(JPT) for that subject. If no principals * of the given class is not found, null is returned. * </p> * * @param subject The subject supplying the principals. * @param jptName the name of the Jetspeed Principal Type * @return A List of all principals of type JetspeedPrincipal matching a JPT name parameter. */ public static List<JetspeedPrincipal> getPrincipals(Subject subject, String jptName) { List<JetspeedPrincipal> result = new LinkedList<JetspeedPrincipal>(); Iterator<Principal> principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { Principal p = principals.next(); if (p instanceof JetspeedPrincipal) { JetspeedPrincipal jp = (JetspeedPrincipal)p; if (jp.getType().getName().equals(jptName)) { result.add(jp); } } } return result; } /**
public boolean isDefinedAttribute(String name) { return jp.getType().getAttributeTypes().getAttributeTypeMap().containsKey(name); }
protected void processFound(List<JetspeedPrincipal> found, User user, Set<Long> resolvedIds, Set<Principal> principals, Map<String, UserSubjectPrincipalsResolver> resolvers) { for (int i = found.size() -1; i > -1; i--) { JetspeedPrincipal p = found.get(i); if (!p.isEnabled() || !resolvers.containsKey(p.getType().getName()) || !resolvedIds.add(p.getId())) { found.remove(i); } } for (JetspeedPrincipal p : found) { resolvers.get(p.getType().getName()).processPrincipal(p, user, resolvedIds, principals, resolvers); } }
protected final void validatePrincipal(JetspeedPrincipal principal) { if (!principal.getType().getName().equals(principalType.getName())) { throw new IllegalArgumentException("Principal is not of type "+principalType.getName()); } if (principal.isTransient()) { throw new IllegalArgumentException("Principal is transient"); } }
public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof JetspeedPrincipal) { JetspeedPrincipal other = (JetspeedPrincipal)o; return (getName().equals(other.getName()) && getType().equals(other.getType()) && (((getDomainId() != null) ? getDomainId().longValue() : 0L) == ((other.getDomainId() != null) ? other.getDomainId().longValue() : 0L))); } return false; }
@SuppressWarnings("unchecked") public SecurityAttributesImpl(JetspeedPrincipal jp, Collection avColl, boolean readOnly, boolean extendable) { this.jp = jp; this.avColl = avColl; this.persistent = true; this.readOnly = jp.getType().getAttributeTypes().isReadOnly() ? true : readOnly; this.extendable = jp.getType().getAttributeTypes().isExtendable() ? true : extendable; Map<String, SecurityAttributeType> stMap = jp.getType().getAttributeTypes().getAttributeTypeMap(); for (Object avObj : avColl) { SecurityAttributeValue av = (SecurityAttributeValue)avObj; SecurityAttributeType sat = stMap.get(av.getName()); saMap.put(av.getName(), new SecurityAttributeImpl(sat != null ? sat : new SecurityAttributeTypeImpl(av.getName()), av, true)); } }
private Collection<? extends JetspeedPrincipal> _getSSOUsersForPrincipal(JetspeedPrincipal principal, Long remoteSecurityDomain) throws SecurityException { return domainPrincipalAccess.getAssociatedTo(principal.getName(), getPrincipalType(), principal.getType(), IsRemoteIdentityForPrincipalAssociationHandler.ASSOCIATION_NAME, remoteSecurityDomain, principal.getDomainId()); }
private JSPrincipalAssociation createJSPrincipalAssociation(String associationName, JetspeedPrincipal from, JetspeedPrincipal to) { JSPrincipalAssociation jsAssoc = new JSPrincipalAssociation(); jsAssoc.setName(associationName); jsAssoc.setFromType(from.getType().getName()); jsAssoc.setFromName(from.getName()); jsAssoc.setToType(to.getType().getName()); jsAssoc.setToName(to.getName()); return jsAssoc; }
public void addAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName) throws SecurityException { if (!SynchronizationStateAccess.isSynchronizing() && !ldapEntityManager.isReadOnly()) { SecurityEntityRelationType relationType = ldapEntityManager.getSupportedEntityRelationType(associationName, from.getType().getName(), to.getType().getName()); if (relationType != null && relationType.isCreateAllowed()) { ldapEntityManager.addRelation(from.getName(), to.getName(), relationType); } } databaseStorageManager.addAssociation(from, to, associationName); }
public void removeAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName) throws SecurityException { if (!SynchronizationStateAccess.isSynchronizing() && !ldapEntityManager.isReadOnly()) { SecurityEntityRelationType relationType = ldapEntityManager.getSupportedEntityRelationType(associationName, from.getType().getName(), to.getType().getName()); if (relationType != null && relationType.isRemoveAllowed()) { ldapEntityManager.removeRelation(from.getName(), to.getName(), relationType); } } databaseStorageManager.removeAssociation(from, to, associationName); } }
public void addAssociation(JetspeedPrincipal from, JetspeedPrincipal to, String associationName) throws SecurityException AssociationHandlerKey key = new AssociationHandlerKey(associationName, from.getType().getName(), to.getType().getName()); JetspeedPrincipalAssociationHandler jpah = assHandlers.get(key); throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_UNSUPPORTED.createScoped(from.getType().getName(), associationName, to.getType().getName())); if (pfrom == null) throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(from.getType().getName(), from.getName())); if (pto == null) throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(to.getType().getName(), to.getName()));
public void removeAttribute(String name) throws SecurityException { if (isReadOnly() && !isSynchronizing()) { throw new SecurityException(SecurityException.ATTRIBUTES_ARE_READ_ONLY.createScoped(getPrincipal().getType().getName())); } SecurityAttributeImpl sa = saMap.get(name); if (sa != null) { if (sa.isReadOnly() && !isSynchronizing()) { throw new SecurityException(SecurityException.ATTRIBUTE_IS_READ_ONLY.createScoped(getPrincipal().getType().getName(), name)); } if (sa.isRequired() && !isSynchronizing()) { throw new SecurityException(SecurityException.ATTRIBUTE_IS_REQUIRED.createScoped(getPrincipal().getType().getName(), name)); } saMap.remove(name); avColl.remove(sa.getSecurityAttributeValue()); } }
public void removePrincipal(JetspeedPrincipal principal) throws SecurityException { if (!principalExists(principal)) { throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(principal.getType().getName(), principal.getName())); } try { getPersistenceBrokerTemplate().delete(principal); // evict from cache to notify jspmCache.evictPrincipal(principal.getId()); } catch (Exception pbe) { if (pbe instanceof DataIntegrityViolationException) { logger.error(pbe.getMessage(), pbe); throw new SecurityException(SecurityException.PRINCIPAL_NOT_REMOVABLE.createScoped(principal.getType().getName(), principal.getName())); } KeyedMessage msg = SecurityException.UNEXPECTED.create("JetspeedSecurityPersistenceManager", "removePrincipal", pbe.getMessage()); logger.error(msg, pbe); throw new SecurityException(msg, pbe); } }
@SuppressWarnings("unchecked") public void beforeRemoveTo(JetspeedPrincipal to) throws SecurityException { if (associationType.isDependent()) { List<JetspeedPrincipal> fromList = (List<JetspeedPrincipal>)getManagerTo().getAssociatedTo(to.getName(), to.getType(), associationType.getAssociationName()); for (JetspeedPrincipal from : fromList) { getManagerFrom().removePrincipal(from); } } else if (associationType.isRequired() && !isSynchronizing()) { if (!getManagerTo().getAssociatedTo(to.getName(), to.getType(), associationType.getAssociationName()).isEmpty()) { throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_REQUIRED.createScoped(to.getType().getName(), to.getName(), associationType.getFromPrincipalType().getName(), associationType.getAssociationName())); } } }
public void addPrincipal(JetspeedPrincipal principal, Set<JetspeedPrincipalAssociationReference> associations) throws SecurityException { if (!SynchronizationStateAccess.isSynchronizing() && !ldapEntityManager.isReadOnly()) { EntityFactory entityFactory = ldapEntityManager.getEntityFactory(principal.getType().getName()); if (entityFactory.isCreateAllowed()) { ldapEntityManager.addEntity(entityFactory.createEntity(principal)); } } delegateJpsm.addPrincipal(principal, associations); }
public void removePrincipal(JetspeedPrincipal principal) throws SecurityException { if (!SynchronizationStateAccess.isSynchronizing() && !ldapEntityManager.isReadOnly()) { EntityFactory entityFactory = ldapEntityManager.getEntityFactory(principal.getType().getName()); if (entityFactory.isRemoveAllowed()) { ldapEntityManager.removeEntity(entityFactory.createEntity(principal)); } } delegateJpsm.removePrincipal(principal); }
public void updatePrincipal(JetspeedPrincipal principal) throws SecurityException { if (!SynchronizationStateAccess.isSynchronizing() && !ldapEntityManager.isReadOnly()) { EntityFactory entityFactory = ldapEntityManager.getEntityFactory(principal.getType().getName()); if (entityFactory.isUpdateAllowed()) { ldapEntityManager.updateEntity(entityFactory.createEntity(principal)); } } delegateJpsm.updatePrincipal(principal); } }
public void updatePrincipal(JetspeedPrincipal principal) throws SecurityException { validatePrincipal(principal); if (principal.isReadOnly() && !isSynchronizing()) { throw new SecurityException(SecurityException.PRINCIPAL_IS_READ_ONLY.createScoped(principal.getType().getName(), principal.getName())); } jpsm.updatePrincipal(principal); notifyUpdatedPrincipal(principal); }