Add floating API

This commit is contained in:
René Pfeuffer
2019-02-14 16:36:06 +01:00
parent 75239a0104
commit 83076dba46
2 changed files with 46 additions and 4 deletions

View File

@@ -70,10 +70,9 @@ public final class GroupNames implements Serializable, Iterable<String>
* Constructs ...
*
*/
@SuppressWarnings("unchecked")
public GroupNames()
{
this(Collections.EMPTY_LIST);
this(Collections.emptyList());
}
/**

View File

@@ -80,6 +80,49 @@ public final class SyncingRealmHelper {
this.groupManager = groupManager;
}
public AuthenticationInfoBuilder.ForRealm authenticationInfo() {
return new AuthenticationInfoBuilder().new ForRealm();
}
public class AuthenticationInfoBuilder {
private String realm;
private User user;
private Collection<String> groups;
private boolean external;
private AuthenticationInfo build() {
return SyncingRealmHelper.this.createAuthenticationInfo(realm, user, groups, external);
}
public class ForRealm {
public ForUser forRealm(String realm) {
AuthenticationInfoBuilder.this.realm = realm;
return AuthenticationInfoBuilder.this.new ForUser();
}
}
public class ForUser {
public AuthenticationInfoBuilder.WithGroups andUser(User user) {
AuthenticationInfoBuilder.this.user = user;
return AuthenticationInfoBuilder.this.new WithGroups();
}
}
public class WithGroups {
public AuthenticationInfo withGroups(Collection<String> groups) {
AuthenticationInfoBuilder.this.groups = groups;
AuthenticationInfoBuilder.this.external = false;
return build();
}
public AuthenticationInfo withExternalGroups(Collection<String> groups) {
AuthenticationInfoBuilder.this.groups = groups;
AuthenticationInfoBuilder.this.external = false;
return build();
}
}
}
//~--- methods --------------------------------------------------------------
/**
* Create {@link AuthenticationInfo} from user and groups.
@@ -176,6 +219,6 @@ public final class SyncingRealmHelper {
}
}
});
}
});
}
}