Search in sources :

Example 21 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project webtools.servertools by eclipse.

the class XmlTestCase method getXml40Server.

private Server getXml40Server(String testId) {
    Factory factory = new Factory();
    factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
    try {
        return (Server) factory.loadDocument(getXmlInputStream(testId));
    } catch (Exception e) {
        fail("Exception occurred loading " + testId + " XML: " + e.getMessage());
        return null;
    }
}
Also used : Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory)

Example 22 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project webtools.servertools by eclipse.

the class XmlTestCase method getXml32Server.

private org.eclipse.jst.server.tomcat.core.internal.xml.server32.Server getXml32Server(String testId) {
    Factory factory = new Factory();
    factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server32");
    try {
        return (org.eclipse.jst.server.tomcat.core.internal.xml.server32.Server) factory.loadDocument(getXmlInputStream(testId));
    } catch (Exception e) {
        fail("Exception occurred loading " + testId + " XML: " + e.getMessage());
        return null;
    }
}
Also used : Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory)

Example 23 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project oauth2-server by gw2auth.

the class OAuth2ServerConfiguration method jwkSource.

@Bean
public JWKSource<SecurityContext> jwkSource(@Value("${com.gw2auth.oauth2.keypair.id}") String keyPairId, @Value("${com.gw2auth.oauth2.keypair.path}") String keyPairPath) throws IOException, GeneralSecurityException {
    if (keyPairId.equals("generate")) {
        keyPairId = UUID.randomUUID().toString();
    }
    final KeyPair keyPair;
    if (keyPairPath.equals("generate")) {
        keyPair = generateRsaKey();
    } else {
        keyPair = loadRsaKey(keyPairPath, keyPairPath + ".pub");
    }
    final RSAKey rsaKey = new RSAKey.Builder((RSAPublicKey) keyPair.getPublic()).privateKey((RSAPrivateKey) keyPair.getPrivate()).keyID(keyPairId).build();
    final JWKSet jwkSet = new JWKSet(rsaKey);
    return (jwkSelector, securityContext) -> jwkSelector.select(jwkSet);
}
Also used : SecurityContext(com.nimbusds.jose.proc.SecurityContext) Ordered(org.springframework.core.Ordered) FilterChain(javax.servlet.FilterChain) OAuth2AuthorizationServerConfigurer(org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) JWKSet(com.nimbusds.jose.jwk.JWKSet) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter) Value(org.springframework.beans.factory.annotation.Value) KeySpec(java.security.spec.KeySpec) HttpServletRequest(javax.servlet.http.HttpServletRequest) RSAPublicKey(java.security.interfaces.RSAPublicKey) OAuth2LoginConfigurer(org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer) ProviderSettings(org.springframework.security.oauth2.server.authorization.config.ProviderSettings) Order(org.springframework.core.annotation.Order) java.security(java.security) JWKSource(com.nimbusds.jose.jwk.source.JWKSource) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) Files(java.nio.file.Files) Customizer(org.springframework.security.config.Customizer) HttpServletResponse(javax.servlet.http.HttpServletResponse) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) IOException(java.io.IOException) UUID(java.util.UUID) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) Configuration(org.springframework.context.annotation.Configuration) CustomOAuth2AuthorizationCodeRequestAuthenticationProvider(com.gw2auth.oauth2.server.adapt.CustomOAuth2AuthorizationCodeRequestAuthenticationProvider) HttpStatus(org.springframework.http.HttpStatus) RSAKey(com.nimbusds.jose.jwk.RSAKey) Paths(java.nio.file.Paths) Bean(org.springframework.context.annotation.Bean) RSAKey(com.nimbusds.jose.jwk.RSAKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) JWKSet(com.nimbusds.jose.jwk.JWKSet) Bean(org.springframework.context.annotation.Bean)

Example 24 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project oauth2-server by gw2auth.

the class OAuth2ServerConfiguration method oauth2ServerHttpSecurityFilterChain.

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
public SecurityFilterChain oauth2ServerHttpSecurityFilterChain(HttpSecurity http, Customizer<OAuth2LoginConfigurer<HttpSecurity>> oauth2LoginCustomizer) throws Exception {
    final OAuth2AuthorizationServerConfigurer<HttpSecurity> authorizationServerConfigurer = new OAuth2AuthorizationServerConfigurer<>();
    authorizationServerConfigurer.authorizationEndpoint((authorizationEndpoint) -> {
        authorizationEndpoint.authenticationProvider(CustomOAuth2AuthorizationCodeRequestAuthenticationProvider.create(http)).consentPage(OAUTH2_CONSENT_PAGE);
    });
    final RequestMatcher endpointsMatcher = authorizationServerConfigurer.getEndpointsMatcher();
    // This configuration is only for requests matched by the RequestMatcher
    // (that is, only OAuth2 AUTHORIZATION requests -> requests where this application acts as a OAuth2 server, not a client)
    http.requestMatcher(endpointsMatcher).authorizeRequests((auth) -> auth.anyRequest().authenticated()).csrf((csrf) -> csrf.ignoringRequestMatchers(endpointsMatcher)).oauth2Login(oauth2LoginCustomizer).apply(authorizationServerConfigurer);
    return http.build();
}
Also used : SecurityContext(com.nimbusds.jose.proc.SecurityContext) Ordered(org.springframework.core.Ordered) FilterChain(javax.servlet.FilterChain) OAuth2AuthorizationServerConfigurer(org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) JWKSet(com.nimbusds.jose.jwk.JWKSet) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter) Value(org.springframework.beans.factory.annotation.Value) KeySpec(java.security.spec.KeySpec) HttpServletRequest(javax.servlet.http.HttpServletRequest) RSAPublicKey(java.security.interfaces.RSAPublicKey) OAuth2LoginConfigurer(org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer) ProviderSettings(org.springframework.security.oauth2.server.authorization.config.ProviderSettings) Order(org.springframework.core.annotation.Order) java.security(java.security) JWKSource(com.nimbusds.jose.jwk.source.JWKSource) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) Files(java.nio.file.Files) Customizer(org.springframework.security.config.Customizer) HttpServletResponse(javax.servlet.http.HttpServletResponse) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) IOException(java.io.IOException) UUID(java.util.UUID) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) SecurityFilterChain(org.springframework.security.web.SecurityFilterChain) Configuration(org.springframework.context.annotation.Configuration) CustomOAuth2AuthorizationCodeRequestAuthenticationProvider(com.gw2auth.oauth2.server.adapt.CustomOAuth2AuthorizationCodeRequestAuthenticationProvider) HttpStatus(org.springframework.http.HttpStatus) RSAKey(com.nimbusds.jose.jwk.RSAKey) Paths(java.nio.file.Paths) Bean(org.springframework.context.annotation.Bean) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) OAuth2AuthorizationServerConfigurer(org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization.OAuth2AuthorizationServerConfigurer) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Aggregations

Server (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server)15 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)10 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)9 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)8 IPath (org.eclipse.core.runtime.IPath)6 FileInputStream (java.io.FileInputStream)5 IOException (java.io.IOException)5 IStatus (org.eclipse.core.runtime.IStatus)5 MultiStatus (org.eclipse.core.runtime.MultiStatus)5 Status (org.eclipse.core.runtime.Status)5 Host (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host)5 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)4 Engine (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)4 Listener (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener)4 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)4 FileNotFoundException (java.io.FileNotFoundException)3 SAXException (org.xml.sax.SAXException)3 CustomOAuth2AuthorizationCodeRequestAuthenticationProvider (com.gw2auth.oauth2.server.adapt.CustomOAuth2AuthorizationCodeRequestAuthenticationProvider)2 JWKSet (com.nimbusds.jose.jwk.JWKSet)2 RSAKey (com.nimbusds.jose.jwk.RSAKey)2