Search in sources :

Example 1 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class ApiKeyAction method searchContactEmail.

public String searchContactEmail() {
    String searchResult = "Email address '" + contactEmail + "' could not be found";
    List<String> apiKeys = userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
    // clear other fields
    contactName = "";
    contactCompany = "";
    contactDetails = "";
    key = "";
    for (String apiKey : apiKeys) {
        // for each api key, check if contact email matches
        UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
        UserIndex userIndex = userService.getUserIndexForId(userKey);
        if (userIndex != null) {
            User user = userIndex.getUser();
            UserBean bean = userService.getUserAsBean(user);
            if (contactEmail.equals(bean.getContactEmail())) {
                minApiReqInt = bean.getMinApiRequestInterval();
                contactName = bean.getContactName();
                contactCompany = bean.getContactCompany();
                contactDetails = bean.getContactDetails();
                key = apiKey;
                searchResult = "Email address '" + contactEmail + "' found";
                break;
            }
        }
    }
    addActionMessage(searchResult);
    return SUCCESS;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean)

Example 2 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class ApiKeyAction method updateAPIKey.

public void updateAPIKey(UserIndex userIndexForId) {
    User user = userIndexForId.getUser();
    UserBean bean = userService.getUserAsBean(user);
    String keyContactName = bean.getContactName();
    String keyContactCompany = bean.getContactCompany();
    String keyContactEmail = bean.getContactEmail();
    String keyContactDetails = bean.getContactDetails();
    if (contactName != null) {
        keyContactName = contactName;
    }
    if (contactCompany != null) {
        keyContactCompany = contactCompany;
    }
    if (contactEmail != null) {
        keyContactEmail = contactEmail;
    }
    if (contactDetails != null) {
        keyContactDetails = contactDetails;
    }
    userPropertiesService.authorizeApi(user, minApiReqInt);
    userPropertiesService.updateApiKeyContactInfo(user, keyContactName, keyContactCompany, keyContactEmail, keyContactDetails);
    // Clear the cached value here
    userService.getMinApiRequestIntervalForKey(key, true);
    return;
}
Also used : User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean)

Example 3 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class ApiKeyAction method deleteAPIKey.

public String deleteAPIKey() {
    // Check if key already exists
    UserIndexKey userKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
    UserIndex userIndexForId = userService.getUserIndexForId(userKey);
    if (userIndexForId == null) {
        addActionMessage("Key '" + key + "' does not exist");
    } else {
        User user = userIndexForId.getUser();
        boolean found = false;
        for (UserIndex index : user.getUserIndices()) {
            if (index.getId().getValue().equalsIgnoreCase(userKey.getValue())) {
                userIndexForId = index;
                found = true;
                break;
            }
        }
        if (!found) {
            addActionMessage("API key " + key + " not found (no exact match).");
        }
        userService.removeUserIndexForUser(user, userIndexForId.getId());
        if (user.getUserIndices().isEmpty()) {
            userService.deleteUser(user);
        }
        // Clear the cached value here
        userService.getMinApiRequestIntervalForKey(key, true);
        addActionMessage("Key '" + key + "' deleted");
        clearContactInfoAndKey();
    }
    return SUCCESS;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

Example 4 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method inactivateUser.

// Marks the user as inactive, can activate again
@Override
public boolean inactivateUser(UserDetail userDetail) {
    User user = userService.getUserForId(userDetail.getId());
    if (user == null) {
        log.info("User '{}' does not exist in the system", userDetail.getUsername());
        return false;
    }
    userPropertiesService.disableUser(user);
    log.info("User '{}' disabled successfully", userDetail.getUsername());
    return true;
}
Also used : User(org.onebusaway.users.model.User)

Example 5 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserManagementServiceImpl method getInactiveUsersDetails.

@Override
public List<UserDetail> getInactiveUsersDetails() {
    List<UserDetail> userDetails = new ArrayList<UserDetail>();
    List<User> users = hibernateTemplate.execute(new HibernateCallback<List<User>>() {

        @SuppressWarnings("unchecked")
        @Override
        public List<User> doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(User.class).createCriteria("userIndices").add(Restrictions.eq("id.type", UserIndexTypes.USERNAME));
            List<User> users = criteria.list();
            return users;
        }
    });
    if (!users.isEmpty()) {
        for (User user : users) {
            UserBean bean = userService.getUserAsBean(user);
            if (bean.isDisabled()) {
                if (!user.getUserIndices().isEmpty()) {
                    UserDetail userDetail = buildUserDetail(user);
                    userDetails.add(userDetail);
                }
            }
        }
    }
    log.debug("Returning user details");
    return userDetails;
}
Also used : User(org.onebusaway.users.model.User) HibernateException(org.hibernate.HibernateException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserBean(org.onebusaway.users.client.model.UserBean) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session)

Aggregations

User (org.onebusaway.users.model.User)56 UserIndex (org.onebusaway.users.model.UserIndex)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)16 Test (org.junit.Test)13 Date (java.util.Date)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)7 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)4 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 UserDetail (org.onebusaway.admin.model.ui.UserDetail)4 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 UserRole (org.onebusaway.users.model.UserRole)3