ExtSource extSource = perun.getExtSourcesManagerBl().checkOrCreateExtSource(session, CADN, ExtSourcesManager.EXTSOURCE_X509);
/** * Create proper UserExtSource */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { PerunBl perun = (PerunBl)session.getPerun(); User user = app.getUser(); if (user == null) { log.error("At the end of approval action, we should have user present in application: {}", app); } else { Attribute userLogin = perun.getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:lifescience-hostel"); if (userLogin.getValue() != null) { ExtSource extSource = perun.getExtSourcesManagerBl().getExtSourceByName(session, "https://login.bbmri-eric.eu/lshostel/"); UserExtSource ues = new UserExtSource(extSource, userLogin + "@lifescience-hostel.org"); ues.setLoa(0); try { perun.getUsersManagerBl().addUserExtSource(session, user, ues); } catch (UserExtSourceExistsException ex) { // this is OK } } // User doesn't have login - don't set UES } return app; }
/** * Creates ExtSource and UserExtSource if necessary for the purpose of joining users identities. * * @param user User to add UES to * @param actor Actor to add * @param extSourceName ExtSource name to add * @param extSourceType ExtSource type to add * @param loa loa in ext source * @return created UserExtSource * @throws PerunException when anything fails */ private UserExtSource createExtSourceAndUserExtSource(User user, String actor, String extSourceName, String extSourceType, int loa) throws PerunException { ExtSource extSource = new ExtSource(extSourceName, extSourceType); try { extSource = perun.getExtSourcesManagerBl().getExtSourceByName(registrarSession, extSourceName); } catch (ExtSourceNotExistsException ex) { extSource = perun.getExtSourcesManager().createExtSource(registrarSession, extSource, null); } UserExtSource ues = new UserExtSource(); ues.setLogin(actor); ues.setLoa(loa); ues.setExtSource(extSource); return perun.getUsersManager().addUserExtSource(registrarSession, user, ues); }
} else { ExtSource es = perun.getExtSourcesManagerBl().getExtSourceByName(sess, app.getExtSourceName()); UserExtSource ues = perun.getUsersManagerBl().getUserExtSourceByExtLogin(sess, es, app.getCreatedBy());