Search in sources :

Example 31 with User

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

the class KeysResource method delete.

private void delete(String apiKey) throws Exception {
    UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
    UserIndex userIndex = _userService.getUserIndexForId(key);
    if (userIndex == null)
        throw new Exception("API key " + apiKey + " not found (userIndex null).");
    User user = userIndex.getUser();
    boolean found = false;
    for (UserIndex index : user.getUserIndices()) {
        if (index.getId().getValue().equalsIgnoreCase(key.getValue())) {
            userIndex = index;
            found = true;
            break;
        }
    }
    if (!found)
        throw new Exception("API key " + apiKey + " not found (no exact match).");
    _userService.removeUserIndexForUser(user, userIndex.getId());
    if (user.getUserIndices().isEmpty())
        _userService.deleteUser(user);
    // Clear the cached value here
    try {
        _userService.getMinApiRequestIntervalForKey(apiKey, true);
    } catch (Exception e) {
    // Ignore this
    }
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 32 with User

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

the class KeysResource method updateKeyContactInfo.

private void updateKeyContactInfo(String apiKey, String contactName, String contactCompany, String contactEmail, String contactDetails, Long minApiReqIntervalLong) throws Exception {
    UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
    UserIndex userIndex = _userService.getUserIndexForId(key);
    if (userIndex == null)
        throw new Exception("API key " + apiKey + " not found (userIndex null).");
    User user = userIndex.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(userIndex.getUser(), minApiReqIntervalLong);
    _userPropertiesService.updateApiKeyContactInfo(user, keyContactName, keyContactCompany, keyContactEmail, keyContactDetails);
}
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) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 33 with User

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

the class KeysResource method listKeyDetails.

@Path("/list/{apiKey}")
@GET
@Produces("application/json")
public Response listKeyDetails(@PathParam("apiKey") String apiKey) throws JsonGenerationException, JsonMappingException, IOException {
    log.info("Starting listKeyDetails");
    try {
        validateSecurity();
        UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
        UserIndex userIndex = _userService.getUserIndexForId(key);
        if (userIndex == null)
            throw new Exception("API key " + apiKey + " not found (userIndex null).");
        User user = userIndex.getUser();
        UserBean bean = _userService.getUserAsBean(user);
        Map<String, String> result = new HashMap<String, String>();
        result.put("keyValue", apiKey);
        result.put("contactName", bean.getContactName());
        result.put("contactCompany", bean.getContactCompany());
        result.put("contactEmail", bean.getContactEmail());
        result.put("contactDetails", bean.getContactDetails());
        result.put("minApiRequestInterval", bean.getMinApiRequestInterval().toString());
        Response response = constructResponse(result);
        log.info("Returning response from listKeyDetails");
        return response;
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new WebApplicationException(e, Response.serverError().build());
    }
}
Also used : Response(javax.ws.rs.core.Response) 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) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with User

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

the class CurrentUserServiceImpl method enableAdminRole.

@Override
public void enableAdminRole() {
    User user = _currentUserStrategy.getCurrentUser(true);
    if (user == null)
        return;
    _userService.enableAdminRoleForUser(user, true);
    _currentUserStrategy.clearCurrentUser();
}
Also used : User(org.onebusaway.users.model.User)

Example 35 with User

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

the class CurrentUserServiceImpl method handleLogin.

@Override
public IndexedUserDetails handleLogin(String type, String id, String credentials, boolean isAnonymous, boolean registerIfNewUser) {
    UserIndexKey key = new UserIndexKey(type, id);
    UserIndex index = _userService.getUserIndexForId(key);
    boolean exists = index != null;
    // New user?
    if (!exists) {
        if (!registerIfNewUser)
            return null;
        index = _userService.getOrCreateUserForIndexKey(key, credentials, false);
        User newUser = index.getUser();
        User oldUser = _currentUserStrategy.getCurrentUser(false);
        if (oldUser != null && _userService.isAnonymous(oldUser))
            _userService.mergeUsers(oldUser, newUser);
    }
    return new IndexedUserDetailsImpl(_authoritiesService, index);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

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