// Path: src/main/java/org/swarmcom/jsynapse/controller/JsynapseApi.java
// public class JsynapseApi {
// 
//     public static final String CLIENT_V1_API = "/_matrix/client/api/v1";
//     public static final String CONTENT_V1_API = "/_matrix/media/v1";
// 
//     @ExceptionHandler
//     @ResponseStatus(NOT_FOUND)
//     public String handleEntityNotFound(EntityNotFoundException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(CONFLICT)
//     public String handleEntityAlreadyExists(EntityAlreadyExistsException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(BAD_REQUEST)
//     public String handleInvalidRequest(InvalidRequestException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(FORBIDDEN)
//     public String handleTokenNotFound(TokenNotFoundException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(BAD_REQUEST)
//     public String handleValidationException(ValidationException ex) {
//         return ex.getMessage();
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/Authentication.java
// public static class AuthenticationResult {
// 
//     @JsonProperty("user_id")
//     String user;
// 
//     @JsonProperty("access_token")
//     String accessToken;
// 
//     public AuthenticationResult(String user, String accessToken) {
//         this.user = user;
//         this.accessToken = accessToken;
//     }
// 
//     public String getUser() {
//         return user;
//     }
// 
//     public void setUser(String user) {
//         this.user = user;
//     }
// 
//     public String getAccessToken() {
//         return accessToken;
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/Authentication.java
// public static class AuthenticationSubmission extends HashMap<String, String> {
//     static final String TYPE = "type";
//     static final String REMOTE_ADDR = "remoteAddr";
// 
//     public AuthenticationSubmission() {
//     }
// 
//     public String getType() {
//         return get(TYPE);
//     }
// 
//     public void setRemoteAddr(String remoteAddr) {
//         put(REMOTE_ADDR, remoteAddr);
//     }
// 
//     public String getRemoteAddr() {
//         return get(REMOTE_ADDR);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/Authentication.java
// public static class AuthenticationFlows {
// 
//     @JsonProperty
//     List<AuthenticationInfo> flows = new LinkedList<>();
// 
//     public AuthenticationFlows(List<AuthenticationInfo> flows) {
//         this.flows = flows;
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/authentication/AuthenticationService.java
// public interface AuthenticationService {
//     AuthenticationFlows getSupportedFlows();
// 
//     AuthenticationResult register(AuthenticationSubmission authentication);
// 
//     AuthenticationResult login(AuthenticationSubmission authentication);
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/controller/JsynapseApi.java
// public static final String CLIENT_V1_API = "/_matrix/client/api/v1";


import org.springframework.web.bind.annotation.*;
import org.swarmcom.jsynapse.controller.JsynapseApi;
import org.swarmcom.jsynapse.domain.Authentication.AuthenticationResult;
import org.swarmcom.jsynapse.domain.Authentication.AuthenticationSubmission;
import org.swarmcom.jsynapse.domain.Authentication.AuthenticationFlows;
import org.swarmcom.jsynapse.service.authentication.AuthenticationService;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import static org.swarmcom.jsynapse.controller.JsynapseApi.CLIENT_V1_API;
/*
 * (C) Copyright 2015 eZuce Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
package org.swarmcom.jsynapse.controller.client.api.v1;




@RestController
@RequestMapping(value = CLIENT_V1_API)
public class AuthenticationRestApi extends JsynapseApi {

    private final AuthenticationService authenticationService;

    @Inject
    public AuthenticationRestApi(final AuthenticationService authenticationService) {
        this.authenticationService = authenticationService;
    }

    @RequestMapping(value = "/login", method = GET)
    public @ResponseBody
    AuthenticationFlows getLoginSchemas() {
        return authenticationService.getSupportedFlows();
    }

    @RequestMapping(value = "/login", method = POST)
    public @ResponseBody
    AuthenticationResult login(@RequestBody final AuthenticationSubmission login, HttpServletRequest request) {
        login.setRemoteAddr(request.getRemoteAddr());
        return authenticationService.login(login);
    }

    @RequestMapping(value = "/register", method = GET)
    public @ResponseBody
    AuthenticationFlows getRegistrationSchemas() {
        return authenticationService.getSupportedFlows();
    }

    @RequestMapping(value = "/register", method = POST)
    public @ResponseBody
// Path: src/main/java/org/swarmcom/jsynapse/controller/JsynapseApi.java
// public class JsynapseApi {
// 
//     public static final String CLIENT_V1_API = "/_matrix/client/api/v1";
//     public static final String CONTENT_V1_API = "/_matrix/media/v1";
// 
//     @ExceptionHandler
//     @ResponseStatus(NOT_FOUND)
//     public String handleEntityNotFound(EntityNotFoundException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(CONFLICT)
//     public String handleEntityAlreadyExists(EntityAlreadyExistsException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(BAD_REQUEST)
//     public String handleInvalidRequest(InvalidRequestException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(FORBIDDEN)
//     public String handleTokenNotFound(TokenNotFoundException ex) {
//         return ex.getMessage();
//     }
// 
//     @ExceptionHandler
//     @ResponseStatus(BAD_REQUEST)
//     public String handleValidationException(ValidationException ex) {
//         return ex.getMessage();
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/Authentication.java
// public static class AuthenticationResult {
// 
//     @JsonProperty("user_id")
//     String user;
// 
//     @JsonProperty("access_token")
//     String accessToken;
// 
//     public AuthenticationResult(String user, String accessToken) {
//         this.user = user;
//         this.accessToken = accessToken;
//     }
// 
//     public String getUser() {
//         return user;
//     }
// 
//     public void setUser(String user) {
//         this.user = user;
//     }
// 
//     public String getAccessToken() {
//         return accessToken;
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/Authentication.java
// public static class AuthenticationSubmission extends HashMap<String, String> {
//     static final String TYPE = "type";
//     static final String REMOTE_ADDR = "remoteAddr";
// 
//     public AuthenticationSubmission() {
//     }
// 
//     public String getType() {
//         return get(TYPE);
//     }
// 
//     public void setRemoteAddr(String remoteAddr) {
//         put(REMOTE_ADDR, remoteAddr);
//     }
// 
//     public String getRemoteAddr() {
//         return get(REMOTE_ADDR);
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/domain/Authentication.java
// public static class AuthenticationFlows {
// 
//     @JsonProperty
//     List<AuthenticationInfo> flows = new LinkedList<>();
// 
//     public AuthenticationFlows(List<AuthenticationInfo> flows) {
//         this.flows = flows;
//     }
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/service/authentication/AuthenticationService.java
// public interface AuthenticationService {
//     AuthenticationFlows getSupportedFlows();
// 
//     AuthenticationResult register(AuthenticationSubmission authentication);
// 
//     AuthenticationResult login(AuthenticationSubmission authentication);
// }
// 
// Path: src/main/java/org/swarmcom/jsynapse/controller/JsynapseApi.java
// public static final String CLIENT_V1_API = "/_matrix/client/api/v1";


// Path: src/main/java/org/swarmcom/jsynapse/controller/client/api/v1/AuthenticationRestApi.java
import org.springframework.web.bind.annotation.*;
import org.swarmcom.jsynapse.controller.JsynapseApi;
import org.swarmcom.jsynapse.domain.Authentication.AuthenticationResult;
import org.swarmcom.jsynapse.domain.Authentication.AuthenticationSubmission;
import org.swarmcom.jsynapse.domain.Authentication.AuthenticationFlows;
import org.swarmcom.jsynapse.service.authentication.AuthenticationService;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import static org.swarmcom.jsynapse.controller.JsynapseApi.CLIENT_V1_API;

/*
 * (C) Copyright 2015 eZuce Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
package org.swarmcom.jsynapse.controller.client.api.v1;




@RestController
@RequestMapping(value = CLIENT_V1_API)
public class AuthenticationRestApi extends JsynapseApi {

    private final AuthenticationService authenticationService;

    @Inject
    public AuthenticationRestApi(final AuthenticationService authenticationService) {
        this.authenticationService = authenticationService;
    }

    @RequestMapping(value = "/login", method = GET)
    public @ResponseBody
    AuthenticationFlows getLoginSchemas() {
        return authenticationService.getSupportedFlows();
    }

    @RequestMapping(value = "/login", method = POST)
    public @ResponseBody
    AuthenticationResult login(@RequestBody final AuthenticationSubmission login, HttpServletRequest request) {
        login.setRemoteAddr(request.getRemoteAddr());
        return authenticationService.login(login);
    }

    @RequestMapping(value = "/register", method = GET)
    public @ResponseBody
    AuthenticationFlows getRegistrationSchemas() {
        return authenticationService.getSupportedFlows();
    }

    @RequestMapping(value = "/register", method = POST)
    public @ResponseBody
    AuthenticationResult register(@RequestBody final AuthenticationSubmission registration, HttpServletRequest request) {