Search in sources :

Example 1 with ApplicationRole

use of org.isisaddons.module.security.dom.role.ApplicationRole in project estatio by estatio.

the class AbstractUserRoleFixtureScript method addUserToRole.

protected ApplicationUser addUserToRole(final String userName, final String roleName, final ExecutionContext executionContext) {
    final ApplicationUser user = applicationUserRepository.findOrCreateUserByUsername(userName);
    final ApplicationRole applicationRole = applicationRoleRepository.findByName(roleName);
    if (applicationRole == null) {
        throw new IllegalArgumentException(String.format("Role [%s] not found", roleName));
    }
    user.addRole(applicationRole);
    executionContext.addResult(this, roleName, applicationRole);
    return user;
}
Also used : ApplicationUser(org.isisaddons.module.security.dom.user.ApplicationUser) ApplicationRole(org.isisaddons.module.security.dom.role.ApplicationRole)

Example 2 with ApplicationRole

use of org.isisaddons.module.security.dom.role.ApplicationRole in project estatio by estatio.

the class EstatioSecurityModuleFixturesMenu method installFixturesAndReturnFirstRole.

// //////////////////////////////////////
@Action(semantics = SemanticsOf.NON_IDEMPOTENT, restrictTo = RestrictTo.PROTOTYPING)
@ActionLayout(cssClassFa = "fa-bolt")
@MemberOrder(sequence = "20")
public Object installFixturesAndReturnFirstRole() {
    final List<FixtureResult> fixtureResultList = fixtureScripts.findFixtureScriptFor(EstatioSecurityModuleSeedFixture.class).run(null);
    for (FixtureResult fixtureResult : fixtureResultList) {
        final Object object = fixtureResult.getObject();
        if (object instanceof ApplicationRole) {
            return object;
        }
    }
    container.warnUser("No rules found in fixture; returning all results");
    return fixtureResultList;
}
Also used : FixtureResult(org.apache.isis.applib.fixturescripts.FixtureResult) ApplicationRole(org.isisaddons.module.security.dom.role.ApplicationRole) EstatioSecurityModuleSeedFixture(org.estatio.module.base.seed.EstatioSecurityModuleSeedFixture) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

ApplicationRole (org.isisaddons.module.security.dom.role.ApplicationRole)2 Action (org.apache.isis.applib.annotation.Action)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)1 FixtureResult (org.apache.isis.applib.fixturescripts.FixtureResult)1 EstatioSecurityModuleSeedFixture (org.estatio.module.base.seed.EstatioSecurityModuleSeedFixture)1 ApplicationUser (org.isisaddons.module.security.dom.user.ApplicationUser)1