use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method setUpUserExtSource.
private void setUpUserExtSource() throws Exception {
ExtSource externalSource = perun.getExtSourcesManager().getExtSourceByName(sess, extSourceName);
// gets real external source object from database
userExtSource.setExtSource(externalSource);
// put real external source into user's external source
userExtSource.setLogin(extLogin);
// set users login in his ext source
assertNotNull(usersManager.addUserExtSource(sess, user, userExtSource));
// create new user ext source in database
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class ExtSourcePerun method covertRichUserToSubject.
private Map<String, String> covertRichUserToSubject(RichUser richUser) throws InternalErrorException {
Map<String, String> richUserInMap = new HashMap<String, String>();
String mapping = getAttributes().get("xmlMapping");
String[] mappingArray = mapping.split(",\n");
//Get user login
String login = "";
for (UserExtSource ues : richUser.getUserExtSources()) {
if (ues.getExtSource() != null && ues.getExtSource().getName().equals(extSourceNameForLogin)) {
login = ues.getLogin();
break;
}
}
//Null login is not allowed there
if (login == null)
throw new InternalErrorException("There is missing login for user " + richUser + " and extSource " + extSourceNameForLogin);
for (int i = 0; i < mappingArray.length; i++) {
String attr = mappingArray[i].trim();
int index = attr.indexOf("=");
if (index <= 0)
throw new InternalErrorException("There is no text in xmlMapping attribute or there is no '=' character.");
String name = attr.substring(0, index);
String value = attr.substring(index + 1);
Matcher attributeMatcher = attributePattern.matcher(value);
//Try to find perun attributes in value part
if (attributeMatcher.find()) {
if (attributeMatcher.group(1).equals("login")) {
value = attributeMatcher.replaceFirst(login);
} else {
String replacement = lookingForValueInRichUserAttributes(attributeMatcher.group(1), richUser);
if (replacement == null)
replacement = "";
value = attributeMatcher.replaceFirst(replacement);
//If whole value is empty because of replacement, it means null for us
if (value.isEmpty())
value = null;
}
} else if (value.startsWith("urn:perun:")) {
//DEPRECATED, but need to be first removed from all settings of PerunExtSource in perun-extSource.xml file
//It is probably old way how to use attribute (without {}) so try to find value for it
value = lookingForValueInRichUserAttributes(value, richUser);
}
//If nothing found, let the value be the same, it is probably static value (without any attribute)
richUserInMap.put(name.trim(), value);
}
return richUserInMap;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class urn_perun_member_attribute_def_virt_loa method getAttributeValue.
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, AttributeDefinition attributeDefinition) throws InternalErrorException {
User user = null;
try {
user = sess.getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
} catch (UserNotExistsException ex) {
throw new InternalErrorException("There is no user for get member " + member, ex);
}
List<UserExtSource> extSources = sess.getPerunBl().getUsersManagerBl().getActiveUserExtSources(sess, user);
Integer maxLoa = 0;
for (UserExtSource e : extSources) {
if (maxLoa < e.getLoa())
maxLoa = e.getLoa();
}
Attribute attribute = new Attribute(attributeDefinition);
attribute.setValue(maxLoa.toString());
return attribute;
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class MuPasswordManagerModule method getUcoFromSessionUser.
/**
* Return MU UCO of a pwdmanager method caller from his UserExtSource in MU IdP.
*
* @param session Session to get user and identity from
* @return Part of API call params like: "<zmenil>UČO</zmenil>" or empty string.
*/
private String getUcoFromSessionUser(PerunSession session) {
PerunBl perunBl = (PerunBl) session.getPerun();
List<UserExtSource> ueses = null;
try {
if (session.getPerunPrincipal().getUser() != null) {
ueses = perunBl.getUsersManagerBl().getUserExtSources(session, session.getPerunPrincipal().getUser());
} else {
return "";
}
} catch (Exception ex) {
return "";
}
for (UserExtSource extSource : ueses) {
if (extSource.getExtSource().getName().equals("https://idp2.ics.muni.cz/idp/shibboleth") && extSource.getExtSource().getType().equals(ExtSourcesManager.EXTSOURCE_IDP)) {
String login = extSource.getLogin();
if (login != null) {
return "<zmenil>" + login.split("@")[0] + "</zmenil>\n";
}
}
}
return "";
}
use of cz.metacentrum.perun.core.api.UserExtSource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributeWhenWrongAttrAssignment.
@Test(expected = WrongAttributeAssignmentException.class)
public void getUserExtSourceAttributeWhenWrongAttrAssignment() throws Exception {
System.out.println(CLASS_NAME + "getUserExtSourceAttributeWhenWrongAttrAssignment");
UserExtSource ues = setUpUserExtSourceTest();
attributesManager.getAttribute(sess, ues, "urn:perun:vo:attribute-def:core:id");
// shouldn't find vo attribute on user external source
}
Aggregations