33 lines
1.2 KiB
Java
33 lines
1.2 KiB
Java
|
package eu.eudat.handlers;
|
||
|
|
||
|
import eu.eudat.models.security.Principal;
|
||
|
import org.springframework.core.MethodParameter;
|
||
|
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||
|
import org.springframework.web.context.request.NativeWebRequest;
|
||
|
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||
|
|
||
|
import java.util.Date;
|
||
|
import java.util.UUID;
|
||
|
|
||
|
/**
|
||
|
* Created by ikalyvas on 12/15/2017.
|
||
|
*/
|
||
|
public final class PrincipalArgumentResolver implements HandlerMethodArgumentResolver {
|
||
|
|
||
|
@Override
|
||
|
public boolean supportsParameter(MethodParameter methodParameter) {
|
||
|
return methodParameter.getParameterType().equals(Principal.class);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Object resolveArgument(MethodParameter methodParameter,ModelAndViewContainer modelAndViewContainer,NativeWebRequest nativeWebRequest,WebDataBinderFactory webDataBinderFactory) throws Exception {
|
||
|
Principal principal = new Principal();
|
||
|
principal.setName("Giannis");
|
||
|
principal.setId(UUID.randomUUID());
|
||
|
principal.setExpiresAt(new Date());
|
||
|
principal.setToken(UUID.randomUUID());
|
||
|
return principal;
|
||
|
}
|
||
|
|
||
|
}
|