From: Sasha Sherstnev Date: Wed, 18 Dec 2013 08:59:23 +0000 (+0000) Subject: Some tiny technical changes to controllers X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=084b1869959f34750b49be06b43be255351fdcc1;p=proteocache.git Some tiny technical changes to controllers --- diff --git a/server/compbio/controllers/BasicController.java b/server/compbio/controllers/BasicController.java index 389a0f7..32703aa 100644 --- a/server/compbio/controllers/BasicController.java +++ b/server/compbio/controllers/BasicController.java @@ -12,16 +12,15 @@ public class BasicController { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserDetails) { UserDetails details = (UserDetails) principal; - String ldapprefix = ""; + String rolefix = ""; String role = details.getUsername(); Collection au = details.getAuthorities(); for (GrantedAuthority ga : au) { - System.out.println("role -> " + ga.getAuthority()); if (ga.getAuthority().equals("ROLE_LDAP_USER")) { - ldapprefix = "LDAP:"; + rolefix = "LDAP:"; } } - return ldapprefix + role; + return rolefix + role; } return principal.toString(); } @@ -41,4 +40,19 @@ public class BasicController { return false; } + protected boolean isAdminRole() { + Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + if (principal instanceof UserDetails) { + UserDetails details = (UserDetails) principal; + Collection au = details.getAuthorities(); + for (GrantedAuthority ga : au) { + if (ga.getAuthority().equals("ROLE_ADMIN")) { + return true; + } + } + return false; + } + return false; + } + } diff --git a/server/compbio/controllers/MainController.java b/server/compbio/controllers/MainController.java index a945e25..d5bef44 100644 --- a/server/compbio/controllers/MainController.java +++ b/server/compbio/controllers/MainController.java @@ -10,7 +10,8 @@ public class MainController extends BasicController { @RequestMapping(value = "/index", method = RequestMethod.GET) public String printPublicHome(ModelMap model) { - model.addAttribute("message", "Spring Security Custom Form example"); + model.addAttribute("username", getPrincipalName()); + if (isUserRole()) return "home"; return "public"; } diff --git a/server/compbio/controllers/UserController.java b/server/compbio/controllers/UserController.java index a00bd15..56b7087 100644 --- a/server/compbio/controllers/UserController.java +++ b/server/compbio/controllers/UserController.java @@ -35,7 +35,7 @@ public class UserController { // JavaMailSender mailSender; private final Pattern EMAIL = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"); - @RequestMapping(value = "/register/query", method = RequestMethod.POST) + @RequestMapping(value = "/register/query", method = RequestMethod.GET) public String RegisterForm(ModelMap model) { User user = new User(); model.addAttribute(user); @@ -91,7 +91,7 @@ public class UserController { } user.setRegistrationDate(new Date()); - UserManager cm = new CassandraUserManager(); + CassandraUserManager cm = new CassandraUserManager(); try { cm.addUser(user); } catch (DataIntegrityViolationException e) { diff --git a/server/compbio/spring/security/LDAPAuthorityMapper.java b/server/compbio/spring/security/LDAPAuthorityMapper.java index 061a3c6..4be363a 100644 --- a/server/compbio/spring/security/LDAPAuthorityMapper.java +++ b/server/compbio/spring/security/LDAPAuthorityMapper.java @@ -11,10 +11,17 @@ import org.apache.commons.logging.LogFactory; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper; -import org.springframework.security.ldap.authentication.LdapAuthenticationProvider; /** - * Maps groups defined in LDAP to roles for a specific user. + * The class maps LDAP groups defined in the LDAP service to the ProteoCache + * roles for a specific user. The class implements the standard Spring Security + * GrantedAuthoritiesMapper interface and should replace the standard + * Authorities Mapper in security configuration XML file. + * + * @version 1.0 January 2014 + * + * @author Alexaner Sherstnev + * */ @Resource public class LDAPAuthorityMapper implements GrantedAuthoritiesMapper { @@ -23,29 +30,19 @@ public class LDAPAuthorityMapper implements GrantedAuthoritiesMapper { public LDAPAuthorityMapper() { } -/* - public Collection mapAuthorities(final Collection authorities) { - Set roles = EnumSet.noneOf(PCacheLDAPAuthority.class); - roles.add(PCacheLDAPAuthority.ROLE_LDAP_USER); - logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER"); - * - * for (GrantedAuthority authority : authorities) { if - * (ROLE_CUSTOMER_SERVICE_OFFICER.equals(authority.getAuthority())) { - * roles.add(PCacheLDAPAuthority.ROLE_USER); } else if - * (ROLE_ADMIN.equals(authority.getAuthority())) { - * roles.add(PCacheLDAPAuthority.ROLE_ADMIN); } } - * - return roles; - }*/ - - + /** + * the real mapping method. Currently, all users who are able to + * authenticate are assigned with the same ROLE_LDAP_USER. + * + * @param authorities a set of original granted authorities assigned by ldapAuthProvider + * @return a new set of granted authorities greated in the method + */ public Collection mapAuthorities(final Collection authorities) { SimpleGrantedAuthority sa = new SimpleGrantedAuthority("ROLE_LDAP_USER"); Set roles = new HashSet(); roles.add(sa); logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER"); - return roles; } } diff --git a/server/compbio/spring/security/PCacheLDAPAuthority.java b/server/compbio/spring/security/PCacheLDAPAuthority.java index dde6d87..aee0964 100644 --- a/server/compbio/spring/security/PCacheLDAPAuthority.java +++ b/server/compbio/spring/security/PCacheLDAPAuthority.java @@ -4,12 +4,14 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.util.Assert; /** - * Maps groups defined in LDAP to roles for a specific user. - */ -/* - * public enum PCacheLDAPAuthority implements GrantedAuthority { ROLE_LDAP_USER; - * public String getAuthority() { return name(); } } + * The class implements the standard granted authority for Spring Security Not + * used in the current version of ProteoCache + * + * @version 1.0 January 2014 + * + * @author Alexaner Sherstnev */ + public final class PCacheLDAPAuthority implements GrantedAuthority { private static final long serialVersionUID = 1; @@ -17,7 +19,7 @@ public final class PCacheLDAPAuthority implements GrantedAuthority { private String role = "ROLE_LDAP_USER"; public PCacheLDAPAuthority(String role) { - Assert.hasText(role, "A granted authority textual representation is required"); + Assert.hasText(role, "A text representation of the granted authority is required"); this.role = role; } diff --git a/webapp/view/fragments/mainmenu.jsp b/webapp/view/fragments/mainmenu.jsp index 8f8e403..adaf956 100644 --- a/webapp/view/fragments/mainmenu.jsp +++ b/webapp/view/fragments/mainmenu.jsp @@ -13,8 +13,11 @@
  • ">Job Time Execution
  • ">IPs by Job count
  • ">Proteins by Job count
  • -
  • ">Proteins by SS Features