Package org.acegisecurity.context

Examples of org.acegisecurity.context.SecurityContext


public class AcegiWorkflowContextHandlerInterceptorDifferentProviderTests extends AbstractWorkflowContextHandlerInterceptorTests {


  protected MockHttpServletRequest getMockRequest(String userName) {
    Authentication auth = new AnonymousAuthenticationToken(userName, userName, new GrantedAuthority[]{ new GrantedAuthorityImpl(userName) });
    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(auth);
    SecurityContextHolder.setContext(context);

    return new MockHttpServletRequest();
  }
View Full Code Here



  protected MockHttpServletRequest getMockRequest(String userName) {
    User user = new User(userName, "dummy", true, true, true, true, new GrantedAuthority[]{});
    Authentication auth = new UsernamePasswordAuthenticationToken(user, null);
    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(auth);
    SecurityContextHolder.setContext(context);

    return new MockHttpServletRequest();
  }
View Full Code Here

* @author robh
*/
public class AcegiWorkflowContextHandlerInterceptor extends DefaultWorkflowContextHandlerInterceptor {

  protected String getCaller(HttpServletRequest request) {
    SecurityContext context = (SecurityContext) SecurityContextHolder.getContext();
    Object principal = context.getAuthentication().getPrincipal();
    if (principal instanceof UserDetails)
      return ((UserDetails) principal).getUsername();
 
    // fallback mechanism
    return principal.toString();
View Full Code Here

    if (role == null) {
      throw new WorkflowException("Condition [" + getClass().getName() + "] expects argument [" + ROLE + "].");
    }

    SecurityContext securityContext = (SecurityContext) SecurityContextHolder.getContext();
    GrantedAuthority[] authorities = securityContext.getAuthentication().getAuthorities();

    for (int i = 0; i < authorities.length; i++) {
      GrantedAuthority authority = authorities[i];
      if (role.equals(authority.getAuthority())) {
        return true;
View Full Code Here

        assertTrue(validate(new Person(30, "Steven"), text));
    }

    public void testParser39InRoleRule() {

        SecurityContext context = new SecurityContextImpl();
        GrantedAuthority[] roles = new GrantedAuthority[] { new GrantedAuthorityImpl("ADMIN_ROLE"),
                new GrantedAuthorityImpl("USER_ROLE") };
        context.setAuthentication(new TestingAuthenticationToken("username", "username", roles));
        SecurityContextHolder.setContext(context);

        String text = "{firstName: inRole('USER_ROLE') == true : 'Current user must be in USER_ROLE'}";
        assertTrue(validate(new Person(30, "Steven"), text));
    }
View Full Code Here

  public void setUp() {
    GrantedAuthority[] roles = new GrantedAuthority[]{new GrantedAuthorityImpl("manager"), new GrantedAuthorityImpl("vp")};

    Authentication authentication = new UsernamePasswordAuthenticationToken(new Object(), new Object(), roles);

    SecurityContext context = new SecurityContextImpl();
    context.setAuthentication(authentication);

    SecurityContextHolder.setContext(context);

  }
View Full Code Here

    }

    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
View Full Code Here

    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof SecurityContext) {
            SecurityContext test = (SecurityContext) obj;

            if ((this.getAuthentication() == null) && (test.getAuthentication() == null)) {
                return true;
            }

            if ((this.getAuthentication() != null) && (test.getAuthentication() != null)
                && this.getAuthentication().equals(test.getAuthentication())) {
                return true;
            }
        }

        return false;
View Full Code Here

        this.locale = locale;
        registerOptionHandlers();
        CmdLineParser p = new CmdLineParser(this);

        // add options from the authenticator
        SecurityContext sc = SecurityContextHolder.getContext();
        Authentication old = sc.getAuthentication();

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

        try {
            p.parseArgument(args.toArray(new String[args.size()]));
            Authentication auth = authenticator.authenticate();
            if (auth==Jenkins.ANONYMOUS)
                auth = loadStoredAuthentication();
            sc.setAuthentication(auth); // run the CLI with the right credential
            if (!(this instanceof LoginCommand || this instanceof HelpCommand))
                Jenkins.getInstance().checkPermission(Jenkins.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 {
            sc.setAuthentication(old); // restore
        }
    }
View Full Code Here

    }
   
    public void build() {
        // Set full privileges while computing to avoid missing any projects the current user cannot see.
        // Use setContext (NOT getContext().setAuthentication()) so we don't affect concurrent threads for same HttpSession.
        SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
        try {
            this.computationalData = new HashMap<Class<?>, Object>();
            for( AbstractProject p : getAllProjects() )
                p.buildDependencyGraph(this);
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.