Created
December 22, 2011 09:49
-
-
Save nchapon/1509747 to your computer and use it in GitHub Desktop.
Faillite Technique
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void updateAuthoritiesFile(File file, UserSession userSession,ArrayList<GrantedAuthority> author) { | |
| // UserServiceFacade userFacade = (UserServiceFacade) ControllerUtility | |
| // .getBean("userServiceFacade"); | |
| SecurityContext context = SecurityContextHolder.getContext(); | |
| Authentication auth = context.getAuthentication(); | |
| UserDetails userDetails = (UserDetails) auth.getPrincipal(); | |
| ArrayList<GrantedAuthority> authorities = null; | |
| if(CommonUtility.isNullOrEmpty(author)){ | |
| authorities = new ArrayList<GrantedAuthority>( | |
| userDetails.getAuthorities()); | |
| }else{ | |
| authorities = author; | |
| } | |
| UserServiceFacade userFacade = (UserServiceFacade) getBean("userServiceFacade"); | |
| User current = userFacade.findUser(userSession.getUserName()); | |
| if(hasRole("ROLE_ADMIN")&& file!=null&& !CommonUtility.isNullOrEmpty(current.getBu())&& file.getBu()!=null&& file.getBu().getId()!=null&& (!file.getBu().getId().equals(current.getBu().get(0).getId()) || !hasLocation(current,file.getLocation()))){ | |
| addRole("ROLE_ADMIN_INACTIVE", authorities); | |
| }else{ | |
| removeRoleFromAuthorities("ROLE_ADMIN_INACTIVE", authorities); | |
| } | |
| if (file != null | |
| && file.getInitiator() != null | |
| && file.getInitiator().getLogin() != null | |
| && file.getInitiator().getLogin() | |
| .equals(userSession.getUserName())) { | |
| addRole("ROLE_FILE_INITIATOR", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_FILE_INITIATOR", authorities); | |
| } | |
| if (file != null | |
| && file.getResponsible() != null | |
| && file.getResponsible().getLogin() | |
| .equals(userSession.getUserName())) { | |
| addRole("ROLE_RESPONSIBLE", authorities); | |
| //removeRoleFromAuthorities("ROLE_ADMIN_INACTIVE", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_RESPONSIBLE", authorities); | |
| } | |
| if (file != null | |
| && file.getContributors() != null | |
| && isUserInList(userSession.getUserName(), | |
| file.getContributors())) { | |
| addRole("ROLE_CONTRIBUTOR", authorities); | |
| //removeRoleFromAuthorities("ROLE_ADMIN_INACTIVE", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_CONTRIBUTOR", authorities); | |
| } | |
| if (file != null && file.getApprovers() != null | |
| && isUserInList(userSession.getUserName(), file.getApprovers())) { | |
| addRole("ROLE_APPROVER", authorities); | |
| //removeRoleFromAuthorities("ROLE_ADMIN_INACTIVE", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_APPROVER", authorities); | |
| } | |
| // User user = userFacade.loadUser(userSession.getUserName()); | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 1L) { | |
| addRole("ROLE_INACTIVE_HEADER", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 1L) { | |
| addRole("ROLE_INACTIVE_CLOSE_HEADER", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_HEADER", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_HEADER", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 2L) { | |
| addRole("ROLE_INACTIVE_D1D2", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 2L) { | |
| addRole("ROLE_INACTIVE_CLOSE_D1D2", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_D1D2", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_D1D2", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 3L) { | |
| addRole("ROLE_INACTIVE_D3", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 3L) { | |
| addRole("ROLE_INACTIVE_CLOSE_D3", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_D3", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_D3", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 4L) { | |
| addRole("ROLE_INACTIVE_D4", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 4L) { | |
| addRole("ROLE_INACTIVE_CLOSE_D4", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_D4", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_D4", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 5L) { | |
| addRole("ROLE_INACTIVE_D5", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 5L) { | |
| addRole("ROLE_INACTIVE_CLOSE_D5", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_D5", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_D5", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 6L) { | |
| addRole("ROLE_INACTIVE_D6", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 6L) { | |
| addRole("ROLE_INACTIVE_CLOSE_D6", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_D6", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_D6", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !(hasRole("ROLE_DIV_ADMIN", authorities)) && file != null | |
| && file.getFileStatus().getId() > 7L) { | |
| addRole("ROLE_INACTIVE_D7", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 7L) { | |
| addRole("ROLE_INACTIVE_CLOSE_D7", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_D7", authorities); | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSE_D7", authorities); | |
| } | |
| if (!hasRole("ROLE_ADMIN", authorities) | |
| && !hasRole("ROLE_DIV_ADMIN", authorities) | |
| && (file != null && file.getFileStatus().getId() > 8L)) { | |
| addRole("ROLE_INACTIVE_CLOSED_D8", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 8L) { | |
| addRole("ROLE_INACTIVE_CLOSED_D8", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_CLOSED_D8", authorities); | |
| } | |
| if ((!hasRole("ROLE_ADMIN", authorities) && !hasRole("ROLE_DIV_ADMIN", | |
| authorities)) | |
| && file != null | |
| && file.getFileStatus().getId() > 9L) { | |
| addRole("ROLE_INACTIVE_VALIDATED_D8", authorities); | |
| } else if ((hasRole("ROLE_ADMIN", authorities) || (hasRole( | |
| "ROLE_DIV_ADMIN", authorities))) | |
| && file != null | |
| && file.getFileStatus().getId() > 9L) { | |
| addRole("ROLE_INACTIVE_VALIDATED_D8", authorities); | |
| } else { | |
| removeRoleFromAuthorities("ROLE_INACTIVE_VALIDATED_D8", authorities); | |
| } | |
| if(CommonUtility.isNullOrEmpty(author)){ | |
| SecurityContextHolder.getContext().setAuthentication( | |
| new UsernamePasswordAuthenticationToken(SecurityContextHolder | |
| .getContext().getAuthentication().getPrincipal(), | |
| SecurityContextHolder.getContext().getAuthentication() | |
| .getCredentials(), authorities)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment