use of cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi in project perun by CESNET.
the class Auditer method flush.
/**
* Imidiately flushes stored message for last top-level transaction into the log
*
*/
public void flush() {
List<List<List<AuditerMessage>>> topLevelTransactions = getTopLevelTransactions();
if (topLevelTransactions.isEmpty()) {
log.trace("No messages to flush");
return;
}
List<List<AuditerMessage>> transactionChain = topLevelTransactions.get(topLevelTransactions.size() - 1);
if (transactionChain.isEmpty()) {
log.trace("No messages to flush");
topLevelTransactions.remove(topLevelTransactions.size() - 1);
return;
}
if (transactionChain.size() != 1) {
log.error("There should be only one list of messages while flushing representing the most outer transaction.");
}
List<AuditerMessage> messages = transactionChain.get(0);
topLevelTransactions.remove(topLevelTransactions.size() - 1);
if (topLevelTransactions.isEmpty()) {
TransactionSynchronizationManager.unbindResourceIfPossible(this);
}
log.trace("Audit messages was flushed for current transaction.");
synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
storeMessagesToDb(messages);
}
for (AuditerMessage message : messages) {
for (VirtualAttributesModuleImplApi virtAttrModuleImplApi : registeredAttributesModules) {
List<String> resolvingMessages = new ArrayList<String>();
try {
resolvingMessages.addAll(virtAttrModuleImplApi.resolveVirtualAttributeValueChange((PerunSessionImpl) message.getOriginaterPerunSession(), message.getMessage()));
} catch (InternalErrorException ex) {
log.error("Error when auditer trying to resolve messages in modules.", ex);
} catch (WrongAttributeAssignmentException ex) {
log.error("Error when auditer trying to resolve messages in modules.", ex);
} catch (WrongReferenceAttributeValueException ex) {
log.error("Error when auditer trying to resolve messages in modules.", ex);
} catch (AttributeNotExistsException ex) {
log.error("Error when auditer trying to resolve messages in modules.", ex);
}
if (!resolvingMessages.isEmpty()) {
List<AuditerMessage> resolvingAuditerMessages = new ArrayList<>();
for (String msg : resolvingMessages) {
resolvingAuditerMessages.add(new AuditerMessage(message.getOriginaterPerunSession(), msg));
}
storeMessagesToDb(resolvingAuditerMessages);
}
}
}
}
use of cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi in project perun by CESNET.
the class AttributesManagerImpl method initialize.
protected void initialize() throws InternalErrorException {
log.debug("AttributesManagerImpl initialize started.");
//Get PerunSession
//String attributesManagerInitializator = "attributesManagerInitializator";
//PerunPrincipal pp = new PerunPrincipal(attributesManagerInitializator, ExtSourcesManager.EXTSOURCE_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
//PerunSession sess = perun.getPerunSession(pp);
//load all attributes modules
ServiceLoader<AttributesModuleImplApi> attributeModulesLoader = ServiceLoader.load(AttributesModuleImplApi.class);
for (AttributesModuleImplApi module : attributeModulesLoader) {
attributesModulesMap.put(module.getClass().getName(), module);
if (module instanceof VirtualAttributesModuleImplApi) {
Auditer.registerAttributeModule((VirtualAttributesModuleImplApi) module);
}
log.debug("Module " + module.getClass().getSimpleName() + " loaded.");
}
Utils.notNull(jdbc, "jdbc");
//check if all core atributes exists, create it doesn't
List<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>();
//Facility.id
AttributeDefinition attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Facility id");
attributes.add(attr);
//Facility.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_FACILITY_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Facility name");
attributes.add(attr);
//Resource.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Resource id");
attributes.add(attr);
//Resource.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Resource name");
attributes.add(attr);
//Resource.description
attr.setNamespace(AttributesManager.NS_RESOURCE_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("description");
attr.setDisplayName("Resource description");
attributes.add(attr);
//Member.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_MEMBER_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Member id");
attributes.add(attr);
//User.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("User id");
attributes.add(attr);
//User.firstName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("firstName");
attr.setDisplayName("User first name");
attributes.add(attr);
//User.lastName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("lastName");
attr.setDisplayName("User last name");
attributes.add(attr);
//User.middleName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("middleName");
attr.setDisplayName("User middle name");
attributes.add(attr);
//User.titleBefore
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("titleBefore");
attr.setDisplayName("User title before");
attributes.add(attr);
//User.titleAfter
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("titleAfter");
attr.setDisplayName("User title after");
attributes.add(attr);
//User.serviceUser
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_USER_ATTR_CORE);
attr.setType(Boolean.class.getName());
attr.setFriendlyName("serviceUser");
attr.setDisplayName("If user is service user or not.");
attributes.add(attr);
//Group.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Group id");
attributes.add(attr);
//Group.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Group full name");
attributes.add(attr);
//Group.description
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("description");
attr.setDisplayName("Group description");
attributes.add(attr);
//Group.parentGroupId
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("parentGroupId");
attr.setDisplayName("Id of group's parent group.");
attributes.add(attr);
//Vo.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Vo id");
attributes.add(attr);
//Vo.name
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("name");
attr.setDisplayName("Vo full name");
attributes.add(attr);
//Vo.createdAt
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("createdAt");
attr.setDisplayName("Vo created date");
attributes.add(attr);
//Vo.shortName
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_VO_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("shortName");
attr.setDisplayName("Vo short name");
attributes.add(attr);
//Host.id
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_HOST_ATTR_CORE);
attr.setType(Integer.class.getName());
attr.setFriendlyName("id");
attr.setDisplayName("Host id");
attributes.add(attr);
//Host.hostname
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_HOST_ATTR_CORE);
attr.setType(String.class.getName());
attr.setFriendlyName("hostname");
attr.setDisplayName("Host hostname");
attributes.add(attr);
// *** Def attributes
//urn:perun:group:attribute-def:def:groupExtSource
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("groupExtSource");
attr.setDisplayName("Group extSource");
attributes.add(attr);
//urn:perun:group:attribute-def:def:groupMembersExtSource
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("groupMembersExtSource");
attr.setDisplayName("Group members extSource");
attributes.add(attr);
//urn:perun:group:attribute-def:def:groupMembersQuery
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("groupMembersQuery");
attr.setDisplayName("Group members query");
attributes.add(attr);
//urn:perun:group:attribute-def:def:synchronizatinEnabled
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("synchronizationEnabled");
attr.setDisplayName("Group synchronization enabled");
attr.setDescription("Enables group synchronization from external source.");
attributes.add(attr);
//urn:perun:group:attribute-def:def:synchronizationInterval
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setFriendlyName("synchronizationInterval");
attr.setDisplayName("Synchronization interval");
attr.setDescription("Time between two successful synchronizations.");
attributes.add(attr);
//urn:perun:group:attribute-def:def:lastSynchronizationState
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setDescription("If group is synchronized, there will be information about state of last synchronization.");
attr.setFriendlyName("lastSynchronizationState");
attr.setDisplayName("Last synchronization state");
attributes.add(attr);
//urn:perun:group:attribute-def:def:lastSynchronizationTimestamp
attr = new AttributeDefinition();
attr.setNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
attr.setType(String.class.getName());
attr.setDescription("If group is synchronized, there will be the last timestamp of group synchronization.");
attr.setFriendlyName("lastSynchronizationTimestamp");
attr.setDisplayName("Last Synchronization timestamp");
attributes.add(attr);
if (perun.isPerunReadOnly())
log.debug("Loading attributes manager init in readOnly version.");
for (AttributeDefinition attribute : attributes) {
if (!checkAttributeExistsForInitialize(attribute)) {
if (perun.isPerunReadOnly()) {
throw new InternalErrorException("There is missing required attribute " + attribute + " and can't be created because this instance is read only.");
} else {
self.createAttributeExistsForInitialize(attribute);
}
}
}
log.debug("AttributesManagerImpl initialize ended.");
}
Aggregations