Package org.acegisecurity.context

Examples of org.acegisecurity.context.SecurityContext


            super._run();

            // if this is a bundled plugin, make sure it won't get overwritten
            PluginWrapper pw = plugin.getInstalled();
            if (pw!=null && pw.isBundled()) {
                SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM);
                try {
                    pw.doPin();
                } finally {
                    SecurityContextHolder.setContext(oldContext);
                }
View Full Code Here


                User u = User.get(username);
                ApiTokenProperty t = u.getProperty(ApiTokenProperty.class);
                if (t!=null && t.matchesPassword(password)) {
                    // even if we fail to match the password, we aren't rejecting it.
                    // as the user might be passing in a real password.
                    SecurityContext oldContext = ACL.impersonate(u.impersonate());
                    try {
                        chain.doFilter(request,response);
                        return;
                    } finally {
                        SecurityContextHolder.setContext(oldContext);
View Full Code Here

*/
public abstract class SafeTimerTask extends TimerTask {
    public final void run() {
        // background activity gets system credential,
        // just like executors get it.
        SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM);
        try {
            doRun();
        } catch(Throwable t) {
            LOGGER.log(Level.SEVERE, "Timer task "+this+" failed",t);
        } finally {
View Full Code Here

                            this.locale = locale;

                            registerOptionHandlers();
                            CmdLineParser parser = new CmdLineParser(null);
                            try {
                                SecurityContext sc = SecurityContextHolder.getContext();
                                Authentication old = sc.getAuthentication();
                                try {
                                    //  build up the call sequence
                                    Stack<Method> chains = new Stack<Method>();
                                    Method method = m;
                                    while (true) {
                                        chains.push(method);
                                        if (Modifier.isStatic(method.getModifiers()))
                                            break; // the chain is complete.

                                        // the method in question is an instance method, so we need to resolve the instance by using another resolver
                                        Class<?> type = method.getDeclaringClass();
                                        method = findResolver(type);
                                        if (method==null) {
                                            stderr.println("Unable to find the resolver method annotated with @CLIResolver for "+type);
                                            return 1;
                                        }
                                    }

                                    List<MethodBinder> binders = new ArrayList<MethodBinder>();

                                    while (!chains.isEmpty())
                                        binders.add(new MethodBinder(chains.pop(),this,parser));

                                    // authentication
                                    CliAuthenticator authenticator = Jenkins.getInstance().getSecurityRealm().createCliAuthenticator(this);
                                    new ClassParser().parse(authenticator,parser);

                                    // fill up all the binders
                                    parser.parseArgument(args);

                                    Authentication auth = authenticator.authenticate();
                                    if (auth== Jenkins.ANONYMOUS)
                                        auth = loadStoredAuthentication();
                                    sc.setAuthentication(auth); // run the CLI with the right credential
                                    hudson.checkPermission(Jenkins.READ);

                                    // resolve them
                                    Object instance = null;
                                    for (MethodBinder binder : binders)
                                        instance = binder.call(instance);

                                    if (instance instanceof Integer)
                                        return (Integer) instance;
                                    else
                                        return 0;
                                } catch (InvocationTargetException e) {
                                    Throwable t = e.getTargetException();
                                    if (t instanceof Exception)
                                        throw (Exception) t;
                                    throw e;
                                } finally {
                                    sc.setAuthentication(old); // restore
                                }
                            } catch (CmdLineException e) {
                                stderr.println(e.getMessage());
                                printUsage(stderr,parser);
                                return 1;
View Full Code Here

    public DependencyRunner(ProjectRunnable runnable) {
        this.runnable = runnable;
    }

    public void run() {
        SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM);
        try {
            Set<AbstractProject> topLevelProjects = new HashSet<AbstractProject>();
            // Get all top-level projects
            LOGGER.fine("assembling top level projects");
            for (AbstractProject p : Jenkins.getInstance().getAllItems(AbstractProject.class))
View Full Code Here

        GithubAuthenticationToken token = PowerMockito.mock(GithubAuthenticationToken.class);
        PowerMockito.when(token.getGitHub()).thenReturn(github);
        PowerMockito.when(token.getAccessToken()).thenReturn("thisismytoken");
        PowerMockito.when(token.getName()).thenReturn("thisismyname");

        SecurityContext context = PowerMockito.mock(SecurityContext.class);
        PowerMockito.when(context.getAuthentication()).thenReturn(token);
        SecurityContextHolder.setContext(context);

        return ghRepository;
    }
View Full Code Here

     * <p>
     * We need to create a new {@link SecurityContext} instead of {@link SecurityContext#setAuthentication(Authentication)}
     * because the same {@link SecurityContext} object is reused for all the concurrent requests from the same session.
     */
    public static SecurityContext impersonate(Authentication auth) {
        SecurityContext old = SecurityContextHolder.getContext();
        SecurityContextHolder.setContext(new NotSerilizableSecurityContext(auth));
        return old;
    }
View Full Code Here

        }

        //attempt authentication if j_secuity_check is present or if the getDefaultTargetUrl()
        //is present and user is not already authenticated.
        boolean bAuthenticated = false;
        SecurityContext context = (SecurityContext)
                request.getSession().getAttribute(HttpSessionContextIntegrationFilter.ACEGI_SECURITY_CONTEXT_KEY);

        if (context != null) {
            Authentication auth = context.getAuthentication();

            if ((auth != null) && auth instanceof UsernamePasswordAuthenticationToken) {
                UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) auth;
                bAuthenticated = token.isAuthenticated();
            }
View Full Code Here

     * SecurityContextHolder we are logging out a session that is not related to the current user.</b>
     *
     * @param event
     */
    protected void handleLogout(HttpSessionDestroyedEvent event) {
        SecurityContext context = (SecurityContext)
                event.getSession().getAttribute(HttpSessionContextIntegrationFilter.ACEGI_SECURITY_CONTEXT_KEY);

        if (context == null) {
            log.debug("The destroyed session has no SecurityContext");

            return;
        }

        Authentication auth = context.getAuthentication();

        if ((auth != null) && (auth instanceof JaasAuthenticationToken)) {
            JaasAuthenticationToken token = (JaasAuthenticationToken) auth;

            try {
View Full Code Here

     * Retrieves the Id of the currently authenticated in user that is performing these data operations.
     *
     * @return Integer
     */
    private Integer getAuthenticatedExecutingUser() {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if(securityContext != null) {
            UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) securityContext.getAuthentication();
            if(authentication != null) {
                Object detail = authentication.getDetails();
                if(detail != null && detail instanceof AuthenticatedUserVo) {
                    return ((AuthenticatedUserVo)detail).getUserId();
                }
View Full Code Here

TOP

Related Classes of org.acegisecurity.context.SecurityContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.