use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class MembersManagerBlImpl method createMember.
/*
* This method finally has to call this.createMember(PerunSession sess, Vo vo, UserExtSource userExtSource)
* @see cz.metacentrum.perun.core.api.MembersManager#createMember(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Vo, java.lang.String, java.lang.String, java.lang.String, cz.metacentrum.perun.core.api.Candidate)
*/
public Member createMember(PerunSession sess, Vo vo, String extSourceName, String extSourceType, String login, Candidate candidate, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, GroupOperationsException {
// Create ExtSource object
ExtSource extSource = new ExtSource();
extSource.setName(extSourceName);
extSource.setType(extSourceType);
// Create UserExtSource object
UserExtSource userExtSource = new UserExtSource();
userExtSource.setLogin(login);
userExtSource.setExtSource(extSource);
// Set all above data to the candidate's userExtSource
candidate.setUserExtSource(userExtSource);
return this.createMember(sess, vo, candidate, groups);
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class MembersManagerBlImpl method createMember.
/*
* This method with support of LoA finally has to call this.createMember(PerunSession sess, Vo vo, UserExtSource userExtSource)
* @see cz.metacentrum.perun.core.api.MembersManager#createMember(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Vo, java.lang.String, java.lang.String, java.lang.String, cz.metacentrum.perun.core.api.Candidate)
*/
public Member createMember(PerunSession sess, Vo vo, String extSourceName, String extSourceType, int loa, String login, Candidate candidate, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, GroupOperationsException {
// Create ExtSource object
ExtSource extSource = new ExtSource();
extSource.setName(extSourceName);
extSource.setType(extSourceType);
// Create UserExtSource object
UserExtSource userExtSource = new UserExtSource();
userExtSource.setLogin(login);
userExtSource.setExtSource(extSource);
userExtSource.setLoa(loa);
// Set all above data to the candidate's userExtSource
candidate.setUserExtSource(userExtSource);
return this.createMember(sess, vo, candidate, groups);
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_optionalLogin_namespace_mu method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
try {
Attribute loginInMU = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:mu");
attribute = Utils.copyAttributeToVirtualAttributeWithValue(loginInMU, attribute);
} catch (AttributeNotExistsException ex) {
//That means that mu login attribute not exists at all
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
//if attribute is still null (empty login in mu or not existing attribute), try to find uco in user ext sources
if (attribute.getValue() == null) {
List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
for (UserExtSource userExtSource : userExtSources) {
ExtSource extSource = userExtSource.getExtSource();
//Skip if extSource is not the one we are looking for
if (userExtSource.getLogin() == null || extSource == null)
continue;
if (!ExtSourcesManager.EXTSOURCE_IDP.equals(extSource.getType()))
continue;
if (!EXTSOURCE_MUNI_IDP2.equals(extSource.getName()))
continue;
//Get login from this extSource and get only UCO from it
String login = userExtSource.getLogin();
Matcher loginMUMatcher = loginMUPattern.matcher(login);
//This user has login in mu, but in weird format so skip this one
if (!loginMUMatcher.find())
continue;
//It is ok, take UCO from login and set it to attribute value
String UCO = loginMUMatcher.group(1);
attribute.setValue(UCO);
break;
}
}
return attribute;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertDNs method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
Map<String, String> userCertDNs = new LinkedHashMap<>();
List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
//Sort user ext sources by their ids (biggest id go last)
Collections.sort(userExtSources, (ues1, ues2) -> ues1.getId() - ues2.getId());
//Prepare also prefix number
int i = 1;
for (UserExtSource uES : userExtSources) {
if (uES.getExtSource() != null) {
String login = uES.getLogin();
String type = uES.getExtSource().getType();
String name = uES.getExtSource().getName();
if (type != null && login != null && name != null && type.equals(ExtSourcesManager.EXTSOURCE_X509)) {
userCertDNs.put(i + ":" + login, name);
i++;
}
}
}
attribute.setValue(userCertDNs);
return attribute;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributes.
@Test
public void getUserExtSourceAttributes() throws Exception {
System.out.println(CLASS_NAME + "getUserExtSourceAttributes");
UserExtSource ues = setUpUserExtSourceTest();
attributes = setUpUserExtSourceAttribute();
attributesManager.setAttribute(sess, ues, attributes.get(0));
List<Attribute> retAttr = attributesManager.getAttributes(sess, ues);
assertNotNull("unable to get ues attributes", retAttr);
assertTrue("our attribute was not returned", retAttr.contains(attributes.get(0)));
}
Aggregations