return this;
}
public SubjectSupplemental getSubjectSupplemental(Map<String, Object> sharedState) {
final String name = getPlugInName();
final AuthorizationPlugIn ap = getPlugInLoader().loadAuthorizationPlugIn(name);
if (ap instanceof PlugInConfigurationSupport) {
PlugInConfigurationSupport pcf = (PlugInConfigurationSupport) ap;
try {
pcf.init(getConfiguration(), sharedState);
} catch (IOException e) {
throw MESSAGES.unableToInitialisePlugIn(name, e.getMessage());
}
}
return new SubjectSupplemental() {
public void supplementSubject(Subject subject) throws IOException {
Set<RealmUser> users = subject.getPrincipals(RealmUser.class);
Set<Principal> principals = subject.getPrincipals();
// In general we expect exactly one RealmUser, however we could cope with multiple
// identities so load the roles for them all.
for (RealmUser current : users) {
principals.addAll(loadRoles(current));
}
}
private Set<RealmRole> loadRoles(final RealmUser user) throws IOException {
Set<RealmRole> response;
String[] roles = ap.loadRoles(user.getName(), getRealmName());
response = new HashSet<RealmRole>(roles.length);
for (String current : roles) {
response.add(new RealmRole(current));
}
return response;