Package org.acegisecurity.context

Examples of org.acegisecurity.context.SecurityContext


     * 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


            .getAttribute(HttpSessionContextIntegrationFilter.ACEGI_SECURITY_CONTEXT_KEY);

        if (contextFromSessionObject != null) {
          if (contextFromSessionObject instanceof SecurityContext) {

            SecurityContext securityContext = (SecurityContext) contextFromSessionObject;
            if (Constants.isRelogin()) {

              Authentication auth = securityContext
                  .getAuthentication();
              if (auth != null) {
                Object principal = auth.getPrincipal();
                if (principal instanceof UserDetails) {
                  UserDetails ud1 = (UserDetails) principal;
View Full Code Here

   */
  public void attributeAdded(HttpSessionBindingEvent event) {
   
    String eventName = event.getName();
    if (eventName.equals(EVENT_KEY)) {
      SecurityContext securityContext = (SecurityContext) event.getValue();
      User user = (User) securityContext.getAuthentication().getPrincipal();
      /* do something here */
    }
  }
 
View Full Code Here

        @Override
        public void load() {
            super.load();
            if (credentials != null && !credentials.isEmpty()) {
                SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM);
                try {
                    BulkChange bc = new BulkChange(this);
                    try {
                        mayHaveLegacyPerJobCredentials = true;
                        for (Map.Entry<String, Credential> e : credentials.entrySet()) {
View Full Code Here

    /**
     * Method to enforce security and only allow administrators to modify users. Regular
     * users are allowed to modify themselves.
     */
    public void before(Method method, Object[] args, Object target) throws Throwable {
        SecurityContext ctx = SecurityContextHolder.getContext();

        if (ctx.getAuthentication() != null) {
            Authentication auth = ctx.getAuthentication();
            boolean administrator = false;
            GrantedAuthority[] roles = auth.getauthorities();
            for (int i=0; i < roles.length; i++) {
                if (roles[i].getauthority().equals(Constants.ADMIN_ROLE)) {
                    administrator = true;
View Full Code Here

    Mock userDao = null;
    ApplicationContext ctx = null;

    protected void setUp() throws Exception {
        super.setUp();
        SecurityContext context = new SecurityContextImpl();
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user",
                "password",
                new GrantedAuthority[] {new GrantedAuthorityImpl(Constants.USER_ROLE)});
        context.setAuthentication(token);
        SecurityContextHolder.setContext(context);
    }
View Full Code Here

            assertEquals(expected.getMessage(), UserSecurityAdvice.ACCESS_DENIED);
        }
    }

    public void testAddUserAsAdmin() throws Exception {
        SecurityContext context = new SecurityContextImpl();
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin",
                "password",
                new GrantedAuthority[] {new GrantedAuthorityImpl(Constants.ADMIN_ROLE)});
        context.setAuthentication(token);
        SecurityContextHolder.setContext(context);

        UserManager userManager = (UserManager) makeInterceptedTarget();
        User user = new User("admin");
View Full Code Here

        }
    }

        // Test fix to http://issues.appfuse.org/browse/APF-96
    public void testAddUserRoleWhenHasAdminRole() throws Exception {
        SecurityContext context = new SecurityContextImpl();
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user",
                "password",
                new GrantedAuthority[] {new GrantedAuthorityImpl(Constants.ADMIN_ROLE)});
        context.setAuthentication(token);
        SecurityContextHolder.setContext(context);

        UserManager userManager = (UserManager) makeInterceptedTarget();
        User user = new User("user");
        user.getRoles().add(new Role(Constants.ADMIN_ROLE));
View Full Code Here

        userDao.verify();
    }
   
    // Test removing user from cache after update
    public void testRemoveUserFromCache() throws Exception {
        SecurityContext context = new SecurityContextImpl();
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user",
                "password",
                new GrantedAuthority[] {new GrantedAuthorityImpl(Constants.ADMIN_ROLE)});
        context.setAuthentication(token);
        SecurityContextHolder.setContext(context);
       
        UserManager userManager = (UserManager) makeInterceptedTarget();
       
        UserCache cache = (UserCache) ctx.getBean("userCache");
View Full Code Here

     * Handles the logout by getting the SecurityContext for the session that was destroyed.
     * <b>MUST NOT use 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 {
                LoginContext loginContext = token.getLoginContext();
                if (loginContext != null) {
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.