use of org.springframework.security.core.authority.SimpleGrantedAuthority in project ORCID-Source by ORCID.
the class SecurityContextTestUtils method setUpSecurityContextForAnonymous.
public static void setUpSecurityContextForAnonymous() {
SecurityContextImpl securityContext = new SecurityContextImpl();
ArrayList<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
AnonymousAuthenticationToken anonToken = new AnonymousAuthenticationToken("testKey", "testToken", authorities);
securityContext.setAuthentication(anonToken);
SecurityContextHolder.setContext(securityContext);
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project ORCID-Source by ORCID.
the class PublicV2ApiServiceVersionedDelegatorTest method before.
@Before
public void before() {
ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
Authentication auth = new AnonymousAuthenticationToken("anonymous", "anonymous", roles);
SecurityContextHolder.getContext().setAuthentication(auth);
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project libresonic by Libresonic.
the class JWTAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
JWTAuthenticationToken authentication = (JWTAuthenticationToken) auth;
if (authentication.getCredentials() == null || !(authentication.getCredentials() instanceof String)) {
logger.error("Credentials not present");
return null;
}
String rawToken = (String) auth.getCredentials();
DecodedJWT token = JWTSecurityService.verify(jwtKey, rawToken);
Claim path = token.getClaim(JWTSecurityService.CLAIM_PATH);
authentication.setAuthenticated(true);
// TODO:AD This is super unfortunate, but not sure there is a better way when using JSP
if (StringUtils.contains(authentication.getRequestedPath(), "/WEB-INF/jsp/")) {
logger.warn("BYPASSING AUTH FOR WEB-INF page");
} else if (!roughlyEqual(path.asString(), authentication.getRequestedPath())) {
throw new InsufficientAuthenticationException("Credentials not valid for path " + authentication.getRequestedPath() + ". They are valid for " + path.asString());
}
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_FULLY"));
authorities.add(new SimpleGrantedAuthority("ROLE_TEMP"));
return new JWTAuthenticationToken(authorities, rawToken, authentication.getRequestedPath());
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project libresonic by Libresonic.
the class SecurityService method getGrantedAuthorities.
public List<GrantedAuthority> getGrantedAuthorities(String username) {
String[] roles = userDao.getRolesForUser(username);
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_ANONYMOUSLY"));
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
for (int i = 0; i < roles.length; i++) {
authorities.add(new SimpleGrantedAuthority("ROLE_" + roles[i].toUpperCase()));
}
return authorities;
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project geode by apache.
the class GemFireAuthentication method populateAuthorities.
public static ArrayList<GrantedAuthority> populateAuthorities(JMXConnector jmxc) {
ObjectName name;
ArrayList<GrantedAuthority> authorities = new ArrayList<>();
try {
name = new ObjectName(PulseConstants.OBJECT_NAME_ACCESSCONTROL_MBEAN);
MBeanServerConnection mbeanServer = jmxc.getMBeanServerConnection();
for (String role : PulseConstants.PULSE_ROLES) {
Object[] params = role.split(":");
String[] signature = new String[] { String.class.getCanonicalName(), String.class.getCanonicalName() };
boolean result = (Boolean) mbeanServer.invoke(name, "authorize", params, signature);
if (result) {
authorities.add(new SimpleGrantedAuthority("ROLE_" + role));
}
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
return authorities;
}
Aggregations