Search in sources :

Example 1 with IUser

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);
        }
    }
}
Also used : IContact(ch.elexis.core.model.IContact) IUser(ch.elexis.core.model.IUser)

Example 2 with IUser

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());
}
Also used : Address(org.hl7.fhir.r4.model.Address) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) Date(java.util.Date) LocalDate(java.time.LocalDate) Practitioner(org.hl7.fhir.r4.model.Practitioner) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Identifier(org.hl7.fhir.r4.model.Identifier) IUser(ch.elexis.core.model.IUser) Test(org.junit.Test)

Example 3 with IUser

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;
}
Also used : InvalidKeySpecException(java.security.spec.InvalidKeySpecException) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) LoggerFactory(org.slf4j.LoggerFactory) CredentialsMatcher(org.apache.shiro.authc.credential.CredentialsMatcher) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) IModelService(ch.elexis.core.services.IModelService) Component(org.osgi.service.component.annotations.Component) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) IUser(ch.elexis.core.model.IUser) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) ESAuthorizingRealm(info.elexis.server.core.common.security.ESAuthorizingRealm) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Logger(org.slf4j.Logger) DecoderException(org.apache.commons.codec.DecoderException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) Set(java.util.Set) SimpleByteSource(org.apache.shiro.util.SimpleByteSource) Collectors(java.util.stream.Collectors) SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) AuthenticationException(org.apache.shiro.authc.AuthenticationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Optional(java.util.Optional) Reference(org.osgi.service.component.annotations.Reference) PasswordEncryptionService(ch.rgw.tools.PasswordEncryptionService) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) IUser(ch.elexis.core.model.IUser)

Example 4 with IUser

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;
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) SimpleByteSource(org.apache.shiro.util.SimpleByteSource) IUser(ch.elexis.core.model.IUser) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 5 with IUser

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;
}
Also used : ArrayList(java.util.ArrayList) IUser(ch.elexis.core.model.IUser) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole)

Aggregations

IUser (ch.elexis.core.model.IUser)6 IContact (ch.elexis.core.model.IContact)2 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)2 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)2 SimpleByteSource (org.apache.shiro.util.SimpleByteSource)2 PractitionerRole (org.hl7.fhir.r4.model.PractitionerRole)2 IModelService (ch.elexis.core.services.IModelService)1 PasswordEncryptionService (ch.rgw.tools.PasswordEncryptionService)1 ESAuthorizingRealm (info.elexis.server.core.common.security.ESAuthorizingRealm)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DecoderException (org.apache.commons.codec.DecoderException)1