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());
}
}
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);
}
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();
}
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);
}
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;
}
Aggregations