All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.muserver.rest.MuSecurityContext Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package io.muserver.rest;

import javax.ws.rs.core.SecurityContext;
import java.security.Principal;

class MuSecurityContext implements SecurityContext {

    private final Principal principal;
    private final Authorizer authorizer;
    private final boolean isHttps;
    private final String authenticationScheme;

    MuSecurityContext(Principal principal, Authorizer authorizer, boolean isHttps, String authenticationScheme) {
        this.principal = principal;
        this.authorizer = authorizer;
        this.isHttps = isHttps;
        this.authenticationScheme = authenticationScheme;
    }

    @Override
    public Principal getUserPrincipal() {
        return principal;
    }

    @Override
    public boolean isUserInRole(String role) {
        return authorizer.isInRole(principal, role);
    }

    @Override
    public boolean isSecure() {
        return isHttps;
    }

    @Override
    public String getAuthenticationScheme() {
        return authenticationScheme;
    }

    static final MuSecurityContext notLoggedInHttpContext = new MuSecurityContext(null, (principal1, role) -> false, false, null);
    static final MuSecurityContext notLoggedInHttpsContext = new MuSecurityContext(null, (principal1, role) -> false, true, null);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy