use of cz.metacentrum.perun.core.api.NamespaceRules in project perun by CESNET.
the class LoginNamespacesRulesConfigLoader method loadNamespacesRulesFromJsonNode.
private Set<NamespaceRules> loadNamespacesRulesFromJsonNode(JsonNode rootNode) {
Set<NamespaceRules> rules = new HashSet<>();
// Fetch all namespaces from the configuration file
JsonNode namespacesNodes = rootNode.get("namespaces");
// For each namespace node construct NamespaceRules and add it to the set
Iterator<String> namespacesNames = namespacesNodes.fieldNames();
while (namespacesNames.hasNext()) {
String namespaceName = namespacesNames.next();
JsonNode namespaceNode = namespacesNodes.get(namespaceName);
JsonNode defaultEmail = namespaceNode.get("default_email");
JsonNode csvGenHeader = namespaceNode.get("csv_gen_header");
JsonNode csvGenPlaceholder = namespaceNode.get("csv_gen_placeholder");
JsonNode csvGenHeaderDescription = namespaceNode.get("csv_gen_header_description");
JsonNode requiredAttributesNode = namespaceNode.get("required_attributes");
JsonNode optionalAttributesNode = namespaceNode.get("optional_attributes");
Set<String> requiredAttributes = objectMapper.convertValue(requiredAttributesNode, new TypeReference<>() {
});
Set<String> optionalAttributes = objectMapper.convertValue(optionalAttributesNode, new TypeReference<>() {
});
NamespaceRules namespaceRules = new NamespaceRules();
namespaceRules.setNamespaceName(namespaceName);
namespaceRules.setDefaultEmail(defaultEmail.asText());
namespaceRules.setRequiredAttributes(requiredAttributes);
namespaceRules.setOptionalAttributes(optionalAttributes);
if (csvGenHeader != null && !csvGenHeader.isNull())
namespaceRules.setCsvGenHeader(csvGenHeader.asText());
if (csvGenPlaceholder != null && !csvGenPlaceholder.isNull())
namespaceRules.setCsvGenPlaceholder(csvGenPlaceholder.asText());
if (csvGenHeaderDescription != null && !csvGenHeaderDescription.isNull()) {
namespaceRules.setCsvGenHeaderDescription(csvGenHeaderDescription.asText());
}
rules.add(namespaceRules);
}
return rules;
}
use of cz.metacentrum.perun.core.api.NamespaceRules in project perun by CESNET.
the class MembersManagerEntryIntegrationTest method getNamespaceRules.
@Test
public void getNamespaceRules() throws Exception {
System.out.println(CLASS_NAME + "getNamespaceRule");
NamespaceRules rules = perun.getMembersManagerBl().getNamespaceRules("dummy_with_login");
assertEquals(rules.getNamespaceName(), "dummy_with_login");
assertThat(rules.getRequiredAttributes()).containsExactly("login");
assertThat(rules.getOptionalAttributes()).containsExactly("password");
}
use of cz.metacentrum.perun.core.api.NamespaceRules in project perun by CESNET.
the class LoginNamespacesRulesConfigLoader method loadNamespacesRulesConfig.
public Map<String, NamespaceRules> loadNamespacesRulesConfig() {
Map<String, NamespaceRules> namespacesRules = new HashMap<>();
try {
JsonNode rootNode = loadConfigurationFile(configurationPath);
loadNamespacesRulesFromJsonNode(rootNode).forEach(namespace -> namespacesRules.put(namespace.getNamespaceName(), namespace));
} catch (RuntimeException e) {
throw new InternalErrorException("Configuration file has invalid syntax. Configuration file: " + configurationPath.getFilename(), e);
}
return namespacesRules;
}
use of cz.metacentrum.perun.core.api.NamespaceRules in project perun by CESNET.
the class MembersManagerBlImpl method createSponsoredMember.
@Override
public Member createSponsoredMember(PerunSession sess, SponsoredUserData data, Vo vo, User sponsor, LocalDate validityTo, boolean sendActivationLink, String url, Validation validation) throws AlreadyMemberException, LoginNotExistsException, PasswordCreationFailedException, ExtendMembershipException, WrongAttributeValueException, ExtSourceNotExistsException, WrongReferenceAttributeValueException, UserNotInRoleException, InvalidLoginException, AlreadySponsorException, InvalidSponsoredUserDataException, NamespaceRulesNotExistsException, PasswordStrengthException {
User createdUser = createUser(sess, data);
String email = setEmailForUser(sess, createdUser, data.getEmail(), data.getNamespace());
if (isBlank(data.getPassword()) && isNotBlank(data.getNamespace())) {
NamespaceRules rules = getNamespaceRules(data.getNamespace());
if (rules.getRequiredAttributes().contains("password")) {
if (!sendActivationLink) {
throw new InvalidSponsoredUserDataException("Password is required but not provided.");
}
var module = perunBl.getUsersManagerBl().getPasswordManagerModule(sess, data.getNamespace());
var randomPassword = module.generateRandomPassword(sess, data.getLogin());
data.setPassword(randomPassword);
}
}
Member sponsoredMember = setSponsoredMember(sess, data, vo, createdUser, sponsor, validityTo, validation);
if (sendActivationLink) {
// TODO: at this moment there is missing way how to specify if email should be in different language than english
String defaultLanguage = "en";
sendAccountActivationLinkEmail(sess, sponsoredMember, data.getNamespace(), url, email, defaultLanguage);
}
return sponsoredMember;
}
Aggregations