use of io.vertigo.core.definition.DefinitionReference in project vertigo by KleeGroup.
the class UserAuthorizations method addAuthorization.
/**
* Add a authorization to this User.
* Authorization must be previously declared.
*
* @param authorization Authorization to add
* @return this UserAuthorizations
*/
public UserAuthorizations addAuthorization(final Authorization authorization) {
Assertion.checkNotNull(authorization);
// -----
authorizationRefs.put(authorization.getName(), new DefinitionReference<>(authorization));
if (authorization.getEntityDefinition().isPresent()) {
authorizationMapRefs.computeIfAbsent(new DefinitionReference<>(authorization.getEntityDefinition().get()), key -> new HashSet<>()).add(new DefinitionReference<>(authorization));
for (final Authorization grantedAuthorization : authorization.getGrants()) {
if (!hasAuthorization(grantedAuthorization::getName)) {
// On test pour ne pas créer de boucle
addAuthorization(grantedAuthorization);
}
}
}
return this;
}
use of io.vertigo.core.definition.DefinitionReference in project vertigo by KleeGroup.
the class DefinitionSpaceTest method testRegister.
@Test
public void testRegister() throws IOException, ClassNotFoundException {
final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
assertEquals(1L, definitionSpace.getAllTypes().size(), "definitionSpace must contain one element ");
assertEquals(1L, definitionSpace.getAll(SampleDefinition.class).size(), "definitionSpace[SampleDefinition.class] must contain one element ");
final SampleDefinition sampleDefinition = definitionSpace.resolve("SAMPLE_THE_DEFINITION", SampleDefinition.class);
assertNotNull(sampleDefinition);
assertEquals("THE_DEFINITION", DefinitionUtil.getLocalName(sampleDefinition.getName(), SampleDefinition.class), "localName must be THE_DEFINITION");
assertEquals(sampleDefinition.getName(), DefinitionUtil.getPrefix(SampleDefinition.class) + "_" + DefinitionUtil.getLocalName(sampleDefinition.getName(), SampleDefinition.class), "localName must be THE_DEFINITION");
final DefinitionReference<SampleDefinition> sampleDefinitionRef = new DefinitionReference<>(sampleDefinition);
byte[] serialized;
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(sampleDefinitionRef);
oos.flush();
serialized = bos.toByteArray();
}
// ---
DefinitionReference definitionReference;
try (final ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
final ObjectInputStream ios = new ObjectInputStream(bis)) {
definitionReference = DefinitionReference.class.cast(ios.readObject());
}
assertNotSame(sampleDefinitionRef, definitionReference, "DefinitionReferences must be not strictly equals");
assertSame(sampleDefinition, definitionReference.get(), "Definitions must be strictly equals");
}
Aggregations