// deferr notification of LoginClient in case
// a workspace wants to override the authentication or authorization scheme
private boolean deferredNotification;
public SecurityService() {
ErraiBus.get().subscribe(SUBJECT, new MessageCallback() {
public void callback(Message msg) {
switch (SecurityCommands.valueOf(msg.getCommandType())) {
case AuthenticationScheme:
if (authHandler == null) {
// msg.toSubject("LoginClient").sendNowWith(ErraiBus.get());
return;
}
String credentialsRequired = msg.get(String.class, CredentialsRequired);
String[] credentialNames = credentialsRequired.split(",");
Credential[] credentials = new Credential[credentialNames.length];
for (int i = 0; i < credentialNames.length; i++) {
switch (CredentialTypes.valueOf(credentialNames[i])) {
case Name:
credentials[i] = new NameCredential();
break;
case Password:
credentials[i] = new PasswordCredential();
break;
default:
//todo: throw a massive error here.
}
}
// callback on externally provided login form
// asking for the required credentials specified on the server side.
authHandler.doLogin(credentials);
// Create an authentication request and send the credentials
Message challenge = createMessage()
.toSubject("AuthenticationService")
.command(SecurityCommands.AuthRequest)
.with(MessageParts.ReplyTo, SUBJECT)
.getMessage();
for (int i = 0; i < credentialNames.length; i++) {
switch (CredentialTypes.valueOf(credentialNames[i])) {
case Name:
challenge.set(CredentialTypes.Name, credentials[i].getValue());
break;
case Password:
challenge.set(CredentialTypes.Password, credentials[i].getValue());
break;
}
}
challenge.sendNowWith(ErraiBus.get());
break;
case AuthenticationNotRequired:
notifyLoginClient(msg);
break;
case FailedAuth:
notifyLoginClient(msg);
break;
case SuccessfulAuth:
if (authenticationContext != null && authenticationContext.isValid()) return;
authenticationContext = createAuthContext(msg);
notifyLoginClient(msg);
break;
}
}
});
// listener for the authorization assignment
ErraiBus.get().subscribe("AuthorizationListener",
new MessageCallback() {
public void callback(Message message) {
authenticationContext = createAuthContext(message);
if (!deferredNotification) {