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.

Storing Parties

You can store new parties with PartyRepository#save method:

public Party createJohnGult() {
    Party johnGult = new DefaultParty();
    johnGult.setName("John Gult");

Retrieving Parties

Retrieve the current party:


This method will return Optional with the party inside.

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

public Optional<Party> findJohnGult() {
    return partyRepository.findOneByEmail("");

public Optional<Party> findById(String id) {
    return partyRepository.findOneById(id);
public Iterable<Party> getAllParties() {
    return partyRepository.findAll();

Removing Parties

Removing party is as simple as invoking PartyRepository#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 = playAuthApi.getPartyRoleManager().create("Administrator");

Retrieving Roles

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

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
playAuthApi.getCurrentParty().ifPresent(p -> p.addRole(someRole));
// Remove a role from the current subject
playAuthApi.getCurrentParty().ifPresent(p -> p.removeRole(someRole));
// Check if the current subject has a role assigned
playAuthApi.getCurrentParty().map(p -> p.hasRole(someRole)).orElse(false);
// Get all roles
Collection<PartyRole> myRoles = playAuthApi.getCurrentParty().map(Party::getRoles).orElse(Collections.empty());