public Response getUser(String identifier) throws SCIMException { log.debug("Calling SCIM REST method getUser by id {}", identifier); if (identifier == null) { throw new NullPointerException("identifier is null"); } try { User perunUser = perunBl.getUsersManagerBl().getUserById(session, Integer.parseInt(identifier)); ObjectMapper mapper = new ObjectMapper(); return Response.ok(mapper.writeValueAsString(mapPerunUserToScimUser(perunUser))).build(); } catch (InternalErrorException ex) { log.warn("Internal exception occured while getting user with id {}.", identifier); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (UserNotExistsException ex) { log.warn("User with id {} does not exists.", identifier); return Response.status(Response.Status.NOT_FOUND).build(); } catch (IOException ex) { throw new SCIMException("Cannot convert user resource to json string", ex); } }
String userLocale = (String) perun.getAttributesManagerBl().getAttribute(session, perun.getUsersManagerBl() .getUserById(session, id), "urn:perun:user:attribute-def:def:preferredLanguage").getValue(); if (userLocale == null) {
private List<MemberSCIM> mapPerunMembersToScimMembers(List<Member> perunMembers) { List<MemberSCIM> scimMembers = new ArrayList(); for (Member perunMember : perunMembers) { User perunUser; try { perunUser = perunBl.getUsersManagerBl().getUserByMember(session, perunMember); MemberSCIM member = new MemberSCIM(); String id = String.valueOf(perunMember.getId()); member.setDisplay(perunUser.getDisplayName()); member.setValue(id); member.setRef(BASE_PATH + USERS_PATH + id); scimMembers.add(member); } catch (InternalErrorException ex) { log.error("Cannot find user with id " + perunMember.getUserId(), ex); } } return scimMembers; } }
/** * Return groups that user is member of. * * @return groups that user is member of * @throws VOOTException if the can not read groups of user */ private List<Group> isMemberOf() throws VOOTException{ List<Group> groups = new ArrayList<Group>(); List<Vo> vos = new ArrayList<Vo>(); try{ vos.addAll(perun.getUsersManagerBl().getVosWhereUserIsMember(session, user)); }catch(InternalErrorException ex){ throw new VOOTException("internal_server_error"); } try{ for (Vo vo : vos) { Member member = perun.getMembersManagerBl().getMemberByUser(session, vo, user); groups.addAll(perun.getGroupsManagerBl().getAllMemberGroups(session, member)); } }catch(InternalErrorException ex){ throw new VOOTException("internal_server_error"); }catch(MemberNotExistsException ex){ throw new VOOTException("not_a_member"); } return groups; }
List<RichUser> users = perun.getUsersManagerBl().findRichUsersWithAttributes(sess, searchString, attrs); for (RichUser user : users) { Author author = new Author(user.getId(), user.getFirstName(), user.getLastName(), user.getMiddleName(),
@Override public List<ApplicationFormItemData> createApplication(PerunSession session, Application application, List<ApplicationFormItemData> data) throws PerunException { if (application.getUser() == null) { for (ApplicationFormItemData item : data) { if (item.getFormItem() != null && Objects.equals(AttributesManager.NS_USER_ATTR_DEF+":birthNumber", item.getFormItem().getPerunDestinationAttribute())) { // if application contains birth number, try to map to existing user String rc = item.getValue(); if (rc != null && !rc.isEmpty()) { try { User user = ((PerunBl) session.getPerun()).getUsersManagerBl().getUserByExtSourceNameAndExtLogin(session, "RC", rc); application.setUser(user); registrar.updateApplicationUser(session, application); } catch (Exception ex) { log.warn("Couldn't find or set user to application {} by RC: {}", application, ex); } } break; } } } return data; }
private Author convertAuthorToAuthorWithAttributes(Author author) { try { if (session == null) { session = perun.getPerunSession(new PerunPrincipal("perunCabinet", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient()); } User user = perun.getUsersManagerBl().getUserById(session, author.getId()); Attribute a = perun.getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":preferredMail"); Attribute b = perun.getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":organization"); author.setAttributes(Arrays.asList(a,b)); } catch (Exception ex) { log.error("Unable to get attributes for {}: {}", author, ex); } return author; }
User user = perun.getUsersManagerBl().getUserById(session, id); Attribute emailAttribute = perun.getAttributesManagerBl().getAttribute(session, user, "urn:perun:user:attribute-def:def:preferredMail"); if (emailAttribute != null && StringUtils.hasText(emailAttribute.toString())) {
@Override public void canBeApproved(PerunSession session, Application app) throws PerunException { // check if submitted from trusted IdP if (!Objects.equals("https://www.structuralbiology.eu/idp/shibboleth", app.getExtSourceName())) { // submitted by untrusted IdP PerunBl perun = (PerunBl) session.getPerun(); User user = null; // check if user is known if (app.getUser() != null) { user = app.getUser(); } else { try { user = perun.getUsersManagerBl().getUserByExtSourceNameAndExtLogin(session, app.getExtSourceName(), app.getCreatedBy()); } catch (Exception ex) { // unable to find user -> untrusted IdP throw new CantBeApprovedException("Application can't be approved automatically. User doesn't have identity from \"www.structuralbiology.eu\". Please check users identity before manual/force approval.", "", "", "", true); } } List<UserExtSource> ueses = perun.getUsersManagerBl().getUserExtSources(session, user); for (UserExtSource ues : ueses) { if (Objects.equals("https://www.structuralbiology.eu/idp/shibboleth", ues.getExtSource().getName())) { // user has trusted identity return; } } throw new CantBeApprovedException("Application can't be approved automatically. User doesn't have identity from \"www.structuralbiology.eu\". Please check users identity before manual/force approval.", "", "", "", true); } // submitted from trusted IdP }
if (pair.getLeft().equals(a.getFriendlyNameParameter())) { perun.getUsersManagerBl().deletePassword(registrarSession, pair.getRight(), pair.getLeft()); log.debug("[REGISTRAR] Unreserving new login: {} in namespace: {} since user already have login: {} in same namespace." , pair.getRight(), pair.getLeft(), a.getValue());
User user = perun.getUsersManagerBl().getUserById(session, id); Attribute emailAttribute = perun.getAttributesManagerBl().getAttribute(session, user, "urn:perun:user:attribute-def:def:jabber"); if (emailAttribute != null && StringUtils.hasText(emailAttribute.toString())) {
perun.getUsersManagerBl().addUserExtSource(session, user, userExtSource); } catch (UserExtSourceExistsException e) {
userOfMember = perun.getUsersManagerBl().getUserByMember(session, member); }catch(InternalErrorException ex){ throw new VOOTException("internal_server_error");
user = perun.getUsersManagerBl().getUserById(sess, userId); } catch (UserNotExistsException ex) { throw new CabinetException("User with ID: "+userId+" doesn't exists.", ErrorCodes.PERUN_EXCEPTION, ex); List<UserExtSource> ues = perun.getUsersManagerBl().getUserExtSources(sess, user); String authorId = ""; for (UserExtSource es : ues) {
BufferedWriter writer = perunInitializer.getOutputWriter(); List<User> users = perun.getUsersManagerBl().getUsers(perunSession); List<UserExtSource> userExtSources = perun.getUsersManagerBl().getUserExtSources(perunSession, user); List<String> extLogins = new ArrayList<>(); for(UserExtSource ues: userExtSources) {
/** * 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; }
perun.getUsersManagerBl().validatePasswordAndSetExtSources(registrarSession, app.getUser(), pair.getRight(), pair.getLeft()); UserExtSource ues = perun.getUsersManagerBl().getUserExtSourceByExtLogin(sess, es, app.getCreatedBy()); perun.getUsersManagerBl().validatePasswordAndSetExtSources(registrarSession, u, pair.getRight(), pair.getLeft()); perun.getUsersManagerBl().validatePasswordAndSetExtSources(registrarSession, app.getUser(), pair.getRight(), pair.getLeft());
if (perun.getUsersManagerBl().isLoginAvailable(registrarSession, loginNamespace, login)) { try { try { perun.getUsersManagerBl().reservePassword(registrarSession, login, loginNamespace, pass); log.debug("[REGISTRAR] Password for login: {} in namespace: {} successfully reserved in external system.", login, loginNamespace); } catch (Exception ex) {
perun.getUsersManagerBl().deletePassword(sess, login.getRight(), login.getLeft());