Search in sources :

Example 1 with JwtTokenServiceEndpoint

use of io.jenkins.blueocean.auth.jwt.JwtTokenServiceEndpoint in project blueocean-plugin by jenkinsci.

the class BlueOceanConfigStatePreloader method getStateJson.

/**
 * {@inheritDoc}
 */
@Override
public String getStateJson() {
    StringWriter writer = new StringWriter();
    Jenkins jenkins = Jenkins.get();
    VersionNumber versionNumber = Jenkins.getVersion();
    String version = versionNumber != null ? versionNumber.toString() : Jenkins.VERSION;
    AuthorizationStrategy authorizationStrategy = jenkins.getAuthorizationStrategy();
    boolean allowAnonymousRead = true;
    if (authorizationStrategy instanceof FullControlOnceLoggedInAuthorizationStrategy) {
        allowAnonymousRead = ((FullControlOnceLoggedInAuthorizationStrategy) authorizationStrategy).isAllowAnonymousRead();
    }
    String jwtTokenEndpointHostUrl = Jenkins.get().getRootUrl();
    JwtTokenServiceEndpoint jwtTokenServiceEndpoint = JwtTokenServiceEndpoint.first();
    if (jwtTokenServiceEndpoint != null) {
        jwtTokenEndpointHostUrl = jwtTokenServiceEndpoint.getHostUrl();
    }
    addFeatures(new JSONBuilder(writer).object().key("version").value(getBlueOceanPluginVersion()).key("jenkinsConfig").object().key("analytics").value(Analytics.isAnalyticsEnabled()).key("version").value(version).key("security").object().key("enabled").value(jenkins.isUseSecurity()).key("loginUrl").value(jenkins.getSecurityRealm() == SecurityRealm.NO_AUTHENTICATION ? null : jenkins.getSecurityRealm().getLoginUrl()).key("authorizationStrategy").object().key("allowAnonymousRead").value(allowAnonymousRead).endObject().key("enableJWT").value(BlueOceanConfigProperties.BLUEOCEAN_FEATURE_JWT_AUTHENTICATION).key("jwtServiceHostUrl").value(jwtTokenEndpointHostUrl).endObject().endObject()).endObject();
    return writer.toString();
}
Also used : Jenkins(jenkins.model.Jenkins) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) AuthorizationStrategy(hudson.security.AuthorizationStrategy) JwtTokenServiceEndpoint(io.jenkins.blueocean.auth.jwt.JwtTokenServiceEndpoint) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) JSONBuilder(net.sf.json.util.JSONBuilder) StringWriter(java.io.StringWriter) VersionNumber(hudson.util.VersionNumber)

Aggregations

AuthorizationStrategy (hudson.security.AuthorizationStrategy)1 FullControlOnceLoggedInAuthorizationStrategy (hudson.security.FullControlOnceLoggedInAuthorizationStrategy)1 VersionNumber (hudson.util.VersionNumber)1 JwtTokenServiceEndpoint (io.jenkins.blueocean.auth.jwt.JwtTokenServiceEndpoint)1 StringWriter (java.io.StringWriter)1 Jenkins (jenkins.model.Jenkins)1 JSONBuilder (net.sf.json.util.JSONBuilder)1