Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
UserDetails details = (UserDetails) principal;
- String ldapprefix = "";
+ String rolefix = "";
String role = details.getUsername();
Collection<? extends GrantedAuthority> 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();
}
return false;
}
+ protected boolean isAdminRole() {
+ Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ if (principal instanceof UserDetails) {
+ UserDetails details = (UserDetails) principal;
+ Collection<? extends GrantedAuthority> au = details.getAuthorities();
+ for (GrantedAuthority ga : au) {
+ if (ga.getAuthority().equals("ROLE_ADMIN")) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return false;
+ }
+
}
@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";
}
// 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);
}
user.setRegistrationDate(new Date());
- UserManager cm = new CassandraUserManager();
+ CassandraUserManager cm = new CassandraUserManager();
try {
cm.addUser(user);
} catch (DataIntegrityViolationException e) {
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 {
public LDAPAuthorityMapper() {
}
-/*
- public Collection<? extends GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) {
- Set<PCacheLDAPAuthority> 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<? extends GrantedAuthority> mapAuthorities(final Collection<? extends GrantedAuthority> authorities) {
SimpleGrantedAuthority sa = new SimpleGrantedAuthority("ROLE_LDAP_USER");
Set<GrantedAuthority> roles = new HashSet<GrantedAuthority>();
roles.add(sa);
logger.info("LDAPAuthorityMapper: set new role ROLE_LDAP_USER");
-
return roles;
}
}
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;
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;
}
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-search"></span> Search Servlets <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="<spring:url value="/sequence/query" htmlEscape="true" />">Protein Sequence</a></li>
+ <li><a href="<spring:url value="/features/query" htmlEscape="true" />">Protein Secondary Structure Features</a></li>
+ <!--
<li><a href="<spring:url value="/job/query" htmlEscape="true" />">Job</a></li>
<li><a href="<spring:url value="/admin/ip/query" htmlEscape="true" />">IP</a></li>
+ -->
</ul>
</li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-stats"></span> Statistics Servlets<b class="caret"></b></a>
<li><a href="<spring:url value="/stat/exectime/query" htmlEscape="true" />">Job Time Execution</a></li>
<li><a href="<spring:url value="/admin/ip/counts/query" htmlEscape="true" />">IPs by Job count</a></li>
<li><a href="<spring:url value="/sequence/counts/query" htmlEscape="true" />">Proteins by Job count</a></li>
- <li><a href="<spring:url value="/features/query" htmlEscape="true" />">Proteins by SS Features</a></li>
</ul>
</li>
<sec:authorize access="hasRole('ROLE_ADMIN')">