Search in sources :

Example 1 with CheckUserInfo

use of org.olat.modules.vitero.model.CheckUserInfo in project OpenOLAT by OpenOLAT.

the class ViteroConfigurationController method checkUsers.

private void checkUsers() {
    try {
        CheckUserInfo infos = viteroManager.checkUsers();
        if (infos.getAuthenticationCreated() == 0 && infos.getAuthenticationDeleted() == 0) {
            showInfo("check.users.ok");
        } else {
            String[] args = new String[] { Integer.toString(infos.getAuthenticationCreated()), Integer.toString(infos.getAuthenticationDeleted()), Integer.toString(infos.getAuthenticationCreated() + infos.getAuthenticationDeleted()) };
            getWindowControl().setInfo(translate("check.users.nok", args));
        }
    } catch (VmsNotAvailableException e) {
        showError(VmsNotAvailableException.I18N_KEY);
    }
}
Also used : CheckUserInfo(org.olat.modules.vitero.model.CheckUserInfo) VmsNotAvailableException(org.olat.modules.vitero.manager.VmsNotAvailableException)

Example 2 with CheckUserInfo

use of org.olat.modules.vitero.model.CheckUserInfo in project openolat by klemens.

the class ViteroConfigurationController method checkUsers.

private void checkUsers() {
    try {
        CheckUserInfo infos = viteroManager.checkUsers();
        if (infos.getAuthenticationCreated() == 0 && infos.getAuthenticationDeleted() == 0) {
            showInfo("check.users.ok");
        } else {
            String[] args = new String[] { Integer.toString(infos.getAuthenticationCreated()), Integer.toString(infos.getAuthenticationDeleted()), Integer.toString(infos.getAuthenticationCreated() + infos.getAuthenticationDeleted()) };
            getWindowControl().setInfo(translate("check.users.nok", args));
        }
    } catch (VmsNotAvailableException e) {
        showError(VmsNotAvailableException.I18N_KEY);
    }
}
Also used : CheckUserInfo(org.olat.modules.vitero.model.CheckUserInfo) VmsNotAvailableException(org.olat.modules.vitero.manager.VmsNotAvailableException)

Example 3 with CheckUserInfo

use of org.olat.modules.vitero.model.CheckUserInfo in project OpenOLAT by OpenOLAT.

the class ViteroManager method checkUsers.

public CheckUserInfo checkUsers() throws VmsNotAvailableException {
    final String[] authProviders = new String[] { VMS_PROVIDER };
    final String prefix = getVmsUsernamePrefix();
    int authenticationCreated = 0;
    int authenticationDeleted = 0;
    // check if vms user with an openolat login exists on vms server
    // without the need authentication object in openolat.
    List<Usertype> users = getCustomersUsers();
    if (users != null && users.size() > 0) {
        for (Usertype user : users) {
            String vmsUsername = user.getUsername();
            if (vmsUsername.startsWith(prefix)) {
                String olatUsername = vmsUsername.substring(prefix.length(), vmsUsername.length());
                List<Identity> identities = securityManager.getIdentitiesByPowerSearch(olatUsername, null, false, null, null, authProviders, null, null, null, null, null);
                if (identities.isEmpty()) {
                    Identity identity = securityManager.findIdentityByName(olatUsername);
                    if (identity != null) {
                        authenticationCreated++;
                        securityManager.createAndPersistAuthentication(identity, VMS_PROVIDER, Integer.toString(user.getId()), null, null);
                        log.info("Recreate VMS authentication for: " + identity.getName());
                    }
                }
            }
        }
    }
    // check if all openolat users with a vms authentication have an user
    // on the vms server
    List<Identity> identities = securityManager.getIdentitiesByPowerSearch(null, null, false, null, null, authProviders, null, null, null, null, null);
    for (Identity identity : identities) {
        Authentication authentication = securityManager.findAuthentication(identity, VMS_PROVIDER);
        String vmsUserId = authentication.getAuthusername();
        boolean foundIt = false;
        for (Usertype user : users) {
            if (vmsUserId.equals(Integer.toString(user.getId()))) {
                foundIt = true;
            }
        }
        if (!foundIt) {
            securityManager.deleteAuthentication(authentication);
            authenticationDeleted++;
        }
    }
    CheckUserInfo infos = new CheckUserInfo();
    infos.setAuthenticationCreated(authenticationCreated);
    infos.setAuthenticationDeleted(authenticationDeleted);
    return infos;
}
Also used : Usertype(de.vitero.schema.user.Usertype) CheckUserInfo(org.olat.modules.vitero.model.CheckUserInfo) Authentication(org.olat.basesecurity.Authentication) Identity(org.olat.core.id.Identity)

Example 4 with CheckUserInfo

use of org.olat.modules.vitero.model.CheckUserInfo in project openolat by klemens.

the class ViteroManager method checkUsers.

public CheckUserInfo checkUsers() throws VmsNotAvailableException {
    final String[] authProviders = new String[] { VMS_PROVIDER };
    final String prefix = getVmsUsernamePrefix();
    int authenticationCreated = 0;
    int authenticationDeleted = 0;
    // check if vms user with an openolat login exists on vms server
    // without the need authentication object in openolat.
    List<Usertype> users = getCustomersUsers();
    if (users != null && users.size() > 0) {
        for (Usertype user : users) {
            String vmsUsername = user.getUsername();
            if (vmsUsername.startsWith(prefix)) {
                String olatUsername = vmsUsername.substring(prefix.length(), vmsUsername.length());
                List<Identity> identities = securityManager.getIdentitiesByPowerSearch(olatUsername, null, false, null, null, authProviders, null, null, null, null, null);
                if (identities.isEmpty()) {
                    Identity identity = securityManager.findIdentityByName(olatUsername);
                    if (identity != null) {
                        authenticationCreated++;
                        securityManager.createAndPersistAuthentication(identity, VMS_PROVIDER, Integer.toString(user.getId()), null, null);
                        log.info("Recreate VMS authentication for: " + identity.getName());
                    }
                }
            }
        }
    }
    // check if all openolat users with a vms authentication have an user
    // on the vms server
    List<Identity> identities = securityManager.getIdentitiesByPowerSearch(null, null, false, null, null, authProviders, null, null, null, null, null);
    for (Identity identity : identities) {
        Authentication authentication = securityManager.findAuthentication(identity, VMS_PROVIDER);
        String vmsUserId = authentication.getAuthusername();
        boolean foundIt = false;
        for (Usertype user : users) {
            if (vmsUserId.equals(Integer.toString(user.getId()))) {
                foundIt = true;
            }
        }
        if (!foundIt) {
            securityManager.deleteAuthentication(authentication);
            authenticationDeleted++;
        }
    }
    CheckUserInfo infos = new CheckUserInfo();
    infos.setAuthenticationCreated(authenticationCreated);
    infos.setAuthenticationDeleted(authenticationDeleted);
    return infos;
}
Also used : Usertype(de.vitero.schema.user.Usertype) CheckUserInfo(org.olat.modules.vitero.model.CheckUserInfo) Authentication(org.olat.basesecurity.Authentication) Identity(org.olat.core.id.Identity)

Aggregations

CheckUserInfo (org.olat.modules.vitero.model.CheckUserInfo)4 Usertype (de.vitero.schema.user.Usertype)2 Authentication (org.olat.basesecurity.Authentication)2 Identity (org.olat.core.id.Identity)2 VmsNotAvailableException (org.olat.modules.vitero.manager.VmsNotAvailableException)2