use of org.acegisecurity.Authentication in project hudson-2.x by hudson.
the class CLICommand method main.
public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) {
this.stdin = new BufferedInputStream(stdin);
this.stdout = stdout;
this.stderr = stderr;
this.locale = locale;
this.channel = Channel.current();
registerOptionHandlers();
CmdLineParser p = new CmdLineParser(this);
// add options from the authenticator
SecurityContext sc = SecurityContextHolder.getContext();
Authentication old = sc.getAuthentication();
CliAuthenticator authenticator = Hudson.getInstance().getSecurityRealm().createCliAuthenticator(this);
new ClassParser().parse(authenticator, p);
try {
p.parseArgument(args.toArray(new String[args.size()]));
Authentication auth = authenticator.authenticate();
if (auth == Hudson.ANONYMOUS)
auth = loadStoredAuthentication();
// run the CLI with the right credential
sc.setAuthentication(auth);
if (!(this instanceof LoginCommand || this instanceof HelpCommand))
Hudson.getInstance().checkPermission(Hudson.READ);
return run();
} catch (CmdLineException e) {
stderr.println(e.getMessage());
printUsage(stderr, p);
return -1;
} catch (AbortException e) {
// signals an error without stack trace
stderr.println(e.getMessage());
return -1;
} catch (Exception e) {
e.printStackTrace(stderr);
return -1;
} finally {
// restore
sc.setAuthentication(old);
}
}
use of org.acegisecurity.Authentication in project hudson-2.x by hudson.
the class LoginCommand method run.
@Override
protected int run() throws Exception {
Authentication a = Hudson.getAuthentication();
if (a == Hudson.ANONYMOUS)
// this causes CLI to show the command line options.
throw new CmdLineException("No credentials specified.");
ClientAuthenticationCache store = new ClientAuthenticationCache(channel);
store.set(a);
return 0;
}
use of org.acegisecurity.Authentication in project hudson-2.x by hudson.
the class DefaultCrumbIssuer method issueCrumb.
/**
* {@inheritDoc}
*/
@Override
protected String issueCrumb(ServletRequest request, String salt) {
if (request instanceof HttpServletRequest) {
if (md != null) {
HttpServletRequest req = (HttpServletRequest) request;
StringBuilder buffer = new StringBuilder();
Authentication a = Hudson.getAuthentication();
if (a != null) {
buffer.append(a.getName());
}
buffer.append(';');
if (!isExcludeClientIPFromCrumb()) {
buffer.append(getClientIP(req));
}
md.update(buffer.toString().getBytes());
byte[] crumbBytes = md.digest(salt.getBytes());
StringBuilder hexString = new StringBuilder();
for (int i = 0; i < crumbBytes.length; i++) {
String hex = Integer.toHexString(0xFF & crumbBytes[i]);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}
return null;
}
use of org.acegisecurity.Authentication in project hudson-2.x by hudson.
the class HttpSessionContextIntegrationFilter2 method doFilter.
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpSession session = ((HttpServletRequest) req).getSession(false);
if (session != null) {
SecurityContext o = (SecurityContext) session.getAttribute(ACEGI_SECURITY_CONTEXT_KEY);
if (o != null) {
Authentication a = o.getAuthentication();
if (a != null) {
if (a.getPrincipal() instanceof InvalidatableUserDetails) {
InvalidatableUserDetails ud = (InvalidatableUserDetails) a.getPrincipal();
if (ud.isInvalid())
// don't let Acegi see invalid security context
session.setAttribute(ACEGI_SECURITY_CONTEXT_KEY, null);
}
}
}
}
super.doFilter(req, res, chain);
}
use of org.acegisecurity.Authentication in project hudson-2.x by hudson.
the class SecurityServiceImpl method callAs.
public <T> T callAs(final Authentication auth, final Callable<T> task) throws Exception {
checkNotNull(auth);
checkNotNull(task);
final SecurityContext ctx = SecurityContextHolder.getContext();
final Authentication current = ctx.getAuthentication();
ctx.setAuthentication(auth);
try {
return task.call();
} finally {
ctx.setAuthentication(current);
}
}
Aggregations