/*
 * Copyright 2016 Lime - HighTech Solutions s.r.o.
 *
 * 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 io.getlime.security.powerauth.app.rest.api.spring.controller;

import io.getlime.security.powerauth.rest.api.base.authentication.PowerAuthApiAuthentication;
import io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException;
import io.getlime.security.powerauth.rest.api.model.base.PowerAuthApiResponse;
import io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Sample end-point demonstrating how PowerAuth signature validation works.
 *
 * @author Petr Dvorak
 *
 */
@Controller
@RequestMapping(value = "pa/signature")
public class AuthenticationController {

    /**
     * Validate any data sent to this end-point.
     * @return API response with success.
     * @throws Exception In case any error occurs, including during signature validation.
     */
    @RequestMapping(value = "validate", method = RequestMethod.POST)
    @PowerAuth(resourceId = "/pa/signature/validate")
    public @ResponseBody PowerAuthApiResponse<String> login(PowerAuthApiAuthentication auth) throws PowerAuthAuthenticationException {

        // ##EXAMPLE: Here, we could store the authentication in the session like this:
        // ##EXAMPLE: SecurityContextHolder.getContext().setAuthentication(apiAuthentication);
        // ##EXAMPLE: ... or you can grab a user ID like this and use it for querying back-end:
        // ##EXAMPLE: String userId = apiAuthentication.getUserId();

        if (auth != null && auth.getUserId() != null) {
            return new PowerAuthApiResponse<>(PowerAuthApiResponse.Status.OK, "Hooray! User: " + auth.getUserId());
        } else {
            throw new PowerAuthAuthenticationException("Login failed");
        }

    }

}

@@ -1194,16 +1194,77 @@
 Method;%0A
+import org.springframework.web.bind.annotation.RequestParam;%0A
 import o
@@ -1316,16 +1316,16 @@
 seBody;%0A
-
 %0A/**%0A * 
@@ -1580,16 +1580,91 @@
 -point.%0A
+     * @param auth Automatically injected PowerAuth authetnication object.%0A
      * @
@@ -1918,16 +1918,16 @@
 idate%22)%0A
-
     publ
@@ -2682,10 +2682,1171 @@
 %0A    %7D%0A%0A
+    /**%0A     * Validate any data sent to this end-point.%0A     * @param auth Automatically injected PowerAuth authentication object.%0A     * @return API response with success.%0A     * @throws Exception In case any error occurs, including during signature validation.%0A     */%0A    @RequestMapping(value = %22validate%22, method = RequestMethod.GET)%0A    @PowerAuth(resourceId = %22/pa/signature/validate%22)%0A    public @ResponseBody PowerAuthApiResponse%3CString%3E getLogin(PowerAuthApiAuthentication auth) throws PowerAuthAuthenticationException %7B%0A%0A        // ##EXAMPLE: Here, we could store the authentication in the session like this:%0A        // ##EXAMPLE: SecurityContextHolder.getContext().setAuthentication(apiAuthentication);%0A        // ##EXAMPLE: ... or you can grab a user ID like this and use it for querying back-end:%0A        // ##EXAMPLE: String userId = apiAuthentication.getUserId();%0A%0A        if (auth != null && auth.getUserId() != null) %7B%0A            return new PowerAuthApiResponse%3C%3E(PowerAuthApiResponse.Status.OK, %22Hooray! User: %22 + auth.getUserId());%0A        %7D else %7B%0A            throw new PowerAuthAuthenticationException(%22Login failed%22);%0A        %7D%0A%0A    %7D%0A%0A
 %7D%0A

Add GET method to the sample authentication controller