class DefaultServices implements BootstrapExecution
{
public void execute(final BootstrapContext context)
{
final ServerMessageBus bus = context.getBus();
final boolean authenticationConfigured =
context.getConfig().getResource(AuthenticationAdapter.class) != null;
bus.subscribe(ErraiService.AUTHORIZATION_SVC_SUBJECT, new MessageCallback() {
public void callback(Message message) {
switch (SecurityCommands.valueOf(message.getCommandType())) {
case AuthenticationScheme:
if (authenticationConfigured) {
/**
* Respond with what credentials the authentication system requires.
*/
//todo: we only support login/password for now
createConversation(message)
.subjectProvided()
.command(SecurityCommands.AuthenticationScheme)
.with(SecurityParts.CredentialsRequired, "Name,Password")
.with(MessageParts.ReplyTo, ErraiService.AUTHORIZATION_SVC_SUBJECT)
.noErrorHandling().sendNowWith(bus);
} else {
createConversation(message)
.subjectProvided()
.command(SecurityCommands.AuthenticationNotRequired)
.noErrorHandling().sendNowWith(bus);
}
break;
case AuthRequest:
/**
* Receive a challenge.
*/
if (authenticationConfigured) {
try {
context.getConfig().getResource(AuthenticationAdapter.class)
.challenge(message);
}
catch (AuthenticationFailedException a) {
}
}
break;
case EndSession:
if (authenticationConfigured) {
context.getConfig().getResource(AuthenticationAdapter.class)
.endSession(message);
}
// reply in any case
createConversation(message)
.toSubject("LoginClient")
.command(SecurityCommands.EndSession)
.noErrorHandling()
.sendNowWith(bus);
break;
}
}
});
/**
* The standard ServerEchoService.
*/
bus.subscribe(ErraiService.SERVER_ECHO_SERVICE, new MessageCallback() {
public void callback(Message c) {
MessageBuilder.createConversation(c)
.subjectProvided().signalling().noErrorHandling()
.sendNowWith(bus);
}
});
bus.subscribe(ErraiService.AUTHORIZATION_SERVICE, new MessageCallback() {
public void callback(Message message) {
AuthSubject subject = message.getResource(QueueSession.class, "Session")
.getAttribute(AuthSubject.class, ErraiService.SESSION_AUTH_DATA);
Message reply = MessageBuilder.createConversation(message).getMessage();