Package org.openstreetmap.josm.gui

Examples of org.openstreetmap.josm.gui.JosmUserIdentityManager


     * Refreshes the user info from the server. This is necessary if we don't know
     * the users id yet.
     *
     */
    protected void refreshUserIdentity(){
        JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
        try {
            OsmServerUserInfoReader infoReader = new OsmServerUserInfoReader();
            UserInfo info = infoReader.fetchUserInfo(getProgressMonitor().createSubTaskMonitor(1, false));
            im.setFullyIdentified(info.getDisplayName(), info);
        } catch(OsmTransferException e) {
            // retrieving the user info can fail if the current user is not authorised to
            // retrieve it, i.e. if he is working with an OAuth Access Token which doesn't
            // have the respective privileges or if he didn't or he can't authenticate with
            // a username/password-pair.
            //
            // Downgrade your knowlege about its identity if we've assumed that he was fully
            // identified. Otherwise, if he is anonymous or partially identified, keep our level
            // of knowlege.
            //
            if (im.isFullyIdentified()) {
                im.setPartiallyIdentified(im.getUserName());
            }
            Main.warn(tr("Failed to retrieve user infos for the current JOSM user. Exception was: {0}", e.toString()));
        }
    }
View Full Code Here


    }

    @Override
    protected void realRun() throws SAXException, IOException, OsmTransferException {
        try {
            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
            if (im.isAnonymous()) {
                refreshUserIdentity();
            } else if (im.isFullyIdentified()){
                // do nothing
            } else if (im.isPartiallyIdentified()) {
                refreshUserIdentity();
            }
            if (canceled)return;
            synchronized(this) {
                reader = new OsmServerChangesetReader();
            }
            ChangesetQuery query = new ChangesetQuery().beingOpen(true);
            if (im.isAnonymous())
                // we still don't know anything about the current user. Can't retrieve
                // its changesets
                return;
            else if (im.isFullyIdentified()) {
                query = query.forUser(im.getUserId());
            } else {
                // we only know the users name, not its id. Nevermind, try to read
                // its open changesets anyway.
                //
                query = query.forUser(im.getUserName());
            }
            changesets = reader.queryChangesets(
                    query,
                    getProgressMonitor().createSubTaskMonitor(1, false /* not internal */)
            );
View Full Code Here

     * Determines if user set enough information in JOSM preferences to make the request to OSM API without
     * prompting him for a password.
     * @return {@code true} if user chose an OAuth token or supplied both its username and password, {@code false otherwise}
     */
    public static boolean isUserEnoughIdentified() {
        JosmUserIdentityManager identManager = JosmUserIdentityManager.getInstance();
        if (identManager.isFullyIdentified()) {
            return true;
        } else {
            CredentialsManager credManager = CredentialsManager.getInstance();
            try {
                if (JosmPreferencesCredentialAgent.class.equals(credManager.getCredentialsAgentClass())) {
View Full Code Here

            Main.worker.submit(new CloseChangesetTask(selected));
        }

        protected void updateEnabledState() {
            List<Changeset> selected = model.getSelectedChangesets();
            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
            for (Changeset cs: selected) {
                if (cs.isOpen()) {
                    if (im.isPartiallyIdentified() && cs.getUser() != null && cs.getUser().getName().equals(im.getUserName())) {
                        setEnabled(true);
                        return;
                    }
                    if (im.isFullyIdentified() && cs.getUser() != null && cs.getUser().getId() == im.getUserId()) {
                        setEnabled(true);
                        return;
                    }
                }
            }
View Full Code Here

            );
        }

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
            if (im.isAnonymous()) {
                alertAnonymousUser();
                return;
            }
            ChangesetQuery query = new ChangesetQuery();
            if (im.isFullyIdentified()) {
                query = query.forUser(im.getUserId());
            } else {
                query = query.forUser(im.getUserName());
            }
            ChangesetQueryTask task = new ChangesetQueryTask(ChangesetCacheManager.this, query);
            ChangesetCacheManager.getInstance().runDownloadTask(task);
        }
View Full Code Here

         *
         */
        public void fillInQuery(ChangesetQuery query) throws IllegalStateException, IllegalArgumentException  {
            CheckParameterUtil.ensureParameterNotNull(query, "query");
            if (rbRestrictToMyself.isSelected()) {
                JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
                if (im.isPartiallyIdentified()) {
                    query.forUser(im.getUserName());
                } else if (im.isFullyIdentified()) {
                    query.forUser(im.getUserId());
                } else
                    throw new IllegalStateException(tr("Cannot restrict changeset query to the current user because the current user is anonymous"));
            } else if (rbRestrictToUid.isSelected()) {
                int uid  = valUid.getUid();
                if (uid > 0) {
View Full Code Here

        public void restoreFromSettings() {
            String prefRoot = "changeset-query.advanced.user-restrictions";
            String v = Main.pref.get(prefRoot + ".query-type", "mine");
            if ("mine".equals(v)) {
                JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
                if (im.isAnonymous()) {
                    rbRestrictToUid.setSelected(true);
                } else {
                    rbRestrictToMyself.setSelected(true);
                }
            } else if ("uid".equals(v)) {
View Full Code Here

        }
        UserInfo info = userInfoReader.fetchUserInfo(getProgressMonitor().createSubTaskMonitor(1,false));
        synchronized(this) {
            userInfoReader = null;
        }
        JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
        im.setFullyIdentified(im.getUserName(), info);
    }
View Full Code Here

    }

    @Override
    protected void realRun() throws SAXException, IOException, OsmTransferException {
        try {
            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
            if (query.isRestrictedToPartiallyIdentifiedUser() && im.isCurrentUser(query.getUserName())) {
                // if we query changesets for the current user, make sure we query against
                // its user id, not its user name. If necessary, determine the user id
                // first.
                //
                if (im.isPartiallyIdentified() ) {
                    fullyIdentifyCurrentUser();
                }
                query = query.forUser(JosmUserIdentityManager.getInstance().getUserId());
            }
            if (canceled) return;
View Full Code Here

    }

    public ChangesetQuery buildChangesetQuery() {
        BasicQuery q = getSelectedQuery();
        ChangesetQuery query = new ChangesetQuery();
        JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
        if (q == null)
            return query;
        switch(q) {
        case MOST_RECENT_CHANGESETS:
            break;
        case MY_OPEN_CHANGESETS:
            query = query.beingOpen(true);
            break;
        case CHANGESETS_IN_MAP_VIEW:
            Bounds b = Main.map.mapView.getLatLonBounds(Main.map.mapView.getBounds());
            query = query.inBbox(b);
            break;
        }

        if (cbMyChangesetsOnly.isSelected()) {
            if (im.isPartiallyIdentified()) {
                query = query.forUser(im.getUserName());
            } else if (im.isFullyIdentified()) {
                query = query.forUser(im.getUserId()).beingOpen(true);
            } else
                // anonymous -- can happen with a fresh config.
                throw new IllegalStateException(tr("Cannot create changeset query for open changesets of anonymous user"));
        }
View Full Code Here

TOP

Related Classes of org.openstreetmap.josm.gui.JosmUserIdentityManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.