Use the WAFFLE framework to process SSO in the Java library (one -point login)
Use the WAFFLE framework to process SSO in the Java library (one -point login)
Single -point login (SSO) is a authentication technology that allows users to use a set of credentials to access multiple mutual trust applications.Waffle is an open source Java library for handling SSO on the Windows platform.This article will introduce how to use the WAFFLE framework in the Java library to process SSO and provide related Java code examples.
The first step is to introduce the Waffle framework in your Java project.You can download the latest JAR files from Waffle's official website and add it to the road of your project.Or, if you use Maven to build your project, you can add the following dependencies to the pom.xml file:
<dependency>
<groupId>com.github.dblock</groupId>
<artifactId>waffle-jna</artifactId>
<version>1.4.1</version>
</dependency>
Next, you need to configure the Waffle framework to process SSO in your application.First, add the following code to your Spring configuration file:
<bean id="negotiateSecurityFilter" class="waffle.spring.NegotiateSecurityFilter">
<property name="provider" ref="windowsAuthProvider"/>
</bean>
<bean id="negotiateSecurityFilterEntryPoint" class="waffle.spring.NegotiateSecurityFilterEntryPoint">
<property name="loginFormUrl" value="/login"/>
</bean>
<bean id="windowsAuthProvider" class="waffle.windows.auth.impl.WindowsAuthProviderImpl"/>
<security:http>
// Configure NegotiateSecurityFilter to your filter
<security:custom-filter position="PRE_AUTH_FILTER" ref="negotiateSecurityFilter"/>
<security:port-mappings>
<security:port-mapping http="${server.port}" https="${server.port}"/>
</security:port-mappings>
// Configure NegotiateSecurityFILTERENTRYPOINT as an entrance point for authentication
<security:http-basic entry-point-ref="negotiateSecurityFilterEntryPoint"/>
// ... other configuration
</security:http>
In the above configuration, we allocate the `neigotiatedSecurityFilter` to the filter before Spring Security to handle the SSO request.`NegotiaTeSecurityFiltempoint` is to specify the entry point of the URL that jumps when the user jumps without authentication.We have also configured the `WindowsAutHProviderimpl` to provide Windows identity verification.
Finally, you need to add a login page so that users can log in without authentication.In your application, create a `login.jsp` file and add the following:
html
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Please login</h1>
<form action="<c:url value='/j_spring_security_check'/>" method="post">
<label for="j_username">Username:</label>
<input type="text" id="j_username" name="j_username"/>
<br/>
<label for="j_password">Password:</label>
<input type="password" id="j_password" name="j_password"/>
<br/>
<input type="submit" value="Login"/>
</form>
</body>
</html>
Now, your application has been configured and you can handle SSO.When the user accesses the protected URL, the Waffle framework will automatically verify it and redirect the user to the login page.After the user enters the credentials, Waffle will verify the verification credentials and return the verification results.
This is a simple Java class that shows how to use the Waffle framework in the Java library to process SSO:
import waffle.windows.auth.impl.WindowsAuthProviderImpl;
import waffle.servlet.NegotiateSecurityFilter;
import waffle.servlet.NegotiateSecurityFilterEntryPoint;
// Create a class to configure the WAFFLE framework
public class WaffleConfig {
public static void main(String[] args) {
// Create Windows identity verification provider
WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
// Create NegotiateSecurityFilter, and set a provider program
NegotiateSecurityFilter filter = new NegotiateSecurityFilter();
filter.setProvider(provider);
// Create NegotiateSecurityFILTERENTRYPOINT
NegotiateSecurityFilterEntryPoint entryPoint = new NegotiateSecurityFilterEntryPoint();
entryPoint.setLoginFormUrl("/login");
// ... other configuration
}
}
The above is a simple step and sample code that uses the WAFFLE framework to process SSO in the Java library.By following these steps, you can easily integrate the Waffle framework into your Java application to achieve the SSO function.