<commit_before>/*
 * 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 <NAME>
 *
 */
@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");
        }

    }

}<commit_msg>Add GET method to the sample authentication controller<commit_after>/*
 * 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

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

    /**
     * Validate any data sent to this end-point.
     * @param auth Automatically injected PowerAuth authetnication object.
     * @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");
        }

    }

    /**
     * Validate any data sent to this end-point.
     * @param auth Automatically injected PowerAuth authentication object.
     * @return API response with success.
     * @throws Exception In case any error occurs, including during signature validation.
     */
    @RequestMapping(value = "validate", method = RequestMethod.GET)
    @PowerAuth(resourceId = "/pa/signature/validate")
    public @ResponseBody PowerAuthApiResponse<String> getLogin(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");
        }

    }

}
{'fraction_non_alphanumeric': 0.09784283513097072, 'fraction_numerical': 0.002465331278890601, 'mean_word_length': 3.898867924528302, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6278785', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1649, 'n_words': 519}