use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class SchedulingManagerImpl method processOneAuditerMessage.
public void processOneAuditerMessage(String message) throws Exception {
PerunNotifAuditMessage perunNotifAuditMessage = null;
try {
perunNotifAuditMessage = perunNotifAuditMessagesManager.saveMessageToPerunAuditerMessage(message, session);
} catch (InternalErrorException ex) {
logger.error("Error during saving one time auditer message: " + message);
}
processPerunNotifAuditMessage(perunNotifAuditMessage, session);
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class PerunNotifEmailGroupSender method send.
@Override
public Set<Integer> send(List<PerunNotifMessageDto> dtosToSend) {
Set<Integer> usedPoolIds = new HashSet<Integer>();
List<PerunNotifEmailMessageToSendDto> messagesToSend = new ArrayList<PerunNotifEmailMessageToSendDto>();
for (PerunNotifMessageDto messageDto : dtosToSend) {
PoolMessage dto = messageDto.getPoolMessage();
PerunNotifTemplate template = messageDto.getTemplate();
PerunNotifReceiver receiver = messageDto.getReceiver();
try {
String groupSender = dto.getKeyAttributes().get(template.getSender());
if (groupSender == null || groupSender.isEmpty()) {
groupSender = template.getSender();
}
logger.debug("Calculated sender : {}", groupSender);
Integer groupId = Integer.valueOf(receiver.getTarget());
Group group = perun.getGroupsManagerBl().getGroupById(session, groupId);
List<Member> groupMembers = perun.getGroupsManagerBl().getGroupMembers(session, group);
if (groupMembers != null) {
for (Member member : groupMembers) {
try {
PerunNotifEmailMessageToSendDto memberEmailDto = new PerunNotifEmailMessageToSendDto();
memberEmailDto.setMessage(messageDto.getMessageToSend());
memberEmailDto.setSubject(messageDto.getSubject());
memberEmailDto.setReceiver((String) perun.getAttributesManagerBl().getAttribute(session, perun.getUsersManager().getUserByMember(session, member), "urn:perun:user:attribute-def:def:preferredMail").getValue());
memberEmailDto.setSender(groupSender);
messagesToSend.add(memberEmailDto);
} catch (Exception ex) {
logger.error("PreferredEmail cannot be retrieved, userId: {}", member.getUserId(), ex);
}
}
}
usedPoolIds.addAll(messageDto.getUsedPoolIds());
} catch (NumberFormatException ex) {
logger.error("GroupId cannot be parsed: {}", receiver.getTarget());
} catch (GroupNotExistsException ex) {
logger.error("Group with id: {} does not exists.", receiver.getTarget());
} catch (InternalErrorException ex) {
logger.error("Error during processing messageDto.", ex);
}
}
perunNotifEmailManager.sendMessages(messagesToSend);
return usedPoolIds;
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class OIDC method getUserinfo.
private ObjectNode getUserinfo(final PerunSession sess, final User user, Collection<String> allowedScopes, Map<String, String> properties) throws InternalErrorException, PrivilegeException, UserNotExistsException, WrongAttributeAssignmentException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode userinfo = mapper.createObjectNode();
for (final String scope : allowedScopes) {
String property = properties.get(scope);
if (property == null || property.isEmpty()) {
log.info("No values are mapped to scope " + scope + ". Configure them in " + CONFIG_FILE);
continue;
}
try {
JsonNode claims = mapper.readTree(property);
if (!claims.isObject()) {
throw new InternalErrorException("Config file " + CONFIG_FILE + " is wrongly configured. Values have to be valid JSON objects.");
}
claims = replaceAttrsInJsonTree(sess, user, claims);
if (claims != null && claims.isObject()) {
userinfo.putAll((ObjectNode) claims);
}
} catch (IOException e) {
throw new InternalErrorException("Config file " + CONFIG_FILE + " is wrongly configured. Values have to be valid JSON objects.", e);
}
}
return userinfo;
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Utils method generateAllGroupsToWriter.
/**
* Method generate all Groups to the text for using in LDIF.
* Write all these information to writer in perunInitializer object.
*
* @param perunInitializer need to be loaded to get all needed dependencies
*
* @throws InternalErrorException if some problem with initializer or objects in perun-core
* @throws IOException if some problem with writer
*/
public static void generateAllGroupsToWriter(PerunInitializer perunInitializer) throws InternalErrorException, IOException {
//Load basic variables
if (perunInitializer == null)
throw new InternalErrorException("PerunInitializer must be loaded before using in generating methods!");
PerunSession perunSession = perunInitializer.getPerunSession();
PerunBl perun = perunInitializer.getPerunBl();
BufferedWriter writer = perunInitializer.getOutputWriter();
//First get all vos
List<Vo> vos = perun.getVosManagerBl().getVos(perunSession);
//Then from all vos get all assigned groups and generate data about them to the writer
for (Vo vo : vos) {
List<Group> groups;
groups = perun.getGroupsManagerBl().getGroups(perunSession, vo);
for (Group group : groups) {
String dn = "dn: ";
String oc1 = "objectclass: top";
String oc3 = "objectclass: perunGroup";
String cn = "cn: ";
String perunVoId = "perunVoId: ";
String parentGroup = "perunParentGroup: ";
String parentGroupId = "perunParentGroupId: ";
String perunGroupId = "perunGroupId: ";
String owner = "owner: ";
String description = "description: ";
String perunUniqueGroupName = "perunUniqueGroupName: ";
List<Member> members;
members = perun.getGroupsManagerBl().getGroupMembers(perunSession, group, Status.VALID);
perunGroupId += String.valueOf(group.getId());
perunVoId += String.valueOf(group.getVoId());
dn += "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
cn += group.getName();
perunUniqueGroupName += vo.getShortName() + ":" + group.getName();
if (group.getDescription() != null)
description += group.getDescription();
if (group.getParentGroupId() != null) {
parentGroupId += group.getParentGroupId();
parentGroup += "perunGroupId=" + group.getParentGroupId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
}
List<Member> admins = new ArrayList<>();
writer.write(dn + '\n');
writer.write(oc1 + '\n');
writer.write(oc3 + '\n');
writer.write(cn + '\n');
writer.write(perunUniqueGroupName + '\n');
writer.write(perunGroupId + '\n');
writer.write(perunVoId + '\n');
if (group.getDescription() != null)
writer.write(description + '\n');
if (group.getParentGroupId() != null) {
writer.write(parentGroupId + '\n');
writer.write(parentGroup + '\n');
}
//ADD Group Members
for (Member m : members) {
writer.write("uniqueMember: " + "perunUserId=" + m.getUserId() + ",ou=People,dc=perun,dc=cesnet,dc=cz");
writer.write('\n');
}
//ADD resources which group is assigned to
List<Resource> associatedResources;
associatedResources = perun.getResourcesManagerBl().getAssignedResources(perunSession, group);
for (Resource r : associatedResources) {
writer.write("assignedToResourceId: " + r.getId());
writer.write('\n');
}
//FOR NOW No groups has owner
writer.write(owner + '\n');
writer.write('\n');
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class Utils method generateAllResourcesToWriter.
/**
* Method generate all Resources to the text for using in LDIF.
* Write all these information to writer in perunInitializer object.
*
* @param perunInitializer need to be loaded to get all needed dependencies
*
* @throws InternalErrorException if some problem with initializer or objects in perun-core
* @throws IOException if some problem with writer
*/
public static void generateAllResourcesToWriter(PerunInitializer perunInitializer) throws InternalErrorException, IOException {
//Load basic variables
if (perunInitializer == null)
throw new InternalErrorException("PerunInitializer must be loaded before using in generating methods!");
PerunSession perunSession = perunInitializer.getPerunSession();
PerunBl perun = perunInitializer.getPerunBl();
BufferedWriter writer = perunInitializer.getOutputWriter();
//first get all Vos
List<Vo> vos = perun.getVosManagerBl().getVos(perunSession);
//Then from every Vo get all assigned resources and write their data to the writer
for (Vo vo : vos) {
List<Resource> resources;
resources = perun.getResourcesManagerBl().getResources(perunSession, vo);
for (Resource resource : resources) {
//Read facility attribute entityID and write it for the resource if exists
Facility facility = null;
try {
facility = perun.getFacilitiesManagerBl().getFacilityById(perunSession, resource.getFacilityId());
} catch (FacilityNotExistsException ex) {
throw new InternalErrorException("Can't found facility of this resource " + resource, ex);
}
Attribute entityIDAttr = null;
try {
entityIDAttr = perun.getAttributesManagerBl().getAttribute(perunSession, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":entityID");
} catch (AttributeNotExistsException | WrongAttributeAssignmentException ex) {
throw new InternalErrorException("Problem with loading entityID attribute of facility " + facility, ex);
}
String dn = "dn: ";
String oc1 = "objectclass: top";
String oc3 = "objectclass: perunResource";
String cn = "cn: ";
String perunVoId = "perunVoId: ";
String perunFacilityId = "perunFacilityId: ";
String perunResourceId = "perunResourceId: ";
String description = "description: ";
String entityID = "entityID: ";
perunVoId += String.valueOf(resource.getVoId());
perunFacilityId += String.valueOf(resource.getFacilityId());
perunResourceId += String.valueOf(resource.getId());
dn += "perunResourceId=" + resource.getId() + ",perunVoId=" + resource.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
cn += resource.getName();
String descriptionValue = resource.getDescription();
if (descriptionValue != null) {
if (descriptionValue.matches("^[ ]*$"))
descriptionValue = null;
}
writer.write(dn + '\n');
writer.write(oc1 + '\n');
writer.write(oc3 + '\n');
writer.write(cn + '\n');
writer.write(perunResourceId + '\n');
if (descriptionValue != null)
writer.write(description + descriptionValue + '\n');
writer.write(perunVoId + '\n');
writer.write(perunFacilityId + '\n');
if (entityIDAttr.getValue() != null)
writer.write(entityID + (String) entityIDAttr.getValue() + '\n');
//ADD resources which group is assigned to
List<Group> associatedGroups = perun.getResourcesManagerBl().getAssignedGroups(perunSession, resource);
for (Group g : associatedGroups) {
writer.write("assignedGroupId: " + g.getId());
writer.write('\n');
}
writer.write('\n');
}
}
}
Aggregations