Search in sources :

Example 6 with Usertype

use of de.vitero.schema.user.Usertype 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 7 with Usertype

use of de.vitero.schema.user.Usertype in project OpenOLAT by OpenOLAT.

the class ViteroManager method getCustomersUsers.

public List<Usertype> getCustomersUsers() throws VmsNotAvailableException {
    try {
        GetUserListByCustomerRequest listRequest = new GetUserListByCustomerRequest();
        listRequest.setCustomerid(viteroModule.getCustomerId());
        Userlist userList = getUserWebService().getUserListByCustomer(listRequest);
        List<Usertype> userTypes = userList.getUser();
        return userTypes;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot get the list of users of customer: " + viteroModule.getCustomerId(), f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot get the list of users of customer: " + viteroModule.getCustomerId(), e);
        return null;
    }
}
Also used : Usertype(de.vitero.schema.user.Usertype) WebServiceException(javax.xml.ws.WebServiceException) Userlist(de.vitero.schema.user.Userlist) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) GetUserListByCustomerRequest(de.vitero.schema.user.GetUserListByCustomerRequest) ConnectException(java.net.ConnectException)

Example 8 with Usertype

use of de.vitero.schema.user.Usertype in project openolat by klemens.

the class ViteroManager method getCustomersUsers.

public List<Usertype> getCustomersUsers() throws VmsNotAvailableException {
    try {
        GetUserListByCustomerRequest listRequest = new GetUserListByCustomerRequest();
        listRequest.setCustomerid(viteroModule.getCustomerId());
        Userlist userList = getUserWebService().getUserListByCustomer(listRequest);
        List<Usertype> userTypes = userList.getUser();
        return userTypes;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot get the list of users of customer: " + viteroModule.getCustomerId(), f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot get the list of users of customer: " + viteroModule.getCustomerId(), e);
        return null;
    }
}
Also used : Usertype(de.vitero.schema.user.Usertype) WebServiceException(javax.xml.ws.WebServiceException) Userlist(de.vitero.schema.user.Userlist) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) GetUserListByCustomerRequest(de.vitero.schema.user.GetUserListByCustomerRequest) ConnectException(java.net.ConnectException)

Example 9 with Usertype

use of de.vitero.schema.user.Usertype 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)

Example 10 with Usertype

use of de.vitero.schema.user.Usertype in project openolat by klemens.

the class ViteroManager method getGroupRoles.

/**
 * @param id The group id
 * @return
 * @throws VmsNotAvailableException
 */
public ViteroGroupRoles getGroupRoles(int id) throws VmsNotAvailableException {
    try {
        Group groupWs = getGroupWebService();
        Groupid groupId = new Groupid();
        groupId.setGroupid(id);
        Group_Type group = groupWs.getGroup(groupId);
        Completegrouptype groupType = group.getGroup();
        List<Completegrouptype.Participant> participants = groupType.getParticipant();
        int numOfParticipants = participants == null ? 0 : participants.size();
        ViteroGroupRoles groupRoles = new ViteroGroupRoles();
        if (numOfParticipants > 0) {
            Map<Integer, String> idToEmails = new HashMap<Integer, String>();
            List<Usertype> vmsUsers = getVmsUsersByGroup(id);
            if (vmsUsers != null) {
                for (Usertype vmsUser : vmsUsers) {
                    Integer userId = new Integer(vmsUser.getId());
                    String email = vmsUser.getEmail();
                    groupRoles.getEmailsOfParticipants().add(email);
                    idToEmails.put(userId, email);
                }
            }
            for (int i = 0; i < numOfParticipants; i++) {
                Completegrouptype.Participant participant = participants.get(i);
                Integer userId = new Integer(participant.getUserid());
                String email = idToEmails.get(userId);
                if (email != null) {
                    GroupRole role = GroupRole.valueOf(participant.getRole());
                    groupRoles.getEmailsToRole().put(email, role);
                    groupRoles.getEmailsToVmsUserId().put(email, userId);
                }
            }
        }
        return groupRoles;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot get group roles", f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        return null;
    }
}
Also used : Group(de.vitero.schema.group.Group) ViteroGroup(org.olat.modules.vitero.model.ViteroGroup) BusinessGroup(org.olat.group.BusinessGroup) ViteroGroupRoles(org.olat.modules.vitero.model.ViteroGroupRoles) Usertype(de.vitero.schema.user.Usertype) WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) Completegrouptype(de.vitero.schema.group.Completegrouptype) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Group_Type(de.vitero.schema.group.Group_Type) Groupid(de.vitero.schema.group.Groupid) BigInteger(java.math.BigInteger) GroupRole(org.olat.modules.vitero.model.GroupRole) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ConnectException(java.net.ConnectException)

Aggregations

Usertype (de.vitero.schema.user.Usertype)10 ConnectException (java.net.ConnectException)6 WebServiceException (javax.xml.ws.WebServiceException)6 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)6 ErrorCode (org.olat.modules.vitero.model.ErrorCode)6 Userlist (de.vitero.schema.user.Userlist)4 Completegrouptype (de.vitero.schema.group.Completegrouptype)2 Group (de.vitero.schema.group.Group)2 Group_Type (de.vitero.schema.group.Group_Type)2 Groupid (de.vitero.schema.group.Groupid)2 GetUserListByCustomerRequest (de.vitero.schema.user.GetUserListByCustomerRequest)2 GetUserListByGroupRequest (de.vitero.schema.user.GetUserListByGroupRequest)2 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 Authentication (org.olat.basesecurity.Authentication)2 Identity (org.olat.core.id.Identity)2 BusinessGroup (org.olat.group.BusinessGroup)2 CheckUserInfo (org.olat.modules.vitero.model.CheckUserInfo)2 GetUserInfo (org.olat.modules.vitero.model.GetUserInfo)2 GroupRole (org.olat.modules.vitero.model.GroupRole)2