Search in sources :

Example 11 with UserBean

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

the class UserServiceImpl method getUserAsBean.

@Override
public UserBean getUserAsBean(User user) {
    UserBean bean = new UserBean();
    bean.setUserId(Integer.toString(user.getId()));
    UserRole anonymous = _authoritiesService.getAnonymousRole();
    boolean isAnonymous = user.getRoles().contains(anonymous);
    bean.setAnonymous(isAnonymous);
    UserRole admin = _authoritiesService.getAdministratorRole();
    boolean isAdmin = user.getRoles().contains(admin);
    bean.setAdmin(isAdmin);
    List<UserIndexBean> indices = new ArrayList<UserIndexBean>();
    bean.setIndices(indices);
    for (UserIndex index : user.getUserIndices()) {
        UserIndexKey key = index.getId();
        UserIndexBean indexBean = new UserIndexBean();
        indexBean.setType(key.getType());
        indexBean.setValue(key.getValue());
        indices.add(indexBean);
    }
    _userPropertiesService.getUserAsBean(user, bean);
    return bean;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexBean(org.onebusaway.users.client.model.UserIndexBean) UserIndexKey(org.onebusaway.users.model.UserIndexKey) UserBean(org.onebusaway.users.client.model.UserBean) UserRole(org.onebusaway.users.model.UserRole) ArrayList(java.util.ArrayList)

Example 12 with UserBean

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

the class IndexedUserAuthenticationProcessorFilter method obtainUsername.

/* during authentication, if you are trying to retrieve the username
  and the user isDisabled in the properties, it will return null
  Without the username, the user can not log in
  */
@Override
protected String obtainUsername(HttpServletRequest request) {
    String username = super.obtainUsername(request);
    if (username != null) {
        username = username.trim();
        if (username.length() > 0) {
            username = obtainUserIndexType(request) + "_" + username;
        }
    }
    UserIndex userIndex = _userService.getUserIndexForUsername(username);
    UserBean bean = _userService.getUserAsBean(userIndex.getUser());
    if (bean == null | bean.isDisabled()) {
        return null;
    }
    return username;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserBean(org.onebusaway.users.client.model.UserBean)

Example 13 with UserBean

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

the class ApiKeyAction method searchAPIKey.

public String searchAPIKey() {
    // 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();
        UserBean bean = userService.getUserAsBean(user);
        minApiReqInt = bean.getMinApiRequestInterval();
        contactName = bean.getContactName();
        contactCompany = bean.getContactCompany();
        contactEmail = bean.getContactEmail();
        contactDetails = bean.getContactDetails();
        addActionMessage("Key '" + key + "' found");
    }
    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 14 with UserBean

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

the class UserManagementServiceImpl method buildUserDetail.

private UserDetail buildUserDetail(User user) {
    UserDetail userDetail = new UserDetail();
    userDetail.setId(user.getId());
    for (UserIndex userIndex : user.getUserIndices()) {
        userDetail.setUsername(userIndex.getId().getValue());
    }
    for (UserRole role : user.getRoles()) {
        // There should be only one role
        userDetail.setRole(role.getName());
    }
    UserBean bean = userService.getUserAsBean(user);
    userDetail.setDisabled(bean.isDisabled());
    return userDetail;
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) UserBean(org.onebusaway.users.client.model.UserBean) UserRole(org.onebusaway.users.model.UserRole)

Example 15 with UserBean

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

the class IndexTemplate method buildTemplate.

@Override
public void buildTemplate(ActionContext context) {
    ValueStack stack = context.getValueStack();
    UserBean user = (UserBean) stack.findValue("currentUser");
    if (user.getDefaultLocationName() != null) {
        addMessage(Messages.SETTINGS_YOUR_DEFAULT_SEARCH_LOCATION_IS_CURRENTLY);
        addText(_locationPronunciation.modify(user.getDefaultLocationName()));
    }
    addMessage(Messages.INDEX_ACTION_SET_DEFAULT_SEARCH_LOCATION);
    addAction("1", "/settings/askForDefaultSearchLocation");
    if (user != null) {
        if (user.isRememberPreferencesEnabled())
            addMessage(Messages.PREFERENCES_DO_NOT_REMEMBER);
        else
            addMessage(Messages.PREFERENCES_DO_REMEMBER);
        addAction("2", "/settings/setRememberPreferences", "enabled", !user.isRememberPreferencesEnabled());
    }
    addMessage(Messages.HOW_TO_GO_BACK);
    addAction("\\*", "/back");
    addMessage(Messages.TO_REPEAT);
    addAction("[#23456789*]", "/repeat");
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) UserBean(org.onebusaway.users.client.model.UserBean)

Aggregations

UserBean (org.onebusaway.users.client.model.UserBean)16 User (org.onebusaway.users.model.User)8 UserIndex (org.onebusaway.users.model.UserIndex)8 UserIndexKey (org.onebusaway.users.model.UserIndexKey)6 ArrayList (java.util.ArrayList)3 UserDetail (org.onebusaway.admin.model.ui.UserDetail)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 Criteria (org.hibernate.Criteria)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 UserRole (org.onebusaway.users.model.UserRole)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1