Search in sources :

Example 6 with AuthenticationPrincipal

use of org.springframework.security.core.annotation.AuthenticationPrincipal in project spring-security by spring-projects.

the class AuthenticationPrincipalArgumentResolver method resolvePrincipal.

private Object resolvePrincipal(MethodParameter parameter, Object principal) {
    AuthenticationPrincipal authPrincipal = findMethodAnnotation(AuthenticationPrincipal.class, parameter);
    String expressionToParse = authPrincipal.expression();
    if (StringUtils.hasLength(expressionToParse)) {
        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setRootObject(principal);
        context.setVariable("this", principal);
        context.setBeanResolver(this.beanResolver);
        Expression expression = this.parser.parseExpression(expressionToParse);
        principal = expression.getValue(context);
    }
    if (isInvalidType(parameter, principal)) {
        if (authPrincipal.errorOnInvalidType()) {
            throw new ClassCastException(principal + " is not assignable to " + parameter.getParameterType());
        }
        return null;
    }
    return principal;
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal)

Aggregations

AuthenticationPrincipal (org.springframework.security.core.annotation.AuthenticationPrincipal)6 Expression (org.springframework.expression.Expression)4 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)4 RQLToObjectListQuery (com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery)2 BulkRequest (com.infiniteautomation.mango.rest.v2.bulk.BulkRequest)2 BulkResponse (com.infiniteautomation.mango.rest.v2.bulk.BulkResponse)2 AbstractRestV2Exception (com.infiniteautomation.mango.rest.v2.exception.AbstractRestV2Exception)2 AccessDeniedException (com.infiniteautomation.mango.rest.v2.exception.AccessDeniedException)2 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)2 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)2 MangoTaskTemporaryResourceManager (com.infiniteautomation.mango.rest.v2.temporaryResource.MangoTaskTemporaryResourceManager)2 TemporaryResource (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource)2 TemporaryResourceStatus (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource.TemporaryResourceStatus)2 TemporaryResourceManager (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceManager)2 TemporaryResourceStatusUpdate (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceStatusUpdate)2 TemporaryResourceWebSocketHandler (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResourceWebSocketHandler)2 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2