The Party entity

The interface is used to represents essential information about people and organizations.

Play Auth has a default implementation of Party interface - DefaultParty. End users may extend this class.

Creating Parties

You can create create new parties with PartyManager.create factory method which also persist newly created parties:

public Party createJohnGult() {
    Collection<Object> principals = new HashSet<Object>();
    principals.add(new EmailAddress(""));
    Party p = PlayAuth.getPartyManager().create("John Gult", principals, "secretword");
    return p;

Play Auth comes with a default implementation of PartyManager interface -  DefaultPartyManager.

By default the PartyManager.create factory method will create an instance of which can be changed by overriding the method PartyManager.getPartyClass. The PartyManager itself can be overridden by defining custom Dependency Injection bindings.

Retrieving Parties

Retrieve the current party:



Note: Returns null if no party is available.

Here are some examples on how to retrieve parties using PartyManager.find* methods:

public Party findJohnGult() {
    Party p = PlayAuth.getPartyManager().findOneByPrincipal("");
    return p;
 * @param idOrEmail may be: String email or id, Long id, EmailAddress or PartyIdentifier
public Party findByIdOrEmail(Object idOrEmail) {
    Party p = PlayAuth.getPartyManager().findOneByPrincipal(idOrEmail);
    return p;
public Collection<Party> getAllParties() {
    return PlayAuth.getPartyManager().findAll();


Removing Parties

Removing party is as simple as invoking PartyManager.delete method:



Party Role

The party roles are intended to simply store common patterns of domain permissions, they have no other special meaning, so the application code must NOT rely on the assigned party roles.

Creating Roles

You can create create new roles with PartyRoleManager.create factory method which also persist newly created entities:

PartyRole admin = PlayAuth.getPartyRoleManager().create("Administrator");


Retrieving Roles

You can retrieve a specific role by its name or identifier, or get all roles at once:

PartyRole admin = PlayAuth.getPartyRoleManager().findByName("Administrator");
Collection<PartyRole> roles = PlayAuth.getPartyRoleManager().findAll();


Finding parties that have a role



Removing Roles

Removing role is as simple as invoking  PartyRoleManager.delete method:



Role handling per party

// Add a role to the current party
// Remove a role from the current subject
// Check if the current subject has a role assigned
// Get all roles
Collection<PartyRole> myRoles = PlayAuth.getCurrentParty().getRoles();