use of org.onebusaway.users.model.UserIndexKey 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.UserIndexKey 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.UserIndexKey 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.UserIndexKey in project onebusaway-application-modules by camsys.
the class UserServiceImpl method registerPhoneNumber.
@Override
public String registerPhoneNumber(User user, String phoneNumber) {
int code = (int) (Math.random() * 8999 + 1000);
String codeAsString = Integer.toString(code);
phoneNumber = PhoneNumberLibrary.normalizePhoneNumber(phoneNumber);
UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, phoneNumber);
_userIndexRegistrationService.setRegistrationForUserIndexKey(key, user.getId(), codeAsString);
return codeAsString;
}
use of org.onebusaway.users.model.UserIndexKey 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;
}
Aggregations