Search in sources :

Example 1 with ObjectCallback

use of org.eclipse.ecf.core.security.ObjectCallback in project ecf by eclipse.

the class HttpClientFileSystemBrowser method getFileRequestCredentials.

/**
 * Retrieves the credentials for requesting the file.
 * @return the {@link Credentials} necessary to retrieve the file
 * @throws UnsupportedCallbackException if the callback fails
 * @throws IOException if IO fails
 * @since 5.0
 */
protected Credentials getFileRequestCredentials() throws UnsupportedCallbackException, IOException {
    if (connectContext == null)
        return null;
    final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
    if (callbackHandler == null)
        return null;
    final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
    final ObjectCallback passwordCallback = new ObjectCallback();
    callbackHandler.handle(new Callback[] { usernameCallback, passwordCallback });
    username = usernameCallback.getName();
    password = (String) passwordCallback.getObject();
    return new UsernamePasswordCredentials(username, password);
}
Also used : CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) NameCallback(org.eclipse.ecf.core.security.NameCallback) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with ObjectCallback

use of org.eclipse.ecf.core.security.ObjectCallback in project ecf by eclipse.

the class HttpClientRetrieveFileTransfer method getFileRequestCredentials.

/**
 * @return Credentials file request credentials
 * @throws UnsupportedCallbackException if some problem
 * @throws IOException if some problem
 * @since 5.0
 */
protected Credentials getFileRequestCredentials() throws UnsupportedCallbackException, IOException {
    if (connectContext == null)
        return null;
    final CallbackHandler callbackHandler = connectContext.getCallbackHandler();
    if (callbackHandler == null)
        return null;
    final NameCallback usernameCallback = new NameCallback(USERNAME_PREFIX);
    final ObjectCallback passwordCallback = new ObjectCallback();
    callbackHandler.handle(new Callback[] { usernameCallback, passwordCallback });
    username = usernameCallback.getName();
    password = (String) passwordCallback.getObject();
    return new UsernamePasswordCredentials(username, password);
}
Also used : CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) NameCallback(org.eclipse.ecf.core.security.NameCallback) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 3 with ObjectCallback

use of org.eclipse.ecf.core.security.ObjectCallback in project ecf by eclipse.

the class XMPPContainer method createAuthorizationCallbacks.

protected Callback[] createAuthorizationCallbacks() {
    final Callback[] cbs = new Callback[1];
    cbs[0] = new ObjectCallback();
    return cbs;
}
Also used : Callback(org.eclipse.ecf.core.security.Callback) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback)

Example 4 with ObjectCallback

use of org.eclipse.ecf.core.security.ObjectCallback in project ecf by eclipse.

the class AbstractBBContainer method getCredentialsFromConnectContext.

protected IBBCredentials getCredentialsFromConnectContext(IConnectContext connectContext) throws ContainerConnectException {
    try {
        if (connectContext == null) {
            return null;
        }
        Callback[] callbacks = new Callback[2];
        callbacks[0] = new NameCallback("Username");
        callbacks[1] = new ObjectCallback();
        CallbackHandler handler = connectContext.getCallbackHandler();
        if (handler != null) {
            handler.handle(callbacks);
        }
        NameCallback nc = (NameCallback) callbacks[0];
        ObjectCallback cb = (ObjectCallback) callbacks[1];
        return new Credentials(nc.getName(), (String) cb.getObject());
    } catch (Exception e) {
        throw new ContainerConnectException("Exception in CallbackHandler.handle(<callbacks>)", e);
    }
}
Also used : CallbackHandler(org.eclipse.ecf.core.security.CallbackHandler) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) Callback(org.eclipse.ecf.core.security.Callback) NameCallback(org.eclipse.ecf.core.security.NameCallback) NameCallback(org.eclipse.ecf.core.security.NameCallback) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) IBBCredentials(org.eclipse.ecf.bulletinboard.IBBCredentials) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) BBException(org.eclipse.ecf.bulletinboard.BBException)

Example 5 with ObjectCallback

use of org.eclipse.ecf.core.security.ObjectCallback in project ecf by eclipse.

the class MSNContainer method connect.

public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException {
    if (!(targetID instanceof MSNID)) {
        throw new ContainerConnectException(Messages.MSNContainer_TargetIDNotMSNID);
    }
    client = new MsnClient();
    ObjectCallback[] cb = { new ObjectCallback() };
    try {
        connectContext.getCallbackHandler().handle(cb);
        client.addSessionListener(new ISessionListener() {

            public void sessionConnected(ChatSession session) {
                try {
                    Contact contact = session.getParticipants()[0];
                    final ID toID = namespace.createInstance(new Object[] { contact.getEmail() });
                    chatSessions.put(toID, session);
                    session.addChatSessionListener(new ChatSessionListener(toID));
                } catch (IDCreateException e) {
                // ignored since this should not be possible
                }
            }
        });
        client.getContactList().addContactListListener(new IContactListListener() {

            public void contactAdded(Contact contact) {
                final MSNRosterEntry entry = new MSNRosterEntry(MSNContainer.this, contact, namespace);
                for (int i = 0; i < entries.size(); i++) {
                    Object e = entries.get(i);
                    if (e instanceof MSNRosterGroup) {
                        MSNRosterGroup group = (MSNRosterGroup) e;
                        if (group.getGroup().contains(contact)) {
                            MSNRosterEntry check = group.getEntryFor(contact);
                            if (check == null) {
                                check = entry;
                                contact.addContactListener(new IContactListener() {

                                    public void nameChanged(String name) {
                                        firePresence(entry.getID(), entry.getPresence());
                                        fireRosterUpdate(entry);
                                    }

                                    public void personalMessageChanged(String personalMessage) {
                                        entry.updatePersonalMessage();
                                        firePresence(entry.getID(), entry.getPresence());
                                        fireRosterUpdate(entry);
                                    }

                                    public void statusChanged(Status status) {
                                        firePresence(entry.getID(), entry.getPresence());
                                        fireRosterUpdate(entry);
                                    }
                                });
                                group.add(check);
                                fireRosterEntryAdded(check);
                            }
                            fireRosterUpdate(group);
                            return;
                        }
                    } else {
                        MSNRosterEntry check = (MSNRosterEntry) e;
                        if (entry.getContact().equals(check.getContact())) {
                            fireRosterEntryAdded(check);
                            fireRosterUpdate(check.getParent());
                            return;
                        }
                    }
                }
                contact.addContactListener(new IContactListener() {

                    public void nameChanged(String name) {
                        firePresence(entry.getID(), entry.getPresence());
                        fireRosterUpdate(entry);
                    }

                    public void personalMessageChanged(String personalMessage) {
                        entry.updatePersonalMessage();
                        firePresence(entry.getID(), entry.getPresence());
                        fireRosterUpdate(entry);
                    }

                    public void statusChanged(Status status) {
                        firePresence(entry.getID(), entry.getPresence());
                        fireRosterUpdate(entry);
                    }
                });
                entries.add(entry);
                entry.setParent(MSNContainer.this);
                fireRosterEntryAdded(entry);
                fireRosterUpdate(MSNContainer.this);
            }

            public void contactRemoved(Contact contact) {
                MSNRosterEntry entry = findEntry(entries, contact.getEmail());
                if (entry != null) {
                    fireHandleUnsubscribed(entry.getUser().getID());
                    fireRosterEntryRemoved(entry);
                    fireRosterUpdate(entry.getParent());
                    if (entry.getContact().getGroups().isEmpty()) {
                        entry.setParent(MSNContainer.this);
                        fireRosterUpdate(MSNContainer.this);
                    }
                }
            }

            public void contactAddedUser(String email) {
                try {
                    fireHandleSubscriptionRequest(namespace.createInstance(new Object[] { email }));
                } catch (IDCreateException e) {
                // ignored
                }
            }

            public void contactRemovedUser(String email) {
            // nothing to do
            }

            public void groupAdded(Group group) {
                entries.add(new MSNRosterGroup(MSNContainer.this, group));
            }
        });
        fireContainerEvent(new ContainerConnectingEvent(guid, targetID));
        client.connect(targetID.getName(), (String) cb[0].getObject());
        connectID = (MSNID) targetID;
        fireContainerEvent(new ContainerConnectedEvent(guid, connectID));
        Activator.getDefault().registerService(this);
    } catch (UnsupportedCallbackException e) {
        throw new ContainerConnectException(e);
    } catch (IOException e) {
        throw new ContainerConnectException(e);
    }
}
Also used : Status(org.eclipse.ecf.protocol.msn.Status) Group(org.eclipse.ecf.protocol.msn.Group) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ObjectCallback(org.eclipse.ecf.core.security.ObjectCallback) ContainerConnectedEvent(org.eclipse.ecf.core.events.ContainerConnectedEvent) ISessionListener(org.eclipse.ecf.protocol.msn.events.ISessionListener) IContactListener(org.eclipse.ecf.protocol.msn.events.IContactListener) IOException(java.io.IOException) ChatSession(org.eclipse.ecf.protocol.msn.ChatSession) Contact(org.eclipse.ecf.protocol.msn.Contact) IChatSessionListener(org.eclipse.ecf.protocol.msn.events.IChatSessionListener) MsnClient(org.eclipse.ecf.protocol.msn.MsnClient) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IContactListListener(org.eclipse.ecf.protocol.msn.events.IContactListListener) ContainerConnectingEvent(org.eclipse.ecf.core.events.ContainerConnectingEvent) ID(org.eclipse.ecf.core.identity.ID) UnsupportedCallbackException(org.eclipse.ecf.core.security.UnsupportedCallbackException)

Aggregations

ObjectCallback (org.eclipse.ecf.core.security.ObjectCallback)7 CallbackHandler (org.eclipse.ecf.core.security.CallbackHandler)5 NameCallback (org.eclipse.ecf.core.security.NameCallback)5 UnsupportedCallbackException (org.eclipse.ecf.core.security.UnsupportedCallbackException)3 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)2 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)2 Callback (org.eclipse.ecf.core.security.Callback)2 IOException (java.io.IOException)1 BBException (org.eclipse.ecf.bulletinboard.BBException)1 IBBCredentials (org.eclipse.ecf.bulletinboard.IBBCredentials)1 ContainerConnectedEvent (org.eclipse.ecf.core.events.ContainerConnectedEvent)1 ContainerConnectingEvent (org.eclipse.ecf.core.events.ContainerConnectingEvent)1 ID (org.eclipse.ecf.core.identity.ID)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 IRosterGroup (org.eclipse.ecf.presence.roster.IRosterGroup)1 ChatSession (org.eclipse.ecf.protocol.msn.ChatSession)1 Contact (org.eclipse.ecf.protocol.msn.Contact)1 Group (org.eclipse.ecf.protocol.msn.Group)1 MsnClient (org.eclipse.ecf.protocol.msn.MsnClient)1 Status (org.eclipse.ecf.protocol.msn.Status)1