Search in sources :

Example 26 with UserIndex

use of org.onebusaway.users.model.UserIndex 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 27 with UserIndex

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

the class CreateApiKeyAction method execute.

@PostConstruct
public void execute() {
    UserIndexKey userIndexKey = new UserIndexKey(UserIndexTypes.API_KEY, key);
    UserIndex userIndex = _userService.getOrCreateUserForIndexKey(userIndexKey, key, false);
    _userPropertiesService.authorizeApi(userIndex.getUser(), 0);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) PostConstruct(javax.annotation.PostConstruct)

Example 28 with UserIndex

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

the class CurrentUserServiceImpl method removeUserIndex.

@Override
public void removeUserIndex(UserIndexKey key) {
    UserIndex index = _currentUserStrategy.getCurrentUserIndex(false);
    if (index == null)
        return;
    boolean removingCurrentUserIndex = index.getId().equals(key);
    _userService.removeUserIndexForUser(index.getUser(), key);
    if (removingCurrentUserIndex)
        _currentUserStrategy.clearCurrentUser();
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex)

Example 29 with UserIndex

use of org.onebusaway.users.model.UserIndex 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)

Example 30 with UserIndex

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

the class UserServiceImpl method addUserIndexToUser.

@Override
public UserIndex addUserIndexToUser(User user, UserIndexKey key, String credentials) {
    UserIndex index = new UserIndex();
    index.setId(key);
    index.setCredentials(credentials);
    index.setUser(user);
    user.getUserIndices().add(index);
    _userDao.saveOrUpdateUser(user);
    return index;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex)

Aggregations

UserIndex (org.onebusaway.users.model.UserIndex)44 User (org.onebusaway.users.model.User)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)22 Test (org.junit.Test)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserRole (org.onebusaway.users.model.UserRole)8 HashSet (java.util.HashSet)6 IOException (java.io.IOException)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)5 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)5 UserDetail (org.onebusaway.admin.model.ui.UserDetail)5 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PostConstruct (javax.annotation.PostConstruct)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)2