AttributeValueExtractor { public static <T> List<AuthAttribute> extractAttributesFromResource(T object) { if (object instanceof AttributiveAuthEntity) { return ((AttributiveAuthEntity) object).getAuthAttributes(); } else { return performReflectiveExtraction(object); } }  static List<AuthAttribute> extractAttributesFromSubject(T object); static List<AuthAttribute> extract(T object, A action); static List<AuthAttribute> extractAttributesFromResource(T object); static List<AuthAttribute> extractAttributesFromAction(T object); static Object extractActionEntityByValue(Class<T> clazz, String value); static final String ACTION_NAME; static final String SUBJECT_NAME; static final String ENVIRONMENT_NAME; }
@Test public void checkExtractorAnnotated() { AnnotatedEntity entity = new AnnotatedEntity("idVal", 1, "123"); List<AuthAttribute> attributes = extractAttributesFromResource(entity); Assert.assertEquals(2, attributes.size()); AuthAttribute attr1 = attributes.get(0); AuthAttribute attr2 = attributes.get(1); Assert.assertEquals(true, attr1.getId().startsWith("ent.")); Assert.assertEquals(true, attr2.getId().startsWith("ent.")); if (attr1.getId().equals("ent.i")) { Assert.assertEquals(1, attr1.getValues().size()); Assert.assertEquals("idVal", attr1.getValues().get(0)); Assert.assertEquals(1, attr2.getValues().size()); Assert.assertEquals("1", attr2.getValues().get(0)); } else { Assert.assertEquals(1, attr2.getValues().size()); Assert.assertEquals("idVal", attr2.getValues().get(0)); Assert.assertEquals(1, attr1.getValues().size()); Assert.assertEquals("1", attr1.getValues().get(0)); } }
@Test public void checkExtractorDefault() { DefaultEntity entity = new DefaultEntity("idVal", 1); List<AuthAttribute> attributes = extractAttributesFromResource(entity); Assert.assertEquals(2, attributes.size()); AuthAttribute attr1 = attributes.get(0); AuthAttribute attr2 = attributes.get(1); Assert.assertEquals(true, attr1.getId().startsWith("defaultEntity.")); Assert.assertEquals(true, attr2.getId().startsWith("defaultEntity.")); if (attr1.getId().equals("defaultEntity.id")) { Assert.assertEquals(1, attr1.getValues().size()); Assert.assertEquals("idVal", attr1.getValues().get(0)); Assert.assertEquals(1, attr2.getValues().size()); Assert.assertEquals("1", attr2.getValues().get(0)); } else { Assert.assertEquals(1, attr2.getValues().size()); Assert.assertEquals("idVal", attr2.getValues().get(0)); Assert.assertEquals(1, attr1.getValues().size()); Assert.assertEquals("1", attr1.getValues().get(0)); } }
@Test public void checkExtractorImpl() { ImplementingEntity entity = new ImplementingEntity("idVal", 1); List<AuthAttribute> attributes = extractAttributesFromResource(entity); Assert.assertEquals(2, attributes.size()); AuthAttribute attr1 = attributes.get(0); AuthAttribute attr2 = attributes.get(1); if (attr1.getId().equals("id")) { Assert.assertEquals(1, attr1.getValues().size()); Assert.assertEquals("idVal", attr1.getValues().get(0)); Assert.assertEquals(1, attr2.getValues().size()); Assert.assertEquals("1", attr2.getValues().get(0)); } else { Assert.assertEquals(1, attr2.getValues().size()); Assert.assertEquals("idVal", attr2.getValues().get(0)); Assert.assertEquals(1, attr1.getValues().size()); Assert.assertEquals("1", attr1.getValues().get(0)); } }