Search in sources :

Example 21 with UserIndexKey

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());
    }
}
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 22 with UserIndexKey

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);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) PostConstruct(javax.annotation.PostConstruct)

Example 23 with UserIndexKey

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);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User)

Example 24 with UserIndexKey

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;
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey)

Example 25 with UserIndexKey

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexBean(org.onebusaway.users.client.model.UserIndexBean) UserIndexKey(org.onebusaway.users.model.UserIndexKey) UserBean(org.onebusaway.users.client.model.UserBean) UserRole(org.onebusaway.users.model.UserRole) ArrayList(java.util.ArrayList)

Aggregations

UserIndexKey (org.onebusaway.users.model.UserIndexKey)30 UserIndex (org.onebusaway.users.model.UserIndex)22 User (org.onebusaway.users.model.User)16 UserBean (org.onebusaway.users.client.model.UserBean)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 Test (org.junit.Test)4 IndexedUserDetails (org.onebusaway.users.model.IndexedUserDetails)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 PostConstruct (javax.annotation.PostConstruct)2 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 DefaultUserAuthenticationToken (org.onebusaway.users.impl.authentication.DefaultUserAuthenticationToken)2 UserRole (org.onebusaway.users.model.UserRole)2 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)2