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