@Test public void testUserRoles() { assertTrue("Check if user is in " + ROLE_ADMIN, this.m_securityContextService.hasRole(ROLE_ADMIN .toString())); assertTrue("Check if user is in " + ROLE_PROVISION, this.m_securityContextService.hasRole(ROLE_PROVISION .toString())); assertFalse("Check if user is not in " + ROLE_USER, this.m_securityContextService.hasRole(ROLE_USER .toString())); assertFalse("Check if user is not in " + ROLE_ANONYMOUS, this.m_securityContextService.hasRole(ROLE_ANONYMOUS .toString())); assertFalse("Check if user is not in " + ROLE_DASHBOARD, this.m_securityContextService.hasRole(ROLE_DASHBOARD .toString())); }
@Override public boolean hasRole(String role) { boolean hasRole = false; UserDetails userDetails = getUserDetails(); if (userDetails != null) { Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities(); if (isRolePresent(authorities, role)) { hasRole = true; } } return hasRole; }
SpringSecurityContextService implements SecurityContextService { @Override public boolean hasRole(String role) { boolean hasRole = false; UserDetails userDetails = getUserDetails(); if (userDetails != null) { Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities(); if (isRolePresent(authorities, role)) { hasRole = true; } } return hasRole; } }
SpringSecurityContextService implements SecurityContextService { @Override public boolean hasRole(String role) { boolean hasRole = false; UserDetails userDetails = getUserDetails(); if (userDetails != null) { Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities(); if (isRolePresent(authorities, role)) { hasRole = true; } } return hasRole; } SpringSecurityContextService(); }
SpringSecurityContextService implements SecurityContextService { @Override public boolean hasRole(String role) { boolean hasRole = false; UserDetails userDetails = getUserDetails(); if (userDetails != null) { Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities(); if (isRolePresent(authorities, role)) { hasRole = true; } } return hasRole; } SpringSecurityContextService(); @Override String getUsername(); @Override String getPassword(); @Override boolean hasRole(String role); @Override boolean isAuthenticated(); }
SpringSecurityContextService implements SecurityContextService { @Override public boolean hasRole(String role) { boolean hasRole = false; UserDetails userDetails = getUserDetails(); if (userDetails != null) { Collection<? extends GrantedAuthority> authorities = userDetails.getAuthorities(); if (isRolePresent(authorities, role)) { hasRole = true; } } return hasRole; } SpringSecurityContextService(); @Override String getUsername(); @Override String getPassword(); @Override boolean hasRole(String role); @Override boolean isAuthenticated();  }