// Path: core/src/main/java/org/juiser/model/User.java
// public interface User {
// 
//     /**
//      * Returns {@code true} if the user has been authenticated (proven their identity) or {@code false} if the user
//      * is considered anonymous.
//      *
//      * @return {@code true} if the user has been authenticated (proven their identity) or {@code false} if the user
//      * is considered anonymous.
//      */
//     boolean isAuthenticated();
// 
//     /**
//      * Returns {@code true} if the user identity is unknown, {@code false} if the user is authenticated.
//      *
//      * @return {@code true} if the user identity is unknown, {@code false} if the user is authenticated.
//      */
//     boolean isAnonymous();
// 
//     String getHref();
// 
//     String getId();
// 
//     String getName(); //full name
// 
//     String getGivenName(); //aka 'first name' in Western cultures
// 
//     String getFamilyName(); //aka surname
// 
//     String getMiddleName();
// 
//     String getNickname(); //aka 'Mike' if givenName is 'Michael'
// 
//     String getUsername(); //OIDC 'preferred_username'
// 
//     URL getProfile();
// 
//     URL getPicture();
// 
//     URL getWebsite();
// 
//     String getEmail();
// 
//     boolean isEmailVerified();
// 
//     String getGender();
// 
//     LocalDate getBirthdate();
// 
//     TimeZone getZoneInfo();
// 
//     Locale getLocale();
// 
//     Phone getPhone();
// 
//     String getPhoneNumber();
// 
//     boolean isPhoneNumberVerified();
// 
//     ZonedDateTime getCreatedAt();
// 
//     ZonedDateTime getUpdatedAt();
// }


import io.jsonwebtoken.lang.Assert;
import org.juiser.model.User;
import javax.servlet.http.HttpServletRequest;
import java.util.function.Function;
/*
 * Copyright 2017 Les Hazlewood and the respective Juiser contributors
 *
 * 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.juiser.servlet;



/**
 * Inspects a Request header and creates a {@link User} instance based on the header value.  Binding the resulting
 * User to the request (or anywhere else) is the responsibility of the caller.
 *
 * @since 1.0.0
 */
public class RequestHeaderUserFactory implements Function<HttpServletRequest, User> {

    private final String headerName;

    private final Function<String, User> headerValueToUser;

// Path: core/src/main/java/org/juiser/model/User.java
// public interface User {
// 
//     /**
//      * Returns {@code true} if the user has been authenticated (proven their identity) or {@code false} if the user
//      * is considered anonymous.
//      *
//      * @return {@code true} if the user has been authenticated (proven their identity) or {@code false} if the user
//      * is considered anonymous.
//      */
//     boolean isAuthenticated();
// 
//     /**
//      * Returns {@code true} if the user identity is unknown, {@code false} if the user is authenticated.
//      *
//      * @return {@code true} if the user identity is unknown, {@code false} if the user is authenticated.
//      */
//     boolean isAnonymous();
// 
//     String getHref();
// 
//     String getId();
// 
//     String getName(); //full name
// 
//     String getGivenName(); //aka 'first name' in Western cultures
// 
//     String getFamilyName(); //aka surname
// 
//     String getMiddleName();
// 
//     String getNickname(); //aka 'Mike' if givenName is 'Michael'
// 
//     String getUsername(); //OIDC 'preferred_username'
// 
//     URL getProfile();
// 
//     URL getPicture();
// 
//     URL getWebsite();
// 
//     String getEmail();
// 
//     boolean isEmailVerified();
// 
//     String getGender();
// 
//     LocalDate getBirthdate();
// 
//     TimeZone getZoneInfo();
// 
//     Locale getLocale();
// 
//     Phone getPhone();
// 
//     String getPhoneNumber();
// 
//     boolean isPhoneNumberVerified();
// 
//     ZonedDateTime getCreatedAt();
// 
//     ZonedDateTime getUpdatedAt();
// }


// Path: servlet/src/main/java/org/juiser/servlet/RequestHeaderUserFactory.java
import io.jsonwebtoken.lang.Assert;
import org.juiser.model.User;
import javax.servlet.http.HttpServletRequest;
import java.util.function.Function;

/*
 * Copyright 2017 Les Hazlewood and the respective Juiser contributors
 *
 * 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.juiser.servlet;



/**
 * Inspects a Request header and creates a {@link User} instance based on the header value.  Binding the resulting
 * User to the request (or anywhere else) is the responsibility of the caller.
 *
 * @since 1.0.0
 */
public class RequestHeaderUserFactory implements Function<HttpServletRequest, User> {

    private final String headerName;

    private final Function<String, User> headerValueToUser;

    public RequestHeaderUserFactory(String headerName, Function<String, User> headerValueToUserConverter) {