You can configure Spring Security as you want. Session management via JSESSIONID is just working out of box. For example, if you want to use Bearer OAuth 2.0 tokens you need to configure AuthServer. This is example of configuration from one of my projects:
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter
{
private final AuthenticationManager authenticationManager;
private final InGridSecurityProperties inGridSecurityProperties;
@Autowired
public AuthorizationServerConfig(AuthenticationManager authenticationManager, InGridSecurityProperties inGridSecurityProperties, GoogleConnectionFactory connectionFactory) {
this.authenticationManager = authenticationManager;
this.inGridSecurityProperties = inGridSecurityProperties;
this.connectionFactory = connectionFactory;
}
@Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception
{
clients.inMemory()
.withClient( inGridSecurityProperties.getClientId() )
.secret( inGridSecurityProperties.getClientSecret() )
.authorities( "ROLE_TRUSTED_CLIENT" )
.authorizedGrantTypes( inGridSecurityProperties.getGrantTypes() )
.scopes( inGridSecurityProperties.getClientScope() )
.accessTokenValiditySeconds(
inGridSecurityProperties.getAccessTokenValiditySeconds() )
.refreshTokenValiditySeconds(
inGridSecurityProperties.getRefreshTokenValiditySeconds() );
}
@Override public void configure(AuthorizationServerSecurityConfigurer security) throws Exception
{
security.tokenKeyAccess( "isAnonymous() || hasAuthority('ROLE_TRUSTED_CLIENT')" )
.checkTokenAccess( "hasAuthority('ROLE_TRUSTED_CLIENT')" );
}
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception
{
endpoints
.authenticationManager( authenticationManager )
.tokenStore( jwtTokenStore() )
.tokenEnhancer( jwtAccessTokenConverter() );
}
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter()
{
JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
KeyPair keyPair = new KeyStoreKeyFactory(
new ClassPathResource( inGridSecurityProperties.getJwtKeyStore() ),
inGridSecurityProperties.getJwtKeyStorePassword().toCharArray() )
.getKeyPair( inGridSecurityProperties.getJwtKeyPairAlias(),
inGridSecurityProperties.getJwtKeyPairPassword().toCharArray() );
converter.setKeyPair( keyPair );
return converter;
}
}
More information you can find in Spring Security Documentation: http://docs.spring.io/spring-security/site/docs/current/reference/