use of ch.elexis.core.model.IUser in project elexis-server by elexis.
the class Context method setTyped.
@Override
public void setTyped(Object object) {
if (object != null) {
if (object instanceof IUser) {
// also set active user contact
IContact userContact = ((IUser) object).getAssignedContact();
setNamed(ACTIVE_USERCONTACT, userContact);
}
Optional<Class<?>> modelInterface = getModelInterface(object);
if (object.equals(context.get(modelInterface.get().getName()))) {
// object is already in the context do nothing otherwise loop happens
return;
}
if (modelInterface.isPresent()) {
context.put(modelInterface.get().getName(), object);
} else {
context.put(object.getClass().getName(), object);
}
}
}
use of ch.elexis.core.model.IUser in project elexis-server by elexis.
the class PractitionerRoleTest method getPractitionerProperties.
/**
* Test all properties set by {@link TestDatabaseInitializer#initializeMandant()}.
*/
@Test
public void getPractitionerProperties() {
List<IUser> user = UserServiceHolder.get().getUsersByAssociatedContact(TestDatabaseInitializer.getMandant());
assertFalse(user.isEmpty());
PractitionerRole readPractitionerRole = client.read().resource(PractitionerRole.class).withId(user.get(0).getId()).execute();
assertNotNull(readPractitionerRole);
assertNotNull(readPractitionerRole.getPractitioner());
Practitioner readPractitioner = client.read().resource(Practitioner.class).withId(readPractitionerRole.getPractitioner().getReferenceElement().getIdPart()).execute();
assertNotNull(readPractitioner);
List<HumanName> names = readPractitioner.getName();
assertNotNull(names);
assertFalse(names.isEmpty());
assertEquals(2, names.size());
HumanName name = names.get(0);
assertNotNull(name);
assertEquals(NameUse.OFFICIAL, name.getUse());
assertEquals("Mandant", name.getFamily());
assertEquals("Test", name.getGivenAsSingleString());
HumanName sysName = names.get(1);
assertNotNull(sysName);
assertEquals(NameUse.ANONYMOUS, sysName.getUse());
assertEquals("tst", sysName.getText());
Date dob = readPractitioner.getBirthDate();
assertNotNull(dob);
assertEquals(LocalDate.of(1970, Month.JANUARY, 1), AllTests.getLocalDateTime(dob).toLocalDate());
assertEquals(AdministrativeGender.MALE, readPractitioner.getGender());
List<ContactPoint> telcoms = readPractitioner.getTelecom();
assertNotNull(telcoms);
assertEquals(2, telcoms.size());
assertEquals(1, telcoms.get(0).getRank());
assertEquals("+01555234", telcoms.get(0).getValue());
assertEquals(ContactPointUse.MOBILE, telcoms.get(1).getUse());
assertEquals("+01444234", telcoms.get(1).getValue());
List<Address> addresses = readPractitioner.getAddress();
assertNotNull(addresses);
assertEquals(1, addresses.size());
assertEquals("City", addresses.get(0).getCity());
assertEquals("123", addresses.get(0).getPostalCode());
assertEquals("Street 100", addresses.get(0).getLine().get(0).asStringValue());
List<Identifier> identifiers = readPractitioner.getIdentifier();
boolean eanFound = false;
boolean kskFound = false;
for (Identifier identifier : identifiers) {
if (identifier.getSystem().equals(XidConstants.DOMAIN_EAN)) {
assertEquals("2000000000002", identifier.getValue());
eanFound = true;
}
if (identifier.getSystem().equals("www.xid.ch/id/ksk")) {
assertEquals("C000002", identifier.getValue());
kskFound = true;
}
}
assertTrue(eanFound);
assertTrue(kskFound);
assertTrue(readPractitioner.getActive());
}
use of ch.elexis.core.model.IUser in project elexis-server by elexis.
the class ElexisConnectorAuthorizingRealm method doGetAuthorizationInfo.
@Override
public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String userid = (String) getAvailablePrincipal(principals);
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Optional<IUser> userOptional = modelService.load(userid, IUser.class);
if (userOptional.isPresent()) {
IUser user = userOptional.get();
Set<String> roles = user.getRoles().stream().map(r -> r.getId()).collect(Collectors.toSet());
info.setRoles(roles);
}
return info;
}
use of ch.elexis.core.model.IUser in project elexis-server by elexis.
the class ElexisConnectorAuthorizingRealm method doGetAuthenticationInfo.
@Override
public AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
Optional<IUser> userOptional = Optional.empty();
boolean validUser = false;
if (token instanceof UsernamePasswordToken) {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
String userid = upToken.getUsername();
if (userid == null || userid.length() == 0) {
return null;
}
userOptional = modelService.load(userid, IUser.class);
if (userOptional.isPresent()) {
validUser = (userid.equals(userOptional.get().getId()));
if (!validUser) {
log.info("userid does not match [{}] : [{}]", userid, userOptional.get().getId());
}
}
}
if (userOptional.isPresent()) {
IUser user = userOptional.get();
String hashedPassword = user.getHashedPassword();
String salt = user.getSalt();
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getId(), hashedPassword, REALM_NAME);
authenticationInfo.setCredentialsSalt(new SimpleByteSource(salt));
return authenticationInfo;
}
return null;
}
use of ch.elexis.core.model.IUser in project elexis-server by elexis.
the class PractitionerRoleResourceProvider method getAllPractitionerRoles.
private List<PractitionerRole> getAllPractitionerRoles() {
// all Kontakt marked as user
IQuery<IUser> query = modelService.getQuery(IUser.class);
List<IUser> practitioners = query.execute();
List<PractitionerRole> ret = new ArrayList<PractitionerRole>();
if (!practitioners.isEmpty()) {
for (IUser user : practitioners) {
Optional<PractitionerRole> fhirPractitionerRole = getTransformer().getFhirObject(user);
fhirPractitionerRole.ifPresent(fp -> ret.add(fp));
}
}
return ret;
}
Aggregations