use of hudson.Plugin in project blueocean-plugin by jenkinsci.
the class JwtImpl method getToken.
@Override
public JwtToken getToken(@Nullable @QueryParameter("expiryTimeInMins") Integer expiryTimeInMins, @Nullable @QueryParameter("maxExpiryTimeInMins") Integer maxExpiryTimeInMins) {
String t = System.getProperty("EXPIRY_TIME_IN_MINS");
long expiryTime = DEFAULT_EXPIRY_IN_SEC;
if (t != null) {
expiryTime = Integer.parseInt(t);
}
int maxExpiryTime = DEFAULT_MAX_EXPIRY_TIME_IN_MIN;
t = System.getProperty("MAX_EXPIRY_TIME_IN_MINS");
if (t != null) {
maxExpiryTime = Integer.parseInt(t);
}
if (maxExpiryTimeInMins != null) {
maxExpiryTime = maxExpiryTimeInMins;
}
if (expiryTimeInMins != null) {
if (expiryTimeInMins > maxExpiryTime) {
throw new ServiceException.BadRequestExpception(String.format("expiryTimeInMins %s can't be greated than %s", expiryTimeInMins, maxExpiryTime));
}
expiryTime = expiryTimeInMins * 60;
}
Authentication authentication = Jenkins.getInstance().getAuthentication();
if (authentication == null) {
throw new ServiceException.UnauthorizedException("Unauthorized: No login session found");
}
String userId = authentication.getName();
User user = User.get(userId, false, Collections.emptyMap());
String email = null;
String fullName = null;
if (user != null) {
fullName = user.getFullName();
userId = user.getId();
Mailer.UserProperty p = user.getProperty(Mailer.UserProperty.class);
if (p != null)
email = p.getAddress();
}
Plugin plugin = Jenkins.getInstance().getPlugin("blueocean-jwt");
String issuer = "blueocean-jwt:" + ((plugin != null) ? plugin.getWrapper().getVersion() : "");
JwtToken jwtToken = new JwtToken();
jwtToken.claim.put("jti", UUID.randomUUID().toString().replace("-", ""));
jwtToken.claim.put("iss", issuer);
jwtToken.claim.put("sub", userId);
jwtToken.claim.put("name", fullName);
long currentTime = System.currentTimeMillis() / 1000;
jwtToken.claim.put("iat", currentTime);
jwtToken.claim.put("exp", currentTime + expiryTime);
jwtToken.claim.put("nbf", currentTime - DEFAULT_NOT_BEFORE_IN_SEC);
//set claim
JSONObject context = new JSONObject();
JSONObject userObject = new JSONObject();
userObject.put("id", userId);
userObject.put("fullName", fullName);
userObject.put("email", email);
context.put("user", userObject);
jwtToken.claim.put("context", context);
return jwtToken;
}
use of hudson.Plugin in project blueocean-plugin by jenkinsci.
the class PipelineSearch method search.
@Override
public Pageable<BluePipeline> search(Query q) {
String s = q.param(EXCLUDED_FROM_FLATTENING_PARAM);
String org = q.param(ORGANIZATION_PARAM);
if (org != null && !OrganizationImpl.INSTANCE.getName().equals(org)) {
throw new ServiceException.BadRequestExpception(String.format("Organization %s not found. Query parameter %s value: %s is invalid. ", org, ORGANIZATION_PARAM, org));
}
List<Class> excludeList = new ArrayList<>();
if (s != null) {
for (String s1 : s.split(",")) {
Class c = null;
try {
c = Class.forName(s1);
} catch (ClassNotFoundException e) {
try {
//TODO: There should be better ways to find a class from a plugin.
Plugin p = Jenkins.getInstance().getPlugin("blueocean-pipeline-api-impl");
if (p != null) {
c = p.getWrapper().classLoader.loadClass(s1);
} else {
logger.error("blueocean-pipeline-api-impl plugin not found!");
}
} catch (ClassNotFoundException e1) {
logger.error(e.getMessage(), e1);
}
//ignored, give other OmniSearch implementations chance, they might handle it
//throw new ServiceException.BadRequestExpception(String.format("%s parameter has invalid value: %s", EXCLUDED_FROM_FLATTENING_PARAM, s1), e);
}
if (c != null) {
excludeList.add(c);
}
}
}
Collection<Item> items = new ArrayList<>();
if (!excludeList.isEmpty()) {
for (Item item : Jenkins.getActiveInstance().getAllItems(Item.class)) {
if (!exclude(item.getParent(), excludeList)) {
items.add(item);
}
}
} else {
items = Jenkins.getActiveInstance().getAllItems(Item.class);
}
items = ContainerFilter.filter(items);
final Iterator<BluePipeline> pipelineIterator = new PipelineContainerImpl().getPipelines(items);
final List<BluePipeline> pipelines = new ArrayList<>();
String pipeline = q.param(getType());
if (pipeline == null) {
return Pageables.wrap(new Iterable<BluePipeline>() {
@Override
public Iterator<BluePipeline> iterator() {
return pipelineIterator;
}
});
} else {
while (pipelineIterator.hasNext()) {
BluePipeline p = pipelineIterator.next();
if (!p.getName().equals(pipeline)) {
continue;
}
pipelines.add(p);
}
return Pageables.wrap(pipelines);
}
}
use of hudson.Plugin in project hudson-2.x by hudson.
the class SmoothiePluginStrategy method load.
/**
* Loads the optional {@link hudson.Plugin} instance, configures and starts it.
*/
public void load(final PluginWrapper plugin) throws IOException {
checkNotNull(plugin);
if (log.isDebugEnabled()) {
log.debug("Configuring plugin: {}", plugin.getShortName());
}
container.register(plugin);
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(plugin.classLoader);
try {
Plugin instance;
// Load the plugin instance, if one has been configured.
if (plugin.getPluginClass() == null) {
instance = new Plugin.DummyImpl();
} else {
try {
// Ask the container to construct the instance
Class<? extends Plugin> type = loadPluginClass(plugin);
instance = container.injector(plugin).getInstance(type);
log.trace("Plugin instance: {}", instance);
} catch (Throwable e) {
throw new IOException2("Failed to load plugin instance for: " + plugin.getShortName(), e);
}
}
plugin.setPlugin(instance);
try {
start(plugin);
} catch (Exception e) {
throw new IOException2("Failed to start plugin: " + plugin.getShortName(), e);
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
use of hudson.Plugin in project hudson-2.x by hudson.
the class SmoothiePluginStrategy method start.
/**
* Configures and starts the {@link hudson.Plugin} instance.
*/
private void start(final PluginWrapper plugin) throws Exception {
assert plugin != null;
if (log.isDebugEnabled()) {
log.debug("Starting plugin: {}", plugin.getShortName());
}
Plugin instance = plugin.getPlugin();
instance.setServletContext(Hudson.getInstance().servletContext);
instance.start();
}
Aggregations