use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_ceitec method getCeitecProxyUserExtSource.
private UserExtSource getCeitecProxyUserExtSource(PerunSessionImpl session, User user, ExtSource ceitecExtSource, String scope) throws InternalErrorException {
UserExtSource ceitecProxyUserExtSource = null;
List<UserExtSource> uess = session.getPerunBl().getUsersManagerBl().getUserExtSources(session, user);
for (UserExtSource ues : uess) {
if (ues.getExtSource().equals(ceitecExtSource) && ues.getLogin().endsWith("@" + scope)) {
if (ceitecProxyUserExtSource != null) {
throw new InternalErrorException("Multiple UserExtSourceLogins with Ceitec proxy IdP scope '" + scope + "' founded for user: " + user);
}
ceitecProxyUserExtSource = ues;
}
}
return ceitecProxyUserExtSource;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_elixir_persistent_shadow method changedAttributeHook.
/**
* ChangedAttributeHook() sets UserExtSource with following properties:
* - extSourceType is IdP
* - extSourceName is https://engine.elixir-idp.ics.muni.cz/authentication/idp/metadata
* - user's extSource login is the same as his elixir-persistent attribute
*
* @param session PerunSession
* @param user User to set UserExtSource for
* @param attribute Attribute containing elixirID
* @throws cz.metacentrum.perun.core.api.exceptions.InternalErrorException
* @throws cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException
*/
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
try {
String userNamespace = attribute.getFriendlyNameParameter();
if (userNamespace.equals("elixir-persistent-shadow") && attribute.getValue() != null) {
ExtSource extSource = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, extSourceNameElixir);
UserExtSource userExtSource = new UserExtSource(extSource, 0, attribute.getValue().toString());
session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, userExtSource);
}
} catch (UserExtSourceExistsException ex) {
log.warn("Elixir IdP external source already exists for the user.", ex);
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("IdP external source for elixir doesn't exist.", ex);
}
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method setUpCandidate.
private Candidate setUpCandidate() {
String userFirstName = Long.toHexString(Double.doubleToLongBits(Math.random()));
String userLastName = Long.toHexString(Double.doubleToLongBits(Math.random()));
// his login in external source
String extLogin = Long.toHexString(Double.doubleToLongBits(Math.random()));
//Mockito.mock(Candidate.class);
Candidate candidate = new Candidate();
candidate.setFirstName(userFirstName);
candidate.setId(0);
candidate.setMiddleName("");
candidate.setLastName(userLastName);
candidate.setTitleBefore("");
candidate.setTitleAfter("");
ExtSource extSource = new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal");
UserExtSource userExtSource = new UserExtSource(extSource, extLogin);
candidate.setUserExtSource(userExtSource);
candidate.setAttributes(new HashMap<String, String>());
return candidate;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method getAdmins.
@Test
public void getAdmins() throws Exception {
System.out.println(CLASS_NAME + "getAdmins");
// set up first user
final Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
facilitiesManagerEntry.addAdmin(sess, facility, user);
// set up authorized group
Group authorizedGroup = new Group("authorizedGroup", "testovaciGroup");
Group returnedGroup = perun.getGroupsManager().createGroup(sess, vo, authorizedGroup);
facilitiesManagerEntry.addAdmin(sess, facility, returnedGroup);
// set up second user
//Mockito.mock(Candidate.class);
Candidate candidate = new Candidate();
candidate.setFirstName("Josef");
candidate.setId(4);
candidate.setMiddleName("");
candidate.setLastName("Novak");
candidate.setTitleBefore("");
candidate.setTitleAfter("");
UserExtSource userExtSource = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), Long.toHexString(Double.doubleToLongBits(Math.random())));
candidate.setUserExtSource(userExtSource);
candidate.setAttributes(new HashMap<String, String>());
Member member2 = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
User user2 = perun.getUsersManagerBl().getUserByMember(sess, member2);
perun.getGroupsManager().addMember(sess, returnedGroup, member2);
// test
List<User> admins = facilitiesManagerEntry.getAdmins(sess, facility);
//assertTrue("group shoud have 2 admins",admins.size() == 2);
assertThat("facility should have 2 admins", admins.size(), is(2));
assertTrue("our member as direct user should be admin", admins.contains(user));
assertTrue("our member as member of admin group should be admin", admins.contains(user2));
}
Aggregations