use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class EgiuiPasswordManagerModule method validatePassword.
@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
if (user == null) {
user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
}
if (user == null) {
log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
} else {
// set extSources and extSource related attributes
try {
List<String> kerberosLogins = new ArrayList<>();
ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "EGI");
UserExtSource ues = new UserExtSource(extSource, userLogin + "@EGI");
ues.setLoa(0);
try {
((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
} catch (UserExtSourceExistsException ex) {
// this is OK
}
// Store also Kerberos logins
Attribute kerberosLoginsAttr = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
kerberosLogins.addAll((List<String>) kerberosLoginsAttr.getValue());
}
if (!kerberosLogins.contains(userLogin + "@EGI") && kerberosLoginsAttr != null) {
kerberosLogins.add(userLogin + "@EGI");
kerberosLoginsAttr.setValue(kerberosLogins);
((PerunBl) sess.getPerun()).getAttributesManagerBl().setAttribute(sess, user, kerberosLoginsAttr);
}
} catch (WrongAttributeAssignmentException | AttributeNotExistsException | ExtSourceNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
// validate password
super.validatePassword(sess, userLogin, user);
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class EinfraservicesPasswordManagerModule method validatePassword.
@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
if (user == null) {
user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
}
if (user == null) {
log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
} else {
// set extSources and extSource related attributes
try {
ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "EINFRA-SERVICES");
UserExtSource ues = new UserExtSource(extSource, userLogin + "@EINFRA-SERVICES");
ues.setLoa(0);
try {
((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
} catch (UserExtSourceExistsException ex) {
// this is OK
}
List<String> kerberosLogins = new ArrayList<>();
// Store also Kerberos logins
Attribute kerberosLoginsAttr = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
kerberosLogins.addAll((List<String>) kerberosLoginsAttr.getValue());
}
if (!kerberosLogins.contains(userLogin + "@EINFRA-SERVICES") && kerberosLoginsAttr != null) {
kerberosLogins.add(userLogin + "@EINFRA-SERVICES");
kerberosLoginsAttr.setValue(kerberosLogins);
((PerunBl) sess.getPerun()).getAttributesManagerBl().setAttribute(sess, user, kerberosLoginsAttr);
}
} catch (WrongAttributeAssignmentException | AttributeNotExistsException | ExtSourceNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
// validate password
super.validatePassword(sess, userLogin, user);
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method addIDPExtSourcesWithSameLoginDifferentUserDuplicates.
@Test
public void addIDPExtSourcesWithSameLoginDifferentUserDuplicates() throws Exception {
System.out.println(CLASS_NAME + "addIDPExtSourcesWithSameLoginDifferentUserDuplicates");
ExtSource ext1 = new ExtSource("test1", ExtSourcesManagerEntry.EXTSOURCE_IDP);
ExtSource ext2 = new ExtSource("test2", ExtSourcesManagerEntry.EXTSOURCE_IDP);
ExtSource ext3 = new ExtSource("test3", ExtSourcesManagerEntry.EXTSOURCE_IDP);
ext1 = perun.getExtSourcesManagerBl().createExtSource(sess, ext1, null);
ext2 = perun.getExtSourcesManagerBl().createExtSource(sess, ext2, null);
ext3 = perun.getExtSourcesManagerBl().createExtSource(sess, ext3, null);
UserExtSource ues1 = new UserExtSource(ext1, 1, "testExtLogin@test");
UserExtSource ues2 = new UserExtSource(ext2, 1, "testExtLogin@test");
UserExtSource ues3 = new UserExtSource(ext3, 1, "testExtLogin@test");
usersManager.addUserExtSource(sess, user, ues1);
usersManager.addUserExtSource(sess, user, ues2);
// should fail since there is different user using these identities (multiple times)
assertThatExceptionOfType(InternalErrorException.class).isThrownBy(() -> usersManager.addUserExtSource(sess, sponsoredUser, ues3));
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method setUpVo.
private Vo setUpVo() throws Exception {
Vo newVo = new Vo(0, "UserManagerTestVo", "UMTestVo");
Vo returnedVo = perun.getVosManager().createVo(sess, newVo);
// create test VO in database
assertNotNull("unable to create testing Vo", returnedVo);
newVo.setId(returnedVo.getId());
assertEquals("both VOs should be the same", newVo, returnedVo);
ExtSource newExtSource = new ExtSource(extSourceName, ExtSourcesManager.EXTSOURCE_INTERNAL);
ExtSource es = perun.getExtSourcesManager().createExtSource(sess, newExtSource, null);
// get and create real external source from DB
perun.getExtSourcesManager().addExtSource(sess, returnedVo, es);
return returnedVo;
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class urn_perun_group_attribute_def_def_groupExtSourceTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_group_attribute_def_def_groupExtSource();
attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
sess = mock(PerunSessionImpl.class);
PerunBl perunBl = mock(PerunBl.class);
when(sess.getPerunBl()).thenReturn(perunBl);
GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
when(perunBl.getGroupsManagerBl()).thenReturn(groupsManagerBl);
Vo groupVo = mock(Vo.class);
VosManagerBl vosManagerBl = mock(VosManagerBl.class);
when(perunBl.getVosManagerBl()).thenReturn(vosManagerBl);
when(sess.getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId())).thenReturn(groupVo);
ExtSource extSource = new ExtSource(1, "my_example", "type");
ExtSourcesManagerBl extSourcesManagerBl = mock(ExtSourcesManagerBl.class);
when(sess.getPerunBl().getExtSourcesManagerBl()).thenReturn(extSourcesManagerBl);
when(sess.getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, groupVo)).thenReturn(Collections.singletonList(extSource));
}
Aggregations