protected FilePermission(IdentityType identityType, Permission permission) { super(VERSION, permission); this.identityTypeId = identityType.getId(); }
protected FilePermission(IdentityType identityType, Permission permission) { super(VERSION, permission); this.identityTypeId = identityType.getId(); }
/** * <p>Return a formatted string representing the reference to the given {@link org.picketlink.idm.model.IdentityType}.</p> * * @param identityType * * @return */ public static String formatId(final IdentityType identityType) { return identityType.getClass().getName() + ID_SEPARATOR + identityType.getPartition().getId() + ID_SEPARATOR + identityType.getId(); }
/** * <p>Return a formatted string representing the reference to the given {@link org.picketlink.idm.model.IdentityType}.</p> * * @param identityType * * @return */ public static String formatId(final IdentityType identityType) { return identityType.getClass().getName() + ID_SEPARATOR + identityType.getPartition().getId() + ID_SEPARATOR + identityType.getId(); }
@Override protected void checkIfExists(IdentityType identityType) throws IdentityManagementException { if (identityType == null) { throw MESSAGES.nullArgument("IdentityType"); } if (lookupIdentityById(identityType.getClass(), identityType.getId()) == null) { throw MESSAGES.attributedTypeNotFoundWithId(identityType.getClass(), identityType.getId(), identityType.getPartition()); } }
@Override protected void checkIfExists(IdentityType identityType) throws IdentityManagementException { if (identityType == null) { throw MESSAGES.nullArgument("IdentityType"); } if (lookupIdentityById(identityType.getClass(), identityType.getId()) == null) { throw MESSAGES.attributedTypeNotFoundWithId(identityType.getClass(), identityType.getId(), identityType.getPartition()); } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().isInstance(obj)) { return false; } IdentityType other = (IdentityType) obj; return (getId() != null && other.getId() != null && getPartition() != null && other.getPartition() != null) && (getId().equals(other.getId()) && getPartition().equals(other.getPartition())); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().isInstance(obj)) { return false; } IdentityType other = (IdentityType) obj; return (getId() != null && other.getId() != null && getPartition() != null && other.getPartition() != null) && (getId().equals(other.getId()) && getPartition().equals(other.getPartition())); }
private void storeIdentityType(IdentityContext context, IdentityType identityType) { FilePartition filePartition = resolve(context.getPartition().getClass(), context.getPartition().getName()); Map<String, FileIdentityType> identityTypes = filePartition.getIdentityTypes().get(identityType.getClass().getName()); if (identityTypes == null) { identityTypes = new ConcurrentHashMap<String, FileIdentityType>(); filePartition.getIdentityTypes().put(identityType.getClass().getName(), identityTypes); } identityTypes.put(identityType.getId(), new FileIdentityType(identityType)); this.fileDataSource.flushAttributedTypes(filePartition); }
private void storeIdentityType(IdentityContext context, IdentityType identityType) { FilePartition filePartition = resolve(context.getPartition().getClass(), context.getPartition().getName()); Map<String, FileIdentityType> identityTypes = filePartition.getIdentityTypes().get(identityType.getClass().getName()); if (identityTypes == null) { identityTypes = new ConcurrentHashMap<String, FileIdentityType>(); filePartition.getIdentityTypes().put(identityType.getClass().getName(), identityTypes); } identityTypes.put(identityType.getId(), new FileIdentityType(identityType)); this.fileDataSource.flushAttributedTypes(filePartition); }
private List<?> findIdentityTypeRelationships(IdentityContext context, Class<? extends Relationship> relationshipType, IdentityType identityType) { List<Object> relationships = new ArrayList<Object>(); for (EntityMapper relationshipMemberMapper : getEntityMappers()) { Entry<Property, Property> property = relationshipMemberMapper.getProperty(RelationshipMember.class); if (property != null) { EntityManager em = getEntityManager(context); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(relationshipMemberMapper.getEntityType()); Root<?> root = criteria.from(relationshipMemberMapper.getEntityType()); Property<Object> identityTypeProperty = relationshipMemberMapper.getProperty(RelationshipMember.class).getValue(); if (identityTypeProperty.getJavaClass().equals(String.class)) { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), IdentityTypeUtil.formatId(identityType))); } else { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), em.find(identityTypeProperty.getJavaClass(), identityType.getId()))); } List<?> result = em.createQuery(criteria).getResultList(); Property<Object> ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); for (Object object : result) { relationships.add(ownerProperty.getValue(object)); } } } return relationships; }
private List<?> findIdentityTypeRelationships(IdentityContext context, Class<? extends Relationship> relationshipType, IdentityType identityType) { List<Object> relationships = new ArrayList<Object>(); for (EntityMapper relationshipMemberMapper : getEntityMappers()) { Entry<Property, Property> property = relationshipMemberMapper.getProperty(RelationshipMember.class); if (property != null) { EntityManager em = getEntityManager(context); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(relationshipMemberMapper.getEntityType()); Root<?> root = criteria.from(relationshipMemberMapper.getEntityType()); Property<Object> identityTypeProperty = relationshipMemberMapper.getProperty(RelationshipMember.class).getValue(); if (identityTypeProperty.getJavaClass().equals(String.class)) { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), IdentityTypeUtil.formatId(identityType))); } else { criteria.where(builder.equal(root.get(identityTypeProperty.getName()), em.find(identityTypeProperty.getJavaClass(), identityType.getId()))); } List<?> result = em.createQuery(criteria).getResultList(); Property<Object> ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); for (Object object : result) { relationships.add(ownerProperty.getValue(object)); } } } return relationships; }
@Override public void removeAttributedType(IdentityContext context, AttributedType attributedType) { if (IdentityType.class.isInstance(attributedType)) { IdentityType identityType = (IdentityType) attributedType; Partition partition = identityType.getPartition(); FilePartition filePartition = resolve(partition.getClass(), partition.getName()); Map<String, FileIdentityType> identityTypes = filePartition.getIdentityTypes().get(attributedType.getClass().getName()); if (identityTypes != null) { identityTypes.remove(identityType.getId()); } this.fileDataSource.flushAttributedTypes(filePartition); } else if (Relationship.class.isInstance(attributedType)) { Map<String, FileRelationship> fileRelationships = this.fileDataSource.getRelationships() .get(attributedType.getClass().getName()); for (FileRelationship fileRelationship : new HashMap<String, FileRelationship>(fileRelationships).values()) { if (fileRelationship.getId().equals(attributedType.getId())) { fileRelationships.remove(fileRelationship.getId()); } } this.fileDataSource.flushRelationships(); } else { this.fileDataSource.getAttributedTypes().remove(attributedType.getId()); this.fileDataSource.flushAttributedTypes(); } }
@Override public void removeAttributedType(IdentityContext context, AttributedType attributedType) { if (IdentityType.class.isInstance(attributedType)) { IdentityType identityType = (IdentityType) attributedType; Partition partition = identityType.getPartition(); FilePartition filePartition = resolve(partition.getClass(), partition.getName()); Map<String, FileIdentityType> identityTypes = filePartition.getIdentityTypes().get(attributedType.getClass().getName()); if (identityTypes != null) { identityTypes.remove(identityType.getId()); } this.fileDataSource.flushAttributedTypes(filePartition); } else if (Relationship.class.isInstance(attributedType)) { Map<String, FileRelationship> fileRelationships = this.fileDataSource.getRelationships() .get(attributedType.getClass().getName()); for (FileRelationship fileRelationship : new HashMap<String, FileRelationship>(fileRelationships).values()) { if (fileRelationship.getId().equals(attributedType.getId())) { fileRelationships.remove(fileRelationship.getId()); } } this.fileDataSource.flushRelationships(); } else { this.fileDataSource.getAttributedTypes().remove(attributedType.getId()); this.fileDataSource.flushAttributedTypes(); } }
@Override public boolean grantPermission(IdentityContext context, IdentityType assignee, Object resource, String operation) { Partition partition = assignee.getPartition(); FilePartition filePartition = resolve(partition.getClass(), partition.getName()); Class resourceClass = context.getPermissionHandlerPolicy().getResourceClass(resource); Serializable resourceIdentifier = context.getPermissionHandlerPolicy().getIdentifier(resource); List<Permission> existingPermissions = listPermissions(context, new IdentityPermission(resource, assignee, null)); if (existingPermissions.isEmpty()) { List<FilePermission> permissions = filePartition.getPermissions().get(assignee.getId()); if (permissions == null) { permissions = new ArrayList<FilePermission>(); filePartition.getPermissions().put(assignee.getId(), permissions); } FilePermission filePermission = new FilePermission(assignee, new IdentityPermission(resourceClass, resourceIdentifier .toString(), assignee, operation)); permissions.add(filePermission); } else { Permission permission = existingPermissions.get(0); revokePermission(context, assignee, resource, null); String newOperations = PermissionUtil.addOperation(permission.getOperation(), operation); grantPermission(context, assignee, resource, newOperations); } this.fileDataSource.flushPermissions(filePartition); return true; }
@Override public boolean grantPermission(IdentityContext context, IdentityType assignee, Object resource, String operation) { Partition partition = assignee.getPartition(); FilePartition filePartition = resolve(partition.getClass(), partition.getName()); Class resourceClass = context.getPermissionHandlerPolicy().getResourceClass(resource); Serializable resourceIdentifier = context.getPermissionHandlerPolicy().getIdentifier(resource); List<Permission> existingPermissions = listPermissions(context, new IdentityPermission(resource, assignee, null)); if (existingPermissions.isEmpty()) { List<FilePermission> permissions = filePartition.getPermissions().get(assignee.getId()); if (permissions == null) { permissions = new ArrayList<FilePermission>(); filePartition.getPermissions().put(assignee.getId(), permissions); } FilePermission filePermission = new FilePermission(assignee, new IdentityPermission(resourceClass, resourceIdentifier .toString(), assignee, operation)); permissions.add(filePermission); } else { Permission permission = existingPermissions.get(0); revokePermission(context, assignee, resource, null); String newOperations = PermissionUtil.addOperation(permission.getOperation(), operation); grantPermission(context, assignee, resource, newOperations); } this.fileDataSource.flushPermissions(filePartition); return true; }
@Override public boolean revokePermission(IdentityContext context, IdentityType assignee, Object resource, String operation) { Partition partition = assignee.getPartition(); FilePartition filePartition = resolve(partition.getClass(), partition.getName()); List<FilePermission> permissions = filePartition.getPermissions().get(assignee.getId()); Class resourceClass = context.getPermissionHandlerPolicy().getResourceClass(resource); Serializable resourceIdentifier = context.getPermissionHandlerPolicy().getIdentifier(resource); if (permissions != null) { for (FilePermission filePermission : new ArrayList<FilePermission>(permissions)) { Permission permission = filePermission.getEntry(); if (hasAttributes(permission, resourceClass, resourceIdentifier, operation)) { String newOperations = PermissionUtil.removeOperation(permission.getOperation(), operation); permissions.remove(filePermission); if (operation != null && !isNullOrEmpty(newOperations)) { grantPermission(context, assignee, resource, newOperations); } } } } return false; }
@Override public boolean revokePermission(IdentityContext context, IdentityType assignee, Object resource, String operation) { Partition partition = assignee.getPartition(); FilePartition filePartition = resolve(partition.getClass(), partition.getName()); List<FilePermission> permissions = filePartition.getPermissions().get(assignee.getId()); Class resourceClass = context.getPermissionHandlerPolicy().getResourceClass(resource); Serializable resourceIdentifier = context.getPermissionHandlerPolicy().getIdentifier(resource); if (permissions != null) { for (FilePermission filePermission : new ArrayList<FilePermission>(permissions)) { Permission permission = filePermission.getEntry(); if (hasAttributes(permission, resourceClass, resourceIdentifier, operation)) { String newOperations = PermissionUtil.removeOperation(permission.getOperation(), operation); permissions.remove(filePermission); if (operation != null && !isNullOrEmpty(newOperations)) { grantPermission(context, assignee, resource, newOperations); } } } } return false; }
for (IdentityType storedType: result) { if (property.getValue(storedType).equals(property.getValue(identityType))) { throw MESSAGES.identityTypeAlreadyExists(identityType.getClass(), identityType.getId(), identityType.getPartition());
for (IdentityType storedType: result) { if (property.getValue(storedType).equals(property.getValue(identityType))) { throw MESSAGES.identityTypeAlreadyExists(identityType.getClass(), identityType.getId(), identityType.getPartition());