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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations