use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertDNs method resolveVirtualAttributeValueChange.
@Override
public List<String> resolveVirtualAttributeValueChange(PerunSessionImpl perunSession, String message) throws InternalErrorException, WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeAssignmentException {
List<String> resolvingMessages = new ArrayList<String>();
if (message == null)
return resolvingMessages;
User user = null;
Attribute attrVirtUserCertDNs = null;
Matcher extSourceTypeX509Matcher = extSourceTypeX509.matcher(message);
Matcher addUserExtSourceMatcher = addUserExtSource.matcher(message);
Matcher removeUserExtSourceMatcher = removeUserExtSource.matcher(message);
Matcher userAttributeSetMatcher = userAttributeSet.matcher(message);
Matcher userAttributeRemovedMatcher = userAttributeRemoved.matcher(message);
if (extSourceTypeX509Matcher.find()) {
if (addUserExtSourceMatcher.find() || removeUserExtSourceMatcher.find()) {
user = getUserFromMessage(message);
if (user != null) {
attrVirtUserCertDNs = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, user, AttributesManager.NS_USER_ATTR_VIRT + ":userCertDNs");
String messageAttributeSet = attrVirtUserCertDNs.serializeToString() + " set for " + user.serializeToString() + ".";
resolvingMessages.add(messageAttributeSet);
}
}
}
return resolvingMessages;
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertDNs method getUserFromMessage.
/**
* Get User from message if exists or if there is only one. In other case return null instead.
*
* @param message
* @return user or null
* @throws InternalErrorException
*/
private User getUserFromMessage(String message) throws InternalErrorException {
User user = null;
List<PerunBean> perunBeans = AuditParser.parseLog(message);
for (PerunBean pb : perunBeans) {
if (pb instanceof User) {
if (user != null) {
return null;
} else {
user = (User) pb;
}
}
}
return user;
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method removeUserAttributeWhenAttributeNotExists.
@Test(expected = AttributeNotExistsException.class)
public void removeUserAttributeWhenAttributeNotExists() throws Exception {
System.out.println(CLASS_NAME + "removeUserAttributeWhenAttributeNotExists");
vo = setUpVo();
member = setUpMember();
User user = perun.getUsersManager().getUserByMember(sess, member);
attributes = setUpUserAttribute();
attributes.get(0).setId(0);
attributesManager.removeAttribute(sess, user, attributes.get(0));
// shouldn't find attribute
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method removeFacilityUserAttributesWhenFacilityNotExists.
@Test(expected = FacilityNotExistsException.class)
public void removeFacilityUserAttributesWhenFacilityNotExists() throws Exception {
System.out.println(CLASS_NAME + "removeFacilityUserAttributesWhenFacilityNotExists");
attributes = setUpFacilityUserAttribute();
vo = setUpVo();
member = setUpMember();
User user = perun.getUsersManager().getUserByMember(sess, member);
attributesManager.removeAttributes(sess, new Facility(), user, attributes);
// shouldn't find facility
}
use of cz.metacentrum.perun.core.api.User in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getMemberGroupAttributesForUser.
@Test
public void getMemberGroupAttributesForUser() throws Exception {
System.out.println(CLASS_NAME + "getMemberGroupAttributesForUser");
vo = setUpVo();
member = setUpMember();
group = setUpGroup();
attributes = setUpUserAttribute();
User user = perun.getUsersManager().getUserByMember(sess, member);
attributesManager.setAttribute(sess, user, attributes.get(0));
Attribute attr = new Attribute();
attr.setNamespace("urn:perun:member_group:attribute-def:opt");
attr.setFriendlyName("member-group-test-for-list-of-names-attribute");
attr.setType(String.class.getName());
attr.setValue("MemberGroupAttributeForList");
attributesManager.createAttribute(sess, attr);
attributesManager.setAttribute(sess, member, group, attr);
List<String> attrNames = new ArrayList<>();
attrNames.add(attributes.get(0).getName());
attrNames.add(attr.getName());
// return members and users attributes from groups members
List<Attribute> retAttr = attributesManager.getAttributes(sess, member, group, attrNames, true);
assertNotNull("unable to get member-group(work with user) attributes", retAttr);
assertTrue("our attribute was not returned", retAttr.contains(attributes.get(0)));
}
Aggregations