Search in sources :

Example 1 with Role

use of fi.otavanopisto.pyramus.domainmodel.users.Role in project pyramus by otavanopisto.

the class EnvironmentPermissionResolver method hasPermission.

@Override
public boolean hasPermission(Permission permission, ContextReference contextReference, User user) {
    fi.otavanopisto.pyramus.domainmodel.users.User userEntity = getUser(user);
    if (userEntity == null) {
        return hasEveryonePermission(permission, contextReference);
    }
    boolean allowed = false;
    if (PermissionScope.COURSE.equals(permission.getScope()) && (contextReference != null)) {
        Course course = resolveCourse(contextReference);
        if (course != null) {
            allowed = hasCourseAccess(course, userEntity, permission);
        }
    }
    Role environmentRole = userEntity.getRole();
    allowed = allowed || environmentUserRolePermissionDAO.hasEnvironmentPermissionAccess(environmentRole, permission) || hasEveryonePermission(permission, contextReference);
    PyramusPermissionCollection collection = findCollection(permission.getName());
    try {
        PermissionFeature[] features = collection.listPermissionFeatures(permission.getName());
        if (features != null) {
            for (PermissionFeature feature : features) {
                Instance<PermissionFeatureHandler> instance = featureHandlers.select(new PermissionFeatureLiteral(feature.value()));
                if (!instance.isUnsatisfied()) {
                    PermissionFeatureHandler permissionFeatureHandler = instance.get();
                    allowed = permissionFeatureHandler.hasPermission(permission.getName(), userEntity, contextReference, allowed);
                } else
                    logger.log(Level.SEVERE, String.format("Unsatisfied permission feature %s", feature.value()));
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, String.format("Could not list permission features for permission %s", permission), e);
    }
    return allowed;
}
Also used : PermissionFeatureLiteral(fi.otavanopisto.security.PermissionFeatureLiteral) PermissionFeatureHandler(fi.otavanopisto.security.PermissionFeatureHandler) Role(fi.otavanopisto.pyramus.domainmodel.users.Role) PermissionFeature(fi.otavanopisto.security.PermissionFeature) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 2 with Role

use of fi.otavanopisto.pyramus.domainmodel.users.Role in project pyramus by otavanopisto.

the class MuikkuRestServiceTestsIT method testCreateStaffMember.

@Test
public void testCreateStaffMember() {
    Role testStaffMemberRole = Role.MANAGER;
    StaffMemberPayload payload = new StaffMemberPayload();
    payload.setIdentifier(null);
    payload.setRole(testStaffMemberRole.toString());
    payload.setFirstName("Muikku");
    payload.setLastName("Manager");
    payload.setEmail("muikkumanager@example.com");
    Response response = given().headers(getAuthHeaders()).contentType("application/json").body(payload).post("/muikku/users");
    response.then().statusCode(200).body("identifier", not(is((Long) null))).body("firstName", is(payload.getFirstName())).body("lastName", is(payload.getLastName())).body("email", is(payload.getEmail())).body("role", is(testStaffMemberRole.toString()));
    long staffMemberId = response.body().jsonPath().getLong("identifier");
    long personId = getStaffMemberPersonId(staffMemberId);
    given().headers(getAuthHeaders()).delete("/staff/members/{ID}?permanent=true", staffMemberId).then().statusCode(204);
    given().headers(getAuthHeaders()).delete("/persons/persons/{ID}", personId).then().statusCode(204);
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) Response(io.restassured.response.Response) StaffMemberPayload(fi.otavanopisto.pyramus.rest.model.muikku.StaffMemberPayload) Test(org.junit.Test)

Example 3 with Role

use of fi.otavanopisto.pyramus.domainmodel.users.Role in project pyramus by otavanopisto.

the class MuikkuRestServiceTestsIT method testCreateStaffMemberWithReservedEmail.

@Test
public void testCreateStaffMemberWithReservedEmail() {
    Role testStaffMemberRole = Role.MANAGER;
    StaffMemberPayload payload = new StaffMemberPayload();
    payload.setIdentifier(null);
    payload.setRole(testStaffMemberRole.toString());
    payload.setFirstName("Muikku");
    payload.setLastName("Manager");
    payload.setEmail("muikkumanager@example.com");
    Response response = given().headers(getAuthHeaders()).contentType("application/json").body(payload).post("/muikku/users");
    response.then().statusCode(200).body("identifier", not(is((Long) null)));
    long staffMemberId = response.body().jsonPath().getLong("identifier");
    long personId = getStaffMemberPersonId(staffMemberId);
    try {
        payload.setIdentifier(null);
        payload.setFirstName("Muikku2");
        payload.setLastName("Manager2");
        // Attempt to create user with same email - the result should be 409
        given().headers(getAuthHeaders()).contentType("application/json").body(payload).post("/muikku/users").then().statusCode(409);
    } finally {
        given().headers(getAuthHeaders()).delete("/staff/members/{ID}?permanent=true", staffMemberId).then().statusCode(204);
        given().headers(getAuthHeaders()).delete("/persons/persons/{ID}", personId).then().statusCode(204);
    }
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) Response(io.restassured.response.Response) StaffMemberPayload(fi.otavanopisto.pyramus.rest.model.muikku.StaffMemberPayload) Test(org.junit.Test)

Example 4 with Role

use of fi.otavanopisto.pyramus.domainmodel.users.Role in project pyramus by otavanopisto.

the class UsersService method updateUser.

public void updateUser(@WebParam(name = "userId") Long userId, @WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "role") String role) {
    StaffMemberDAO staffDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StaffMember user = staffDAO.findById(userId);
    Role userRole = EnumType.valueOf(Role.class, role);
    Organization organization = user.getOrganization();
    staffDAO.update(user, organization, firstName, lastName, userRole);
    validateEntity(user);
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember)

Example 5 with Role

use of fi.otavanopisto.pyramus.domainmodel.users.Role in project pyramus by otavanopisto.

the class UsersService method createUser.

public UserEntity createUser(@WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "externalId") String externalId, @WebParam(name = "authProvider") String authProvider, @WebParam(name = "role") String role) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    // TODO: should not create if user exists
    Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
    userIdentificationDAO.create(person, authProvider, externalId);
    Role userRole = EnumType.valueOf(Role.class, role);
    // TODO organization
    Organization organization = null;
    StaffMember staffMember = staffMemberDAO.create(organization, firstName, lastName, userRole, person, false);
    personDAO.updateDefaultUser(person, staffMember);
    validateEntity(staffMember);
    return EntityFactoryVault.buildFromDomainObject(staffMember);
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)

Aggregations

Role (fi.otavanopisto.pyramus.domainmodel.users.Role)21 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)9 UserRole (fi.otavanopisto.pyramus.framework.UserRole)7 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)5 User (fi.otavanopisto.pyramus.domainmodel.users.User)5 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)4 EnvironmentRolePermission (fi.otavanopisto.pyramus.domainmodel.security.EnvironmentRolePermission)4 Permission (fi.otavanopisto.pyramus.domainmodel.security.Permission)4 Response (io.restassured.response.Response)4 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)3 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)3 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)3 UserIdentificationDAO (fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)3 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)3 StaffMemberPayload (fi.otavanopisto.pyramus.rest.model.muikku.StaffMemberPayload)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 AddressDAO (fi.otavanopisto.pyramus.dao.base.AddressDAO)2 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)2 OrganizationDAO (fi.otavanopisto.pyramus.dao.base.OrganizationDAO)2