
io.getlime.security.powerauth.rest.api.spring.provider.MinimalClaimsUserInfoProvider Maven / Gradle / Ivy
Show all versions of powerauth-restful-security-spring-annotation Show documentation
/*
* PowerAuth integration libraries for RESTful API applications, examples and
* related software components
*
* Copyright (C) 2023 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package io.getlime.security.powerauth.rest.api.spring.provider;
import com.wultra.core.annotations.PublicSpi;
import io.getlime.security.powerauth.rest.api.spring.model.UserInfoContext;
import jakarta.annotation.Nonnull;
import java.time.Instant;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
/**
* Specialization of {@link UserInfoProvider}.
* Claims {@code sub, jti, iat} are filled.
* UserInfo is always returned, even for activation.
*
* @author Lubos Racansky, [email protected]
*/
@PublicSpi
public class MinimalClaimsUserInfoProvider implements UserInfoProvider{
/**
* Always true, even for activation.
*
* {@inheritDoc}
*/
@Override
public boolean shouldReturnUserInfo(@Nonnull UserInfoContext context) {
return true;
}
/**
* Fill claims {@code sub, jti, iat}.
*
* {@inheritDoc}
*/
@Override
public Map fetchUserClaimsForUserId(@Nonnull UserInfoContext context) {
return minimalClaims(context);
}
/**
* Prepare a set of minimal claims sub
, jti
and iat
.
*
* @param context User info context object.
* @return Map of claims obtained for a given user ID.
*/
private static Map minimalClaims(@Nonnull UserInfoContext context) {
final Map defaultClaims = new LinkedHashMap<>();
defaultClaims.put("sub", context.getUserId());
defaultClaims.put("jti", UUID.randomUUID().toString());
defaultClaims.put("iat", Instant.now().getEpochSecond());
return Collections.unmodifiableMap(defaultClaims);
}
}