use of org.eclipse.ecf.core.security.Callback 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;
}
use of org.eclipse.ecf.core.security.Callback 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);
}
}
use of org.eclipse.ecf.core.security.Callback in project ecf by eclipse.
the class XMPPChatRoomContainer method connect.
public void connect(ID remote, IConnectContext connectContext) throws ContainerConnectException {
if (!(remote instanceof XMPPRoomID)) {
throw new ContainerConnectException(NLS.bind(Messages.XMPPChatRoomContainer_Exception_Connect_Wrong_Type, remote));
}
final XMPPRoomID roomID = (XMPPRoomID) remote;
fireContainerEvent(new ContainerConnectingEvent(this.getID(), remote, connectContext));
synchronized (getConnectLock()) {
try {
connectionState = CONNECTING;
remoteServerID = null;
addSharedObjectToContainer(remote);
multiuserchat = new MultiUserChat(getXMPPConnection(), roomID.getMucString());
// Get nickname from join context
String nick = null;
try {
final Callback[] callbacks = new Callback[1];
callbacks[0] = new NameCallback(Messages.XMPPChatRoomContainer_NAME_CALLBACK_NICK, roomID.getNickname());
if (connectContext != null) {
final CallbackHandler handler = connectContext.getCallbackHandler();
if (handler != null) {
handler.handle(callbacks);
}
}
if (callbacks[0] instanceof NameCallback) {
final NameCallback cb = (NameCallback) callbacks[0];
nick = cb.getName();
}
} catch (final Exception e) {
throw new ContainerConnectException(Messages.XMPPChatRoomContainer_EXCEPTION_CALLBACKHANDLER, e);
}
String nickname = null;
if (// $NON-NLS-1$
nick == null || nick.equals(""))
nickname = roomID.getNickname();
else
nickname = nick;
multiuserchat.addSubjectUpdatedListener(new SubjectUpdatedListener() {
public void subjectUpdated(String subject, String from) {
fireSubjectUpdated(subject, from);
}
});
multiuserchat.addMessageListener(new PacketListener() {
public void processPacket(Packet arg0) {
handleXMPPMessage(arg0);
}
});
multiuserchat.addParticipantListener(new PacketListener() {
public void processPacket(Packet arg0) {
handleXMPPMessage(arg0);
}
});
multiuserchat.addParticipantStatusListener(new ParticipantStatusListener() {
public void joined(String arg0) {
handleChatMembershipEvent(arg0, true);
}
public void left(String arg0) {
handleChatMembershipEvent(arg0, false);
}
public void voiceGranted(String arg0) {
// TODO Auto-generated method stub
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("voiceGranted(" + arg0 + ")");
}
public void voiceRevoked(String arg0) {
// TODO Auto-generated method stub
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("voiceRevoked(" + arg0 + ")");
}
public void membershipGranted(String arg0) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"membershipGranted(" + arg0 + // $NON-NLS-1$
")");
}
public void membershipRevoked(String arg0) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"membershipRevoked(" + arg0 + // $NON-NLS-1$
")");
}
public void moderatorGranted(String arg0) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"moderatorGranted(" + arg0 + // $NON-NLS-1$
")");
}
public void moderatorRevoked(String arg0) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"moderatorRevoked(" + arg0 + // $NON-NLS-1$
")");
}
public void ownershipGranted(String arg0) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"ownershipGranted(" + arg0 + // $NON-NLS-1$
")");
}
public void ownershipRevoked(String arg0) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"ownershipRevoked(" + arg0 + // $NON-NLS-1$
")");
}
public void adminGranted(String arg0) {
// TODO Auto-generated method stub
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("adminGranted(" + arg0 + ")");
}
public void adminRevoked(String arg0) {
// TODO Auto-generated method stub
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("adminRevoked(" + arg0 + ")");
}
public void kicked(String arg0, String arg1, String arg2) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
"kicked(" + arg0 + "," + arg1 + "," + arg2 + // $NON-NLS-1$ //$NON-NLS-2$
")");
}
public void banned(String arg0, String arg1, String arg2) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
"banned(" + arg0 + "," + arg1 + "," + arg2 + // $NON-NLS-1$ //$NON-NLS-2$
")");
}
public void nicknameChanged(String arg0, String arg1) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"nicknameChanged(" + arg0 + "," + arg1 + // $NON-NLS-1$ //$NON-NLS-2$
")");
}
});
multiuserchat.addInvitationRejectionListener(new InvitationRejectionListener() {
public void invitationDeclined(String arg0, String arg1) {
// TODO Auto-generated method stub
System.out.println(// $NON-NLS-1$
"invitationDeclined(" + arg0 + "," + arg1 + // $NON-NLS-1$ //$NON-NLS-2$
")");
}
});
multiuserchat.join(nickname);
connectionState = CONNECTED;
remoteServerID = roomID;
containerHelper.setRoomID(remoteServerID);
fireContainerEvent(new ContainerConnectedEvent(this.getID(), roomID));
} catch (final Exception e) {
cleanUpConnectFail();
final ContainerConnectException ce = new ContainerConnectException(NLS.bind(Messages.XMPPChatRoomContainer_EXCEPTION_JOINING_ROOM, roomID));
ce.setStackTrace(e.getStackTrace());
throw ce;
}
}
}
Aggregations