use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_bbmri_persistent_shadow method changedAttributeHook.
/**
* ChangedAttributeHook() sets UserExtSource with following properties:
* - extSourceType is IdP
* - extSourceName is https://login.bbmri-eric.eu/idp/
* - user's extSource login is the same as his bbmri-persistent attribute
*
* @param session PerunSession
* @param user User to set UserExtSource for
* @param attribute Attribute containing bbmriID
* @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("bbmri-persistent-shadow") && attribute.getValue() != null) {
ExtSource extSource = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, extSourceNameBbmri);
UserExtSource userExtSource = new UserExtSource(extSource, 0, attribute.getValue().toString());
session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, userExtSource);
}
} catch (UserExtSourceExistsException ex) {
log.warn("BBMRI IdP external source already exists for the user.", ex);
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("IdP external source for BBMRI doesn't exist.", ex);
}
}
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 handleChangedAttributeHook.
private void handleChangedAttributeHook(PerunSessionImpl session, User user, Attribute attribute, String entityId, String scope) throws InternalErrorException {
/*
* "Synchornize" this attribute to user extSource. Means it creates, updates and removes userExtSource
* whenever this attribute is added, edited or removed.
*
* Ceitec proxy UserExtSourceLogin has form: {login-namespace:ceitec}@ceitec.cz
*/
try {
ExtSource ceitecProxyIdp = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, entityId);
UserExtSource ceitecUes = getCeitecProxyUserExtSource(session, user, ceitecProxyIdp, scope);
log.debug("changedAttributeHook UserExtSourceLogin to be synchronized: " + ceitecUes);
if (attribute.getValue() == null) {
// Deleting attribute
if (ceitecUes == null) {
log.debug("Deleting ceitec login but proxy UES does not exist. Probably ceitec login was not set before.");
} else {
session.getPerunBl().getUsersManagerBl().removeUserExtSource(session, user, ceitecUes);
}
} else {
String newLogin = attribute.getValue() + "@" + scope;
if (ceitecUes == null) {
// Creating UES
ceitecUes = new UserExtSource(ceitecProxyIdp, 0, newLogin);
session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, ceitecUes);
} else {
// Updating UES
ceitecUes.setLogin(newLogin);
session.getPerunBl().getUsersManagerBl().updateUserExtSource(session, ceitecUes);
}
}
} catch (ExtSourceNotExistsException e) {
throw new InternalErrorException("Attribute module 'urn_perun_user_attribute_def_def_login_namespace_ceitec' " + " require extSource with name (entityId): " + entityId + ". User: " + user, e);
} catch (UserExtSourceAlreadyRemovedException e) {
throw new InternalErrorException("Inconsistency. Attribute module 'urn_perun_user_attribute_def_def_login_namespace_ceitec' " + " tries to delete extSource but it does not exists. " + "extSource with name (entityId): " + entityId + ". User: " + user, e);
} catch (UserExtSourceExistsException e) {
throw new InternalErrorException("This module should check if ceitec login already exists " + "and call update method.", e);
}
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_organizationsWithLoa method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
HashMap<String, String> organizationsWithLoa = new LinkedHashMap<String, String>();
List<UserExtSource> extSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
//If no userExtSources, so no Loa for any of them.
if (extSources == null || extSources.isEmpty())
return attribute;
String version = attributeDefinition.getFriendlyNameParameter();
if (version == null)
throw new InternalErrorException("There is no parameter (cs or en) in attribute " + attributeDefinition);
UserExtSource userExtSourceForCreating = null;
UserExtSource userExtSourceForModifiing = null;
//Initialize MapOfExtSource
initializeMapOfExtSourceName();
for (UserExtSource uES : extSources) {
String uEName = uES.getExtSource().getName();
String uELoa = String.valueOf(uES.getLoa());
if (uES.getCreatedAt() != null) {
Date testingDate = null;
Date lastUsedDate = null;
boolean parsed = true;
try {
testingDate = BeansUtils.getDateFormatter().parse(uES.getCreatedAt());
} catch (Exception ex) {
//Not Parsed correctly
parsed = false;
}
if (parsed) {
if (userExtSourceForCreating == null || userExtSourceForCreating.getCreatedAt() == null)
userExtSourceForCreating = uES;
else {
try {
lastUsedDate = BeansUtils.getDateFormatter().parse(userExtSourceForCreating.getCreatedAt());
if (testingDate != null && testingDate.compareTo(lastUsedDate) < 0) {
userExtSourceForCreating = uES;
}
} catch (Exception ex) {
//Not Parsed correctly
userExtSourceForCreating = uES;
}
}
}
}
if (uES.getModifiedAt() != null) {
Date testingDate = null;
Date lastUsedDate = null;
boolean parsed = true;
try {
testingDate = BeansUtils.getDateFormatter().parse(uES.getModifiedAt());
} catch (Exception ex) {
//Not Parsed correctly
parsed = false;
}
if (parsed) {
if (userExtSourceForModifiing == null || userExtSourceForModifiing.getModifiedAt() == null)
userExtSourceForModifiing = uES;
else {
try {
lastUsedDate = BeansUtils.getDateFormatter().parse(userExtSourceForModifiing.getModifiedAt());
if (testingDate != null && testingDate.compareTo(lastUsedDate) < 0) {
userExtSourceForModifiing = uES;
}
} catch (Exception ex) {
//Not Parsed correctly
userExtSourceForModifiing = uES;
}
}
}
}
String uESimpleName = getSimpleNameOfExtSource(uEName, version.equals("cs"));
organizationsWithLoa.put(uESimpleName, uELoa);
}
//Set created,modified by userExtSources
if (userExtSourceForCreating != null) {
attribute.setValueCreatedAt(userExtSourceForCreating.getCreatedAt());
attribute.setValueCreatedBy(userExtSourceForCreating.getCreatedBy());
}
if (userExtSourceForModifiing != null) {
attribute.setValueModifiedAt(userExtSourceForModifiing.getModifiedAt());
attribute.setValueModifiedBy(userExtSourceForModifiing.getModifiedBy());
}
attribute.setValue(organizationsWithLoa);
return attribute;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_logins_namespace_google method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Set<String> googleLogins = new HashSet<>();
List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
for (UserExtSource uES : userExtSources) {
if (uES.getExtSource() != null && EXTSOURCE.equals(uES.getExtSource().getName())) {
String login = uES.getLogin();
if (login != null && !login.isEmpty() && login.matches(LOGIN_REGEX)) {
googleLogins.add(login.replaceAll("[@].*$", ""));
}
}
}
Attribute attribute = new Attribute(attributeDefinition);
attribute.setValue(new ArrayList<>(googleLogins));
return attribute;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_shibbolethExtSources method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Map<String, String> idpLogins = new LinkedHashMap<String, String>();
List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
for (UserExtSource uES : userExtSources) {
if (uES.getExtSource() != null) {
String login = uES.getLogin();
String type = uES.getExtSource().getType();
String idpIdentifier = uES.getExtSource().getName();
if (type != null && login != null) {
if (type.equals(ExtSourcesManager.EXTSOURCE_IDP)) {
idpLogins.put(idpIdentifier, login);
}
}
}
}
Attribute attribute = new Attribute(attributeDefinition);
attribute.setValue(idpLogins);
return attribute;
}
Aggregations