Search in sources :

Example 6 with SecurityContext

use of org.acegisecurity.context.SecurityContext in project blueocean-plugin by jenkinsci.

the class BlueOceanRootAction method getTarget.

@Override
public Object getTarget() {
    StaplerRequest request = Stapler.getCurrentRequest();
    if (request.getOriginalRestOfPath().startsWith("/rest/")) {
        if (enableJWT) {
            Authentication tokenAuthentication = JwtAuthenticationToken.create(request);
            //create a new context and set it to holder to not clobber existing context
            SecurityContext securityContext = new SecurityContextImpl();
            securityContext.setAuthentication(tokenAuthentication);
            SecurityContextHolder.setContext(securityContext);
        //TODO: implement this as filter, see PluginServletFilter to clear the context
        } else {
            HashCode hashCode = Hashing.sha1().newHasher().putString(Jenkins.getAuthentication().getName(), StandardCharsets.UTF_8).putLong(randomBits).hash();
            // Base64 encode to ensure no non-ASCII characters get into the header
            String refresherToken = Base64.encode(hashCode.asBytes());
            Stapler.getCurrentResponse().setHeader("X-Blueocean-Refresher", refresherToken);
        }
    } else {
        //If user doesn't have overall Jenkins read permission then return 403, which results in classic UI redirecting
        // user to login page
        Jenkins.getInstance().checkPermission(Jenkins.READ);
    }
    return app;
}
Also used : SecurityContextImpl(org.acegisecurity.context.SecurityContextImpl) HashCode(com.google.common.hash.HashCode) Authentication(org.acegisecurity.Authentication) StaplerRequest(org.kohsuke.stapler.StaplerRequest) SecurityContext(org.acegisecurity.context.SecurityContext)

Aggregations

Authentication (org.acegisecurity.Authentication)6 SecurityContext (org.acegisecurity.context.SecurityContext)6 CliAuthenticator (hudson.security.CliAuthenticator)2 IOException (java.io.IOException)2 ClassParser (org.kohsuke.args4j.ClassParser)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 CmdLineParser (org.kohsuke.args4j.CmdLineParser)2 HashCode (com.google.common.hash.HashCode)1 AbortException (hudson.AbortException)1 ExtensionComponent (hudson.ExtensionComponent)1 CLICommand (hudson.cli.CLICommand)1 CloneableCLICommand (hudson.cli.CloneableCLICommand)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1