OpenID-Connect-Java-Spring-Server
An OpenID Connect reference implementation in Java on the Spring platform.
Top Related Projects
Spring Security
Apereo CAS - Identity & Single Sign On for all earthlings and beyond.
Open Source Identity and Access Management For Modern Applications and Services
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Java JWT: JSON Web Token for Java and Android
Quick Overview
The OpenID-Connect-Java-Spring-Server is an open-source implementation of an OpenID Connect identity provider and OAuth 2.0 authorization server. It is built on the Spring Framework and provides a comprehensive solution for authentication and authorization in Java-based web applications.
Pros
- Fully compliant with OpenID Connect and OAuth 2.0 specifications
- Built on the robust and widely-used Spring Framework
- Supports various grant types and authentication methods
- Highly customizable and extensible
Cons
- Steep learning curve for developers new to OpenID Connect and OAuth 2.0
- Documentation could be more comprehensive and up-to-date
- May require significant configuration and setup for complex use cases
- Limited support for newer OAuth 2.0 extensions and features
Code Examples
- Configuring the OpenID Connect client:
@Configuration
@EnableOAuth2Client
public class OpenIdConnectConfig {
@Bean
public OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext oauth2ClientContext,
OAuth2ProtectedResourceDetails details) {
return new OAuth2RestTemplate(details, oauth2ClientContext);
}
}
- Protecting a resource with OpenID Connect:
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/**").authenticated()
.anyRequest().permitAll();
}
}
- Customizing the UserInfo endpoint:
@Component
public class CustomUserInfoService implements UserInfoService {
@Override
public UserInfo getByUsernameAndClientId(String username, String clientId) {
UserInfo userInfo = new DefaultUserInfo();
userInfo.setSubject(username);
userInfo.setName("John Doe");
userInfo.setEmail("john.doe@example.com");
return userInfo;
}
}
Getting Started
- Add the dependency to your
pom.xml
:
<dependency>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-server-webapp</artifactId>
<version>1.3.3</version>
</dependency>
- Configure the server in your
application.properties
:
openid.issuer=https://your-domain.com
openid.server.url=https://your-domain.com/openid-connect-server-webapp
- Implement necessary interfaces and configure your Spring application:
@SpringBootApplication
@Import(ConfigurationPropertiesBean.class)
public class OpenIdConnectServerApplication {
public static void main(String[] args) {
SpringApplication.run(OpenIdConnectServerApplication.class, args);
}
}
- Run your application and access the OpenID Connect discovery endpoint at
/.well-known/openid-configuration
.
Competitor Comparisons
Spring Security
Pros of Spring Security
- Comprehensive security framework with broader scope beyond just OpenID Connect
- Extensive documentation and large community support
- Seamless integration with other Spring projects
Cons of Spring Security
- Steeper learning curve due to its extensive feature set
- May require more configuration for specific OpenID Connect use cases
- Potentially heavier footprint for projects only needing OpenID Connect functionality
Code Comparison
OpenID-Connect-Java-Spring-Server:
@Configuration
@EnableAuthorizationServer
public class OIDCAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
// OpenID Connect specific configuration
}
Spring Security:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.oauth2Login();
// Additional security configurations
}
}
The OpenID-Connect-Java-Spring-Server example focuses specifically on OpenID Connect configuration, while Spring Security provides a more general security setup with OAuth2 login support. Spring Security requires additional configuration for full OpenID Connect implementation but offers more flexibility for various security scenarios.
Apereo CAS - Identity & Single Sign On for all earthlings and beyond.
Pros of CAS
- More comprehensive authentication and authorization solution
- Supports a wider range of protocols and integrations
- Active development with frequent updates and releases
Cons of CAS
- Steeper learning curve due to its extensive feature set
- May be overkill for simpler authentication needs
- Requires more resources to run and maintain
Code Comparison
OpenID-Connect-Java-Spring-Server:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/").permitAll();
}
}
CAS:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/cas/**").permitAll()
.anyRequest().authenticated()
.and().csrf().disable();
}
}
The code comparison shows that CAS typically requires more configuration due to its extensive features, while OpenID-Connect-Java-Spring-Server may have a simpler setup for basic authentication scenarios.
Open Source Identity and Access Management For Modern Applications and Services
Pros of Keycloak
- More comprehensive identity and access management solution with additional features like user federation, identity brokering, and social login
- Active development with frequent updates and a larger community
- Supports multiple protocols beyond OpenID Connect, including SAML and OAuth 2.0
Cons of Keycloak
- Steeper learning curve due to its extensive feature set
- Potentially higher resource consumption for smaller applications
- Less focused on OpenID Connect specifically compared to OpenID-Connect-Java-Spring-Server
Code Comparison
OpenID-Connect-Java-Spring-Server configuration:
@Configuration
public class OpenIDConnectConfig {
@Bean
public OIDCProvider oidcProvider() {
return new OIDCProvider();
}
}
Keycloak configuration:
@Configuration
public class KeycloakConfig {
@Bean
public KeycloakConfigResolver keycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
}
Both projects use Spring-based configuration, but Keycloak's setup is more tailored to its specific implementation and integration with Spring Boot.
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Pros of pac4j
- Multi-protocol support: Handles various authentication mechanisms beyond OpenID Connect
- Framework-agnostic: Can be integrated with different Java web frameworks
- Active development and community support
Cons of pac4j
- Steeper learning curve due to its versatility
- May require additional configuration for specific use cases
- Less focused on OpenID Connect compared to MITREid Connect
Code Comparison
MITREid Connect (OpenID Connect specific):
@Configuration
@EnableAuthorizationServer
public class OAuth2AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
// OpenID Connect server configuration
}
pac4j (Multi-protocol support):
Config config = new Config(new Clients(
new OidcClient(oidcConfiguration),
new FacebookClient(fbId, fbSecret),
new TwitterClient(twId, twSecret)
));
MITREid Connect is tailored for OpenID Connect implementations, offering a more straightforward setup for this specific protocol. pac4j, on the other hand, provides a flexible solution for various authentication methods, including OpenID Connect, OAuth, SAML, and more.
While MITREid Connect excels in OpenID Connect scenarios, pac4j's versatility makes it suitable for projects requiring multiple authentication protocols or the flexibility to switch between them. However, this flexibility comes at the cost of a potentially more complex initial setup and configuration process.
Java JWT: JSON Web Token for Java and Android
Pros of JJWT
- Lightweight and focused solely on JWT creation and parsing
- Easy to integrate into existing projects without additional dependencies
- Extensive documentation and examples for quick implementation
Cons of JJWT
- Lacks built-in OpenID Connect functionality
- Requires additional implementation for complete authentication flows
- No out-of-the-box server setup for identity provider services
Code Comparison
JJWT (JWT creation):
String jwt = Jwts.builder()
.setSubject("user123")
.signWith(SignatureAlgorithm.HS256, "secret")
.compact();
OpenID-Connect-Java-Spring-Server (Token endpoint):
@RequestMapping(value = "/token", method = RequestMethod.POST)
public Map<String, Object> getTokens(@RequestParam Map<String, String> parameters) {
// Token generation logic
}
JJWT focuses on JWT manipulation, while OpenID-Connect-Java-Spring-Server provides a complete OpenID Connect implementation. JJWT offers simplicity for JWT handling, but requires additional work for full authentication flows. OpenID-Connect-Java-Spring-Server provides a comprehensive solution but may be overkill for projects only needing basic JWT functionality.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
MITREid Connect
This project contains a certified OpenID Connect reference implementation in Java on the Spring platform, including a functioning server library, deployable server package, client (RP) library, and general utility libraries. The server can be used as an OpenID Connect Identity Provider as well as a general-purpose OAuth 2.0 Authorization Server.
More information about the project can be found:
- The project homepage on GitHub (with related projects)
- Full documentation
- Documentation for the Maven project and Java API
- Issue tracker (for bug reports and support requests)
- The mailing list for the project can be found at
mitreid-connect@mit.edu
, with archives available online.
The authors and key contributors of the project include:
- Justin Richer
- Amanda Anganes
- Michael Jett
- Michael Walsh
- Steve Moore
- Mike Derryberry
- William Kim
- Mark Janssen
Licensed under the Apache 2.0 license, for details see LICENSE.txt
.
Top Related Projects
Spring Security
Apereo CAS - Identity & Single Sign On for all earthlings and beyond.
Open Source Identity and Access Management For Modern Applications and Services
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Java JWT: JSON Web Token for Java and Android
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot