@@ -0,0 +1,2044 @@
+package com.github.dkanellis.fikey.views;%0A%0A%0Aimport com.github.dkanellis.fikey.storage.DataStorage;%0Aimport com.yubico.u2f.U2F;%0Aimport com.yubico.u2f.data.DeviceRegistration;%0Aimport com.yubico.u2f.data.messages.RegisterRequestData;%0Aimport com.yubico.u2f.data.messages.RegisterResponse;%0Aimport io.dropwizard.views.View;%0A%0Aimport javax.ws.rs.*;%0Aimport javax.ws.rs.core.MediaType;%0A%0A/**%0A * @author Dimitris Kanellis%0A */%0A@Path(%22/%22)%0A@Produces(MediaType.TEXT_HTML)%0Apublic class RegisterDeviceResource %7B%0A%0A    public static final String APP_ID = %22https://localhost:8080%22;%0A%0A    private final static String SUCCESSFUL_REGISTRATION_MESSAGE = %22Successfully registered device: %3Cpre%3E%25s%3C/pre%3E%22;%0A%0A    private final DataStorage%3CString, String, String%3E storage;%0A    private U2F u2fManager;%0A%0A    public RegisterDeviceResource() %7B%0A        this.storage = new DataStorage%3C%3E();%0A        this.u2fManager = new U2F();%0A    %7D%0A%0A    @Path(%22startDeviceRegistration%22)%0A    @GET%0A    public View startDeviceRegistration(@QueryParam(%22username%22) String username, @QueryParam(%22password%22) String password) %7B%0A        RegisterRequestData registerRequest = u2fManager.startRegistration(APP_ID, storage.getDevicesFromUser(username));%0A        storage.addRequest(registerRequest.getRequestId(), registerRequest.toJson());%0A        return new RegisterDeviceView(username, registerRequest.toJson());%0A    %7D%0A%0A    @Path(%22finishDeviceRegistration%22)%0A    @POST%0A    public String finishRegistration(@FormParam(%22tokenResponse%22) String response, @FormParam(%22username%22) String username) %7B%0A        RegisterResponse registerResponse = RegisterResponse.fromJson(response);%0A        RegisterRequestData registerRequest%0A                = RegisterRequestData.fromJson(storage.removeRequest(registerResponse.getRequestId()));%0A        DeviceRegistration registration = u2fManager.finishRegistration(registerRequest, registerResponse);%0A        storage.addDeviceToUser(username, registration.getKeyHandle(), registration.toJson());%0A        return String.format(SUCCESSFUL_REGISTRATION_MESSAGE, registration);%0A    %7D%0A%7D%0A

Add device registration logic