Upgrade gradle 8.x
- Pump gradle to 8.x - Use dependencies from boot 3.x for samples, and framework/security baseline for modules. - Client module disables to get handled later. - Rewrite and upgrade everything needed to get things to compile. - Disable docs as those will get moved to antora - Make only one sample to work, rest happen later. - Fixes #167
This commit is contained in:
9
.vscode/settings.json
vendored
Normal file
9
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"java.completion.importOrder": [
|
||||
"java",
|
||||
"javax",
|
||||
"",
|
||||
"org.springframework",
|
||||
"#"
|
||||
]
|
||||
}
|
||||
406
build.gradle
406
build.gradle
@@ -1,399 +1,31 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://repo.spring.io/plugins-release' }
|
||||
maven { url 'https://plugins.gradle.org/m2/' }
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.build.gradle:propdeps-plugin:0.0.7")
|
||||
classpath("org.springframework.build.gradle:spring-io-plugin:0.0.3.RELEASE")
|
||||
// classpath('org.asciidoctor:asciidoctor-gradle-plugin:1.5.2')
|
||||
// classpath("io.spring.gradle:docbook-reference-plugin:0.3.0")
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
|
||||
}
|
||||
plugins {
|
||||
id "base"
|
||||
}
|
||||
|
||||
def sampleServerProjects() {
|
||||
subprojects.findAll { project ->
|
||||
project.name.contains('sec-server') && project.name != 'spring-security-kerberos-samples-common'
|
||||
}
|
||||
description = 'Spring Security Kerberos'
|
||||
|
||||
repositories {
|
||||
// maven { url 'https://repo.spring.io/snapshot' }
|
||||
// maven { url 'https://repo.spring.io/milestone' }
|
||||
// maven { url 'https://repo.spring.io/release' }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
def sampleClientProjects() {
|
||||
subprojects.findAll { project ->
|
||||
project.name.contains('sec-client')
|
||||
}
|
||||
}
|
||||
|
||||
configure(allprojects) {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'propdeps'
|
||||
|
||||
group = 'org.springframework.security.kerberos'
|
||||
|
||||
sourceCompatibility=1.6
|
||||
targetCompatibility=1.6
|
||||
|
||||
[compileJava, compileTestJava]*.options*.compilerArgs = ['-Xlint:none']
|
||||
|
||||
test.systemProperty("java.awt.headless", "true")
|
||||
allprojects {
|
||||
group = 'org.springframework.shell'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://repo.spring.io/libs-release' }
|
||||
}
|
||||
|
||||
// servlet-api (2.5) and tomcat-servlet-api (3.0) classpath entries should not be
|
||||
// exported to dependent projects in Eclipse to avoid false compilation errors due
|
||||
// to changing APIs across these versions
|
||||
eclipse.classpath.file.whenMerged { classpath ->
|
||||
classpath.entries.findAll { entry -> entry.path.contains('servlet-api') }*.exported = false
|
||||
}
|
||||
}
|
||||
|
||||
configure(subprojects) { subproject ->
|
||||
apply from: "${rootProject.projectDir}/publish-maven.gradle"
|
||||
|
||||
jar {
|
||||
manifest.attributes['Created-By'] = "${System.getProperty('java.version')} (${System.getProperty('java.specification.vendor')})"
|
||||
manifest.attributes['Implementation-Title'] = subproject.name
|
||||
manifest.attributes['Implementation-Version'] = subproject.version
|
||||
|
||||
from("${rootProject.projectDir}/src/dist") {
|
||||
include "license.txt"
|
||||
include "notice.txt"
|
||||
into "META-INF"
|
||||
expand(copyright: new Date().format('yyyy'), version: project.version)
|
||||
}
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
|
||||
options.author = true
|
||||
options.header = project.name
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn:classes) {
|
||||
classifier = 'sources'
|
||||
from sourceSets.main.allJava.srcDirs
|
||||
include '**/*.java', '**/*.aj'
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives javadocJar
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile "org.mockito:mockito-core:$mockitoVersion"
|
||||
testCompile "junit:junit:$junitVersion"
|
||||
testRuntime("log4j:log4j:$log4jVersion")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
project('spring-security-kerberos-core') {
|
||||
description = 'Spring Security Kerberos Core'
|
||||
dependencies {
|
||||
compile "org.springframework:spring-core:$springVersion"
|
||||
compile "org.springframework.security:spring-security-core:$springSecurityVersion"
|
||||
}
|
||||
}
|
||||
|
||||
project('spring-security-kerberos-web') {
|
||||
description = 'Spring Security Kerberos Web'
|
||||
dependencies {
|
||||
compile project(":spring-security-kerberos-core")
|
||||
compile "org.springframework:spring-core:$springVersion"
|
||||
compile "org.springframework:spring-web:$springVersion"
|
||||
compile "org.springframework.security:spring-security-web:$springSecurityVersion"
|
||||
|
||||
compile("javax.servlet:javax.servlet-api:$servletApi3Version", optional)
|
||||
|
||||
testCompile "org.springframework.security:spring-security-config:$springSecurityVersion"
|
||||
testCompile "org.springframework:spring-test:$springVersion"
|
||||
}
|
||||
}
|
||||
|
||||
project('spring-security-kerberos-client') {
|
||||
description = 'Spring Security Kerberos Client'
|
||||
|
||||
configurations {
|
||||
all*.exclude group: "org.apache.directory.api", module: "api-ldap-schema-data"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(":spring-security-kerberos-core")
|
||||
compile "org.springframework:spring-web:$springVersion"
|
||||
compile "org.apache.httpcomponents:httpclient:$httpclientVersion"
|
||||
|
||||
optional("org.springframework.security:spring-security-ldap:$springSecurityVersion")
|
||||
|
||||
testCompile project(":spring-security-kerberos-test")
|
||||
testCompile project(":spring-security-kerberos-web")
|
||||
testCompile "org.springframework.security:spring-security-config:$springSecurityVersion"
|
||||
testCompile "org.springframework.boot:spring-boot-autoconfigure:$springBootVersion"
|
||||
testRuntime "org.apache.tomcat.embed:tomcat-embed-core:$tomcatEmbedVersion"
|
||||
testRuntime "org.apache.tomcat.embed:tomcat-embed-logging-juli:$tomcatEmbedVersion"
|
||||
testRuntime "org.springframework:spring-webmvc:$springVersion"
|
||||
}
|
||||
}
|
||||
|
||||
project('spring-security-kerberos-test') {
|
||||
description = 'Spring Security Kerberos Test'
|
||||
|
||||
configurations {
|
||||
all*.exclude group: "org.apache.directory.api", module: "api-ldap-schema-data"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "junit:junit:$junitVersion"
|
||||
compile "org.apache.directory.server:apacheds-core-api:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-interceptor-kerberos:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-protocol-shared:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-protocol-kerberos:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-ldif-partition:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-mavibot-partition:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-jdbm-partition:$apacheDirServerVersion"
|
||||
compile "org.apache.directory.server:apacheds-protocol-ldap:$apacheDirServerVersion"
|
||||
compile("org.apache.directory.api:api-all:$apacheDirApiVersion") {
|
||||
exclude group: "xml-apis", module: "xml-apis"
|
||||
exclude group: "xpp3", module: "xpp3"
|
||||
exclude group: "dom4j", module: "dom4j"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project('spring-security-kerberos-samples-common') {
|
||||
// don't publish boot packaged samples
|
||||
configurations.archives.artifacts.removeAll { it.archiveTask.is jar }
|
||||
tasks.findByPath("artifactoryPublish")?.enabled = false
|
||||
dependencies {
|
||||
compile project(":spring-security-kerberos-core")
|
||||
}
|
||||
}
|
||||
|
||||
configure(sampleServerProjects()) {
|
||||
apply plugin: 'spring-boot'
|
||||
// don't publish boot packaged samples
|
||||
configurations.archives.artifacts.removeAll { it.archiveTask.is jar }
|
||||
tasks.findByPath("artifactoryPublish")?.enabled = false
|
||||
dependencies {
|
||||
compile project(":spring-security-kerberos-samples-common")
|
||||
compile project(":spring-security-kerberos-client")
|
||||
compile project(":spring-security-kerberos-web")
|
||||
compile "org.springframework.boot:spring-boot-starter-thymeleaf:$springBootVersion"
|
||||
compile "org.springframework.security:spring-security-config:$springSecurityVersion"
|
||||
compile "org.springframework.security:spring-security-ldap:$springSecurityVersion"
|
||||
compile "org.springframework:spring-beans:$springVersion"
|
||||
compile "org.springframework:spring-aop:$springVersion"
|
||||
compile "org.springframework:spring-expression:$springVersion"
|
||||
compile "org.springframework:spring-context:$springVersion"
|
||||
compile "org.springframework:spring-tx:$springVersion"
|
||||
compile "org.springframework:spring-jdbc:$springVersion"
|
||||
testCompile "org.springframework:spring-test:$springVersion"
|
||||
testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion"
|
||||
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
||||
testCompile "junit:junit:$junitVersion"
|
||||
}
|
||||
}
|
||||
|
||||
configure(sampleClientProjects()) {
|
||||
apply plugin: 'spring-boot'
|
||||
// don't publish boot packaged samples
|
||||
configurations.archives.artifacts.removeAll { it.archiveTask.is jar }
|
||||
tasks.findByPath("artifactoryPublish")?.enabled = false
|
||||
dependencies {
|
||||
compile project(":spring-security-kerberos-samples-common")
|
||||
compile project(":spring-security-kerberos-client")
|
||||
compile "org.springframework:spring-tx:$springVersion"
|
||||
compile "org.springframework:spring-jdbc:$springVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter:$springBootVersion"
|
||||
compile "org.springframework:spring-beans:$springVersion"
|
||||
compile "org.springframework:spring-aop:$springVersion"
|
||||
compile "org.springframework:spring-expression:$springVersion"
|
||||
compile "org.springframework:spring-context:$springVersion"
|
||||
compile "org.springframework:spring-tx:$springVersion"
|
||||
compile "org.springframework:spring-jdbc:$springVersion"
|
||||
testCompile "org.springframework:spring-test:$springVersion"
|
||||
testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion"
|
||||
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
||||
testCompile "junit:junit:$junitVersion"
|
||||
}
|
||||
}
|
||||
|
||||
configure(rootProject) {
|
||||
description = 'Spring Security Kerberos Extension'
|
||||
|
||||
// apply plugin: 'org.asciidoctor.gradle.asciidoctor'
|
||||
// apply plugin: 'docbook-reference'
|
||||
|
||||
// reference {
|
||||
// sourceDir = new File(asciidoctor.outputDir , 'docbook5')
|
||||
// pdfFilename = "spring-security-kerberos-reference.pdf"
|
||||
// epubFilename = "spring-security-kerberos-reference.epub"
|
||||
// expandPlaceholders = ""
|
||||
// }
|
||||
|
||||
// afterEvaluate {
|
||||
// tasks.findAll { it.name.startsWith("reference") }.each{ it.dependsOn.add("asciidoctor") }
|
||||
// }
|
||||
|
||||
// asciidoctorj {
|
||||
// version = '1.5.2'
|
||||
// }
|
||||
|
||||
// asciidoctor {
|
||||
// sourceDir = file("docs/src/reference/asciidoc")
|
||||
// backends = ['docbook5']
|
||||
// options eruby: 'erubis'
|
||||
// attributes docinfo: '',
|
||||
// copycss : '',
|
||||
// icons : 'font',
|
||||
// 'source-highlighter': 'prettify',
|
||||
// sectanchors : '',
|
||||
// toc2: '',
|
||||
// idprefix: '',
|
||||
// idseparator: '-',
|
||||
// doctype: 'book',
|
||||
// numbered: '',
|
||||
// 'spring-version' : springVersion,
|
||||
// 'spring-security-version' : springSecurityVersion,
|
||||
// revnumber : project.version
|
||||
// }
|
||||
|
||||
// task copyDocsSamples(type: Copy) {
|
||||
// from 'spring-security-kerberos-web/src/test/java/org/springframework/security/kerberos/docs/'
|
||||
// from 'spring-security-kerberos-web/src/test/resources/org/springframework/security/kerberos/docs/'
|
||||
// from 'spring-security-kerberos-client/src/test/java/org/springframework/security/kerberos/client/docs/'
|
||||
// include '**/*.java'
|
||||
// include '**/*.xml'
|
||||
// into 'docs/src/reference/asciidoc/samples'
|
||||
// }
|
||||
// asciidoctor.dependsOn copyDocsSamples
|
||||
|
||||
|
||||
// don't publish the default jar for the root project
|
||||
configurations.archives.artifacts.clear()
|
||||
|
||||
task api(type: Javadoc) {
|
||||
group = 'Documentation'
|
||||
description = 'Generates aggregated Javadoc API documentation.'
|
||||
title = "${rootProject.description} ${version} API"
|
||||
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
|
||||
options.author = true
|
||||
options.header = rootProject.description
|
||||
options.splitIndex = true
|
||||
options.links(
|
||||
'https://docs.jboss.org/jbossas/javadoc/4.0.5/connector'
|
||||
)
|
||||
source subprojects.collect { project ->
|
||||
project.sourceSets.main.allJava
|
||||
}
|
||||
destinationDir = new File(buildDir, "api")
|
||||
classpath = files(subprojects.collect { project ->
|
||||
project.sourceSets.main.compileClasspath
|
||||
})
|
||||
maxMemory = '1024m'
|
||||
}
|
||||
|
||||
task docsZip(type: Zip) {
|
||||
group = 'Distribution'
|
||||
classifier = 'docs'
|
||||
description = "Builds -${classifier} archive containing api and reference " +
|
||||
"for deployment at static.springframework.org/spring-security-kerberos/docs."
|
||||
|
||||
from('src/dist') {
|
||||
include 'changelog.txt'
|
||||
}
|
||||
|
||||
from (api) {
|
||||
into 'api'
|
||||
}
|
||||
|
||||
// from (reference) {
|
||||
// into 'reference'
|
||||
// maven { url 'https://repo.spring.io/release' }
|
||||
// if (version.contains('-')) {
|
||||
// maven { url "https://repo.spring.io/milestone" }
|
||||
// }
|
||||
// if (version.endsWith('-SNAPSHOT')) {
|
||||
// maven { url "https://repo.spring.io/snapshot" }
|
||||
// }
|
||||
}
|
||||
|
||||
task distZip(type: Zip, dependsOn: [docsZip]) {
|
||||
group = 'Distribution'
|
||||
classifier = 'dist'
|
||||
description = "Builds -${classifier} archive, containing all jars and docs, " +
|
||||
"suitable for community download page."
|
||||
|
||||
ext.baseDir = "${project.name}-${project.version}";
|
||||
|
||||
from('src/dist') {
|
||||
include 'readme.txt'
|
||||
include 'license.txt'
|
||||
include 'notice.txt'
|
||||
into "${baseDir}"
|
||||
expand(copyright: new Date().format('yyyy'), version: project.version)
|
||||
}
|
||||
|
||||
from(zipTree(docsZip.archivePath)) {
|
||||
into "${baseDir}/docs"
|
||||
}
|
||||
|
||||
subprojects.each { subproject ->
|
||||
into ("${baseDir}/libs") {
|
||||
from subproject.jar
|
||||
if (subproject.tasks.findByPath('sourcesJar')) {
|
||||
from subproject.sourcesJar
|
||||
}
|
||||
if (subproject.tasks.findByPath('javadocJar')) {
|
||||
from subproject.javadocJar
|
||||
}
|
||||
}
|
||||
}
|
||||
configurations.all {
|
||||
resolutionStrategy.cacheChangingModulesFor 1, 'hours'
|
||||
}
|
||||
|
||||
// Create an distribution that contains all dependencies (required and optional).
|
||||
// Not published by default; only for use when building from source.
|
||||
task depsZip(type: Zip, dependsOn: distZip) { zipTask ->
|
||||
group = 'Distribution'
|
||||
classifier = 'dist-with-deps'
|
||||
description = "Builds -${classifier} archive, containing everything " +
|
||||
"in the -${distZip.classifier} archive plus all runtime dependencies."
|
||||
|
||||
from zipTree(distZip.archivePath)
|
||||
|
||||
gradle.taskGraph.whenReady { taskGraph ->
|
||||
if (taskGraph.hasTask(":${zipTask.name}")) {
|
||||
def projectNames = rootProject.subprojects*.name
|
||||
def artifacts = new HashSet()
|
||||
subprojects.each { subproject ->
|
||||
subproject.configurations.runtime.resolvedConfiguration.resolvedArtifacts.each { artifact ->
|
||||
def dependency = artifact.moduleVersion.id
|
||||
if (!projectNames.contains(dependency.name)) {
|
||||
artifacts << artifact.file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zipTask.from(artifacts) {
|
||||
into "${distZip.baseDir}/deps"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives docsZip
|
||||
archives distZip
|
||||
}
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
description = 'Generates gradlew[.bat] scripts'
|
||||
gradleVersion = '2.2.1'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
50
buildSrc/build.gradle
Normal file
50
buildSrc/build.gradle
Normal file
@@ -0,0 +1,50 @@
|
||||
plugins {
|
||||
id "java-gradle-plugin"
|
||||
id "java"
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
maven { url 'https://repo.spring.io/plugins-release/' }
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
}
|
||||
|
||||
ext {
|
||||
def propertiesFile = new File(new File("$projectDir").parentFile, "gradle.properties")
|
||||
propertiesFile.withInputStream {
|
||||
def properties = new Properties()
|
||||
properties.load(it)
|
||||
set("springFrameworkVersion", properties["springFrameworkVersion"])
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform("org.springframework:spring-framework-bom:${springFrameworkVersion}"))
|
||||
implementation("org.springframework:spring-core")
|
||||
implementation 'org.asciidoctor:asciidoctor-gradle-jvm:3.3.2'
|
||||
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:4.29.0'
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
modulePlugin {
|
||||
id = "org.springframework.security.kerberos.module"
|
||||
implementationClass = "org.springframework.security.kerberos.gradle.ModulePlugin"
|
||||
}
|
||||
bomPlugin {
|
||||
id = "org.springframework.security.kerberos.bom"
|
||||
implementationClass = "org.springframework.security.kerberos.gradle.BomPlugin"
|
||||
}
|
||||
distPlugin {
|
||||
id = "org.springframework.security.kerberos.root"
|
||||
implementationClass = "org.springframework.security.kerberos.gradle.RootPlugin"
|
||||
}
|
||||
samplePlugin {
|
||||
id = "org.springframework.security.kerberos.sample"
|
||||
implementationClass = "org.springframework.security.kerberos.gradle.SamplePlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.gradle.api.publish.tasks.GenerateModuleMetadata;
|
||||
import org.jfrog.build.extractor.clientConfiguration.ArtifactSpec;
|
||||
import org.jfrog.build.extractor.clientConfiguration.ArtifactSpecs;
|
||||
import org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin;
|
||||
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
public class ArtifactoryConventions {
|
||||
|
||||
void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(ArtifactoryPlugin.class);
|
||||
|
||||
project.getTasks().withType(GenerateModuleMetadata.class, metadata -> {
|
||||
metadata.setEnabled(false);
|
||||
});
|
||||
|
||||
project.getPlugins().withType(ArtifactoryPlugin.class, artifactory -> {
|
||||
Task task = project.getTasks().findByName(ArtifactoryTask.ARTIFACTORY_PUBLISH_TASK_NAME);
|
||||
if (task != null) {
|
||||
ArtifactoryTask aTask = (ArtifactoryTask) task;
|
||||
aTask.setCiServerBuild();
|
||||
// bom is not a java project so plugin doesn't
|
||||
// add defaults for publications.
|
||||
aTask.publications("mavenJava");
|
||||
aTask.publishConfigs("archives");
|
||||
|
||||
// plugin is difficult to work with, use this hack
|
||||
// to set props before task does its real work
|
||||
task.doFirst(t -> {
|
||||
// this needs mods if we ever have zips other than
|
||||
// docs zip having asciidoc/javadoc.
|
||||
ArtifactoryTask at = (ArtifactoryTask) t;
|
||||
ArtifactSpecs artifactSpecs = at.getArtifactSpecs();
|
||||
Map<String, String> propsMap = new HashMap<>();
|
||||
propsMap.put("zip.deployed", "false");
|
||||
propsMap.put("zip.type", "docs");
|
||||
ArtifactSpec spec = ArtifactSpec.builder()
|
||||
.artifactNotation("*:*:*:*@zip")
|
||||
// archives is manually set for zip in root plugin
|
||||
.configuration("archives")
|
||||
.properties(propsMap)
|
||||
.build();
|
||||
artifactSpecs.add(spec);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.dsl.DependencyConstraintHandler;
|
||||
import org.gradle.api.plugins.JavaPlatformPlugin;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class BomPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(SpringMavenPlugin.class);
|
||||
pluginManager.apply(JavaPlatformPlugin.class);
|
||||
new ArtifactoryConventions().apply(project);
|
||||
|
||||
// bom should have main shell modules and starters
|
||||
DependencyConstraintHandler constraints = project.getDependencies().getConstraints();
|
||||
project.getRootProject().getAllprojects().forEach(p -> {
|
||||
p.getPlugins().withType(ModulePlugin.class, m -> {
|
||||
constraints.add("api", p);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.artifacts.ComponentMetadataDetails;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.DependencyConstraint;
|
||||
import org.gradle.api.artifacts.DependencyConstraintMetadata;
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler;
|
||||
import org.gradle.api.tasks.Internal;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class ExtractVersionConstraints extends DefaultTask {
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private final Map<String, String> versionConstraints = new TreeMap<>();
|
||||
|
||||
private final Set<ConstrainedVersion> constrainedVersions = new TreeSet<>();
|
||||
|
||||
private final Set<VersionProperty> versionProperties = new TreeSet<>();
|
||||
|
||||
private final List<String> projectPaths = new ArrayList<>();
|
||||
|
||||
public ExtractVersionConstraints() {
|
||||
DependencyHandler dependencies = getProject().getDependencies();
|
||||
this.configuration = getProject().getConfigurations().create(getName());
|
||||
dependencies.getComponents().all(this::processMetadataDetails);
|
||||
}
|
||||
|
||||
public void enforcedPlatform(String projectPath) {
|
||||
this.configuration.getDependencies().add(getProject().getDependencies().enforcedPlatform(
|
||||
getProject().getDependencies().project(Collections.singletonMap("path", projectPath))));
|
||||
this.projectPaths.add(projectPath);
|
||||
}
|
||||
|
||||
@Internal
|
||||
public Map<String, String> getVersionConstraints() {
|
||||
return Collections.unmodifiableMap(this.versionConstraints);
|
||||
}
|
||||
|
||||
@Internal
|
||||
public Set<ConstrainedVersion> getConstrainedVersions() {
|
||||
return this.constrainedVersions;
|
||||
}
|
||||
|
||||
@Internal
|
||||
public Set<VersionProperty> getVersionProperties() {
|
||||
return this.versionProperties;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void extractVersionConstraints() {
|
||||
this.configuration.resolve();
|
||||
for (String projectPath : this.projectPaths) {
|
||||
for (DependencyConstraint constraint : getProject().project(projectPath).getConfigurations()
|
||||
.getByName("apiElements").getAllDependencyConstraints()) {
|
||||
this.versionConstraints.put(constraint.getGroup() + ":" + constraint.getName(),
|
||||
constraint.getVersionConstraint().toString());
|
||||
this.constrainedVersions.add(new ConstrainedVersion(constraint.getGroup(), constraint.getName(),
|
||||
constraint.getVersionConstraint().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processMetadataDetails(ComponentMetadataDetails details) {
|
||||
details.allVariants((variantMetadata) -> variantMetadata.withDependencyConstraints((dependencyConstraints) -> {
|
||||
for (DependencyConstraintMetadata constraint : dependencyConstraints) {
|
||||
this.versionConstraints.put(constraint.getGroup() + ":" + constraint.getName(),
|
||||
constraint.getVersionConstraint().toString());
|
||||
this.constrainedVersions.add(new ConstrainedVersion(constraint.getGroup(), constraint.getName(),
|
||||
constraint.getVersionConstraint().toString()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static final class ConstrainedVersion implements Comparable<ConstrainedVersion>, Serializable {
|
||||
|
||||
private final String group;
|
||||
|
||||
private final String artifact;
|
||||
|
||||
private final String version;
|
||||
|
||||
private ConstrainedVersion(String group, String artifact, String version) {
|
||||
this.group = group;
|
||||
this.artifact = artifact;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public String getArtifact() {
|
||||
return this.artifact;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ConstrainedVersion other) {
|
||||
int groupComparison = this.group.compareTo(other.group);
|
||||
if (groupComparison != 0) {
|
||||
return groupComparison;
|
||||
}
|
||||
return this.artifact.compareTo(other.artifact);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class VersionProperty implements Comparable<VersionProperty>, Serializable {
|
||||
|
||||
private final String libraryName;
|
||||
|
||||
private final String versionProperty;
|
||||
|
||||
public VersionProperty(String libraryName, String versionProperty) {
|
||||
this.libraryName = libraryName;
|
||||
this.versionProperty = versionProperty;
|
||||
}
|
||||
|
||||
public String getLibraryName() {
|
||||
return this.libraryName;
|
||||
}
|
||||
|
||||
public String getVersionProperty() {
|
||||
return this.versionProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(VersionProperty other) {
|
||||
int groupComparison = this.libraryName.compareToIgnoreCase(other.libraryName);
|
||||
if (groupComparison != 0) {
|
||||
return groupComparison;
|
||||
}
|
||||
return this.versionProperty.compareTo(other.versionProperty);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaBasePlugin;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
import org.gradle.api.tasks.bundling.Jar;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.api.tasks.testing.Test;
|
||||
import org.gradle.external.javadoc.CoreJavadocOptions;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class JavaConventions {
|
||||
|
||||
private static final String SOURCE_AND_TARGET_COMPATIBILITY = "17";
|
||||
|
||||
void apply(Project project) {
|
||||
project.getPlugins().withType(JavaBasePlugin.class, java -> {
|
||||
configureJavaConventions(project);
|
||||
configureJavadocConventions(project);
|
||||
configureTestConventions(project);
|
||||
configureJarManifestConventions(project);
|
||||
});
|
||||
}
|
||||
|
||||
private void configureJavadocConventions(Project project) {
|
||||
project.getTasks().withType(Javadoc.class, (javadoc) -> {
|
||||
CoreJavadocOptions options = (CoreJavadocOptions) javadoc.getOptions();
|
||||
options.source("17");
|
||||
options.encoding("UTF-8");
|
||||
options.addStringOption("Xdoclint:none", "-quiet");
|
||||
});
|
||||
}
|
||||
|
||||
private void configureJavaConventions(Project project) {
|
||||
project.getTasks().withType(JavaCompile.class, (compile) -> {
|
||||
compile.getOptions().setEncoding("UTF-8");
|
||||
List<String> args = compile.getOptions().getCompilerArgs();
|
||||
if (!args.contains("-parameters")) {
|
||||
args.add("-parameters");
|
||||
}
|
||||
if (project.hasProperty("toolchainVersion")) {
|
||||
compile.setSourceCompatibility(SOURCE_AND_TARGET_COMPATIBILITY);
|
||||
compile.setTargetCompatibility(SOURCE_AND_TARGET_COMPATIBILITY);
|
||||
}
|
||||
else if (buildingWithJava17(project)) {
|
||||
args.addAll(Arrays.asList("-Xdoclint:none"));
|
||||
// TODO: When we're without javadoc errors
|
||||
// args.addAll(Arrays.asList("-Werror", "-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:rawtypes",
|
||||
// "-Xlint:varargs"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean buildingWithJava17(Project project) {
|
||||
return JavaVersion.current() == JavaVersion.VERSION_17;
|
||||
}
|
||||
|
||||
private void configureTestConventions(Project project) {
|
||||
project.getTasks().withType(Test.class, test -> {
|
||||
test.useJUnitPlatform();
|
||||
});
|
||||
}
|
||||
|
||||
private void configureJarManifestConventions(Project project) {
|
||||
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
|
||||
Set<String> sourceJarTaskNames = sourceSets.stream().map(SourceSet::getSourcesJarTaskName)
|
||||
.collect(Collectors.toSet());
|
||||
Set<String> javadocJarTaskNames = sourceSets.stream().map(SourceSet::getJavadocJarTaskName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
project.getTasks().withType(Jar.class, jar -> {
|
||||
jar.manifest(manifest -> {
|
||||
Map<String, Object> attributes = new TreeMap<>();
|
||||
attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
|
||||
attributes.put("Build-Jdk-Spec", SOURCE_AND_TARGET_COMPATIBILITY);
|
||||
attributes.put("Built-By", "Spring");
|
||||
attributes.put("Implementation-Title",
|
||||
determineImplementationTitle(project, sourceJarTaskNames, javadocJarTaskNames, jar));
|
||||
attributes.put("Implementation-Version", project.getVersion());
|
||||
manifest.attributes(attributes);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private String determineImplementationTitle(Project project, Set<String> sourceJarTaskNames,
|
||||
Set<String> javadocJarTaskNames, Jar jar) {
|
||||
if (sourceJarTaskNames.contains(jar.getName())) {
|
||||
return "Source for " + project.getName();
|
||||
}
|
||||
if (javadocJarTaskNames.contains(jar.getName())) {
|
||||
return "Javadoc for " + project.getName();
|
||||
}
|
||||
return "Jar for " + project.getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaTestFixturesPlugin;
|
||||
import org.gradle.api.plugins.PluginContainer;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
/**
|
||||
* Creates a Management configuration that is appropriate for adding a platform
|
||||
* to that is not exposed externally. If the JavaPlugin is applied, the
|
||||
* compileClasspath, runtimeClasspath, testCompileClasspath, and
|
||||
* testRuntimeClasspath will extend from it.
|
||||
*
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
public class ManagementConfigurationPlugin implements Plugin<Project> {
|
||||
|
||||
public static final String MANAGEMENT_CONFIGURATION_NAME = "management";
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
ConfigurationContainer configurations = project.getConfigurations();
|
||||
configurations.create(MANAGEMENT_CONFIGURATION_NAME, (management) -> {
|
||||
management.setVisible(false);
|
||||
management.setCanBeConsumed(false);
|
||||
management.setCanBeResolved(false);
|
||||
PluginContainer plugins = project.getPlugins();
|
||||
plugins.withType(JavaPlugin.class, (javaPlugin) -> {
|
||||
configurations.getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(management);
|
||||
});
|
||||
plugins.withType(JavaTestFixturesPlugin.class, (javaTestFixturesPlugin) -> {
|
||||
configurations.getByName("testFixturesCompileClasspath").extendsFrom(management);
|
||||
configurations.getByName("testFixturesRuntimeClasspath").extendsFrom(management);
|
||||
});
|
||||
plugins.withType(OptionalDependenciesPlugin.class, (optionalDependencies) -> configurations
|
||||
.getByName(OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME).extendsFrom(management));
|
||||
plugins.withType(MavenPublishPlugin.class, (mavenPublish) -> {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getPublications().withType(MavenPublication.class, (mavenPublication -> {
|
||||
mavenPublication.versionMapping((versions) ->
|
||||
versions.allVariants(versionMapping -> versionMapping.fromResolutionResult())
|
||||
);
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaLibraryPlugin;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class ModulePlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public final void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(JavaPlugin.class);
|
||||
pluginManager.apply(OptionalDependenciesPlugin.class);
|
||||
pluginManager.apply(ManagementConfigurationPlugin.class);
|
||||
pluginManager.apply(JavaLibraryPlugin.class);
|
||||
pluginManager.apply(SpringMavenPlugin.class);
|
||||
new ArtifactoryConventions().apply(project);
|
||||
new JavaConventions().apply(project);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
|
||||
public class OptionalDependenciesPlugin implements Plugin<Project> {
|
||||
|
||||
public static final String OPTIONAL_CONFIGURATION_NAME = "optional";
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
Configuration optional = project.getConfigurations().create(OPTIONAL_CONFIGURATION_NAME);
|
||||
optional.setCanBeConsumed(false);
|
||||
optional.setCanBeResolved(false);
|
||||
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
|
||||
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class)
|
||||
.getSourceSets();
|
||||
sourceSets.all((sourceSet) -> {
|
||||
project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName())
|
||||
.extendsFrom(optional);
|
||||
project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName())
|
||||
.extendsFrom(optional);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlatformPlugin;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
public class PublishAllJavaComponentsPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getPublications().create("mavenJava", MavenPublication.class, new Action<MavenPublication>() {
|
||||
@Override
|
||||
public void execute(MavenPublication maven) {
|
||||
project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
|
||||
maven.from(project.getComponents().getByName("java"));
|
||||
});
|
||||
project.getPlugins().withType(JavaPlatformPlugin.class, (plugin) -> {
|
||||
maven.from(project.getComponents().getByName("javaPlatform"));
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
public class PublishLocalPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublish -> {
|
||||
project.getExtensions().getByType(PublishingExtension.class).getRepositories().maven(maven -> {
|
||||
maven.setName("local");
|
||||
maven.setUrl(new File(project.getRootProject().getBuildDir(), "publications/repos"));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.bundling.Zip;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.external.javadoc.CoreJavadocOptions;
|
||||
|
||||
/**
|
||||
* Manages tasks creating zip file for docs and publishing it.
|
||||
*
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class RootPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(MavenPublishPlugin.class);
|
||||
pluginManager.apply(PublishLocalPlugin.class);
|
||||
new ArtifactoryConventions().apply(project);
|
||||
Javadoc apiTask = createApiTask(project);
|
||||
Zip zipTask = createZipTask(project);
|
||||
zipTask.dependsOn(apiTask);
|
||||
}
|
||||
|
||||
private Zip createZipTask(Project project) {
|
||||
Zip zipTask = project.getTasks().create("distZip", Zip.class, zip -> {
|
||||
zip.setGroup("Distribution");
|
||||
zip.from("spring-shell-docs/build/docs/asciidoc", copy -> {
|
||||
copy.into("docs");
|
||||
});
|
||||
zip.from("build/api", copy -> {
|
||||
copy.into("api");
|
||||
});
|
||||
});
|
||||
|
||||
project.getRootProject().getAllprojects().forEach(p -> {
|
||||
p.getPlugins().withType(AsciidoctorJPlugin.class, a -> {
|
||||
p.getTasksByName("asciidoctor", false).forEach(t -> {
|
||||
zipTask.dependsOn(t);
|
||||
});;
|
||||
});
|
||||
});
|
||||
|
||||
project.getArtifacts().add("archives", zipTask);
|
||||
return zipTask;
|
||||
}
|
||||
|
||||
private Javadoc createApiTask(Project project) {
|
||||
Javadoc api = project.getTasks().create("api", Javadoc.class, a -> {
|
||||
a.setGroup("Documentation");
|
||||
a.setDescription("Generates aggregated Javadoc API documentation.");
|
||||
a.setDestinationDir(new File(project.getBuildDir(), "api"));
|
||||
CoreJavadocOptions options = (CoreJavadocOptions) a.getOptions();
|
||||
options.source("17");
|
||||
options.encoding("UTF-8");
|
||||
options.addStringOption("Xdoclint:none", "-quiet");
|
||||
});
|
||||
|
||||
project.getRootProject().getSubprojects().forEach(p -> {
|
||||
p.getPlugins().withType(ModulePlugin.class, m -> {
|
||||
JavaPluginConvention java = p.getConvention().getPlugin(JavaPluginConvention.class);
|
||||
SourceSet mainSourceSet = java.getSourceSets().getByName("main");
|
||||
|
||||
api.setSource(api.getSource().plus(mainSourceSet.getAllJava()));
|
||||
|
||||
p.getTasks().withType(Javadoc.class, j -> {
|
||||
api.setClasspath(api.getClasspath().plus(j.getClasspath()));
|
||||
});
|
||||
});
|
||||
});
|
||||
return api;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
|
||||
/**
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
class SamplePlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(JavaPlugin.class);
|
||||
pluginManager.apply(ManagementConfigurationPlugin.class);
|
||||
new JavaConventions().apply(project);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.security.kerberos.gradle;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
import org.gradle.api.component.AdhocComponentWithVariants;
|
||||
import org.gradle.api.component.ConfigurationVariantDetails;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.plugins.PluginManager;
|
||||
import org.gradle.api.publish.PublishingExtension;
|
||||
import org.gradle.api.publish.VariantVersionMappingStrategy;
|
||||
import org.gradle.api.publish.maven.MavenPom;
|
||||
import org.gradle.api.publish.maven.MavenPomDeveloperSpec;
|
||||
import org.gradle.api.publish.maven.MavenPomIssueManagement;
|
||||
import org.gradle.api.publish.maven.MavenPomLicenseSpec;
|
||||
import org.gradle.api.publish.maven.MavenPomOrganization;
|
||||
import org.gradle.api.publish.maven.MavenPomScm;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
|
||||
|
||||
import groovy.util.Node;
|
||||
|
||||
public class SpringMavenPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
PluginManager pluginManager = project.getPluginManager();
|
||||
pluginManager.apply(MavenPublishPlugin.class);
|
||||
pluginManager.apply(PublishLocalPlugin.class);
|
||||
pluginManager.apply(PublishAllJavaComponentsPlugin.class);
|
||||
|
||||
project.getPlugins().withType(MavenPublishPlugin.class).all(mavenPublish -> {
|
||||
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
|
||||
publishing.getPublications().withType(MavenPublication.class)
|
||||
.all(mavenPublication -> customizeMavenPublication(mavenPublication, project));
|
||||
project.getPlugins().withType(JavaPlugin.class).all(javaPlugin -> {
|
||||
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
extension.withJavadocJar();
|
||||
extension.withSourcesJar();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeMavenPublication(MavenPublication publication, Project project) {
|
||||
customizePom(publication.getPom(), project);
|
||||
project.getPlugins().withType(JavaPlugin.class)
|
||||
.all((javaPlugin) -> customizeJavaMavenPublication(publication, project));
|
||||
suppressMavenOptionalFeatureWarnings(publication);
|
||||
}
|
||||
|
||||
private void customizeJavaMavenPublication(MavenPublication publication, Project project) {
|
||||
addMavenOptionalFeature(project);
|
||||
publication.versionMapping((strategy) -> strategy.usage(Usage.JAVA_API, (mappingStrategy) -> mappingStrategy
|
||||
.fromResolutionOf(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
|
||||
publication.versionMapping(
|
||||
(strategy) -> strategy.usage(Usage.JAVA_RUNTIME, VariantVersionMappingStrategy::fromResolutionResult));
|
||||
}
|
||||
|
||||
private void suppressMavenOptionalFeatureWarnings(MavenPublication publication) {
|
||||
publication.suppressPomMetadataWarningsFor("mavenOptionalApiElements");
|
||||
publication.suppressPomMetadataWarningsFor("mavenOptionalRuntimeElements");
|
||||
}
|
||||
|
||||
private void addMavenOptionalFeature(Project project) {
|
||||
JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
extension.registerFeature("mavenOptional",
|
||||
(feature) -> feature.usingSourceSet(extension.getSourceSets().getByName("main")));
|
||||
AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.getComponents()
|
||||
.findByName("java");
|
||||
if (javaComponent != null) {
|
||||
javaComponent.addVariantsFromConfiguration(
|
||||
project.getConfigurations().findByName("mavenOptionalRuntimeElements"),
|
||||
ConfigurationVariantDetails::mapToOptional);
|
||||
}
|
||||
}
|
||||
|
||||
private void customizePom(MavenPom pom, Project project) {
|
||||
pom.getUrl().set("https://github.com/spring-projects/spring-security-kerberos");
|
||||
pom.getName().set(project.provider(project::getName));
|
||||
pom.getDescription().set(project.provider(project::getDescription));
|
||||
pom.organization(this::customizeOrganization);
|
||||
pom.licenses(this::customizeLicences);
|
||||
pom.developers(this::customizeDevelopers);
|
||||
pom.scm(scm -> customizeScm(scm, project));
|
||||
pom.issueManagement(this::customizeIssueManagement);
|
||||
|
||||
// TODO: find something better not to add dependencyManagement in pom
|
||||
// which result spring-security-kerberos-management in it. spring-security-kerberos-dependencies
|
||||
// has its own dependencyManagement which we need to keep
|
||||
if (!project.getName().equals("spring-security-kerberos-dependencies")) {
|
||||
pom.withXml(xxx -> {
|
||||
Node pomNode = xxx.asNode();
|
||||
List<?> childs = pomNode.children();
|
||||
ListIterator<?> iter = childs.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
Object next = iter.next();
|
||||
if (next instanceof Node) {
|
||||
if (((Node)next).name().toString().equals("{http://maven.apache.org/POM/4.0.0}dependencyManagement")) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeOrganization(MavenPomOrganization organization) {
|
||||
organization.getName().set("Pivotal Software, Inc.");
|
||||
organization.getUrl().set("https://spring.io");
|
||||
}
|
||||
|
||||
private void customizeLicences(MavenPomLicenseSpec licences) {
|
||||
licences.license(licence -> {
|
||||
licence.getName().set("Apache License, Version 2.0");
|
||||
licence.getUrl().set("https://www.apache.org/licenses/LICENSE-2.0");
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeDevelopers(MavenPomDeveloperSpec developers) {
|
||||
developers.developer((developer) -> {
|
||||
developer.getName().set("Pivotal");
|
||||
developer.getEmail().set("info@pivotal.io");
|
||||
developer.getOrganization().set("Pivotal Software, Inc.");
|
||||
developer.getOrganizationUrl().set("https://www.spring.io");
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeScm(MavenPomScm scm, Project project) {
|
||||
scm.getConnection().set("scm:git:git://github.com/spring-projects/spring-security-kerberos.git");
|
||||
scm.getDeveloperConnection().set("scm:git:ssh://git@github.com/spring-projects/spring-security-kerberos.git");
|
||||
scm.getUrl().set("https://github.com/spring-projects/spring-security-kerberos");
|
||||
}
|
||||
|
||||
private void customizeIssueManagement(MavenPomIssueManagement issueManagement) {
|
||||
issueManagement.getSystem().set("GitHub");
|
||||
issueManagement.getUrl().set("https://github.com/spring-projects/spring-security-kerberos/issues");
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
version=2.0.0-SNAPSHOT
|
||||
servletApi3Version=3.1.0
|
||||
httpclientVersion=4.3.3
|
||||
springSecurityVersion=3.2.7.RELEASE
|
||||
tomcatEmbedVersion=7.0.56
|
||||
servletApi2Version=2.5
|
||||
junitVersion=4.11
|
||||
springVersion=4.1.6.RELEASE
|
||||
apacheDirServerVersion=2.0.0-M15
|
||||
springBootVersion=1.2.1.RELEASE
|
||||
log4jVersion=1.2.17
|
||||
apacheDirApiVersion=1.0.0-M20
|
||||
hamcrestVersion=1.3
|
||||
mockitoVersion=1.9.5
|
||||
springBootVersion=3.0.3
|
||||
springFrameworkVersion=6.0.5
|
||||
springSecurityVersion=6.0.2
|
||||
junitVersion=5.9.1
|
||||
mockitoVersion=4.8.1
|
||||
assertjVersion=3.23.1
|
||||
servletApiVersion=6.0.0
|
||||
httpclient5Version=5.1.4
|
||||
# httpclientVersion=4.3.3
|
||||
# servletApi3Version=3.1.0
|
||||
# httpclientVersion=4.3.3
|
||||
# springSecurityVersion=3.2.7.RELEASE
|
||||
# tomcatEmbedVersion=7.0.56
|
||||
# servletApi2Version=2.5
|
||||
# springVersion=4.1.6.RELEASE
|
||||
# apacheDirServerVersion=2.0.0-M15
|
||||
# springBootVersion=1.2.1.RELEASE
|
||||
# log4jVersion=1.2.17
|
||||
# apacheDirApiVersion=1.0.0-M20
|
||||
# hamcrestVersion=1.3
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,5 @@
|
||||
#Fri Feb 20 10:51:36 GMT 2015
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip
|
||||
|
||||
302
gradlew
vendored
302
gradlew
vendored
@@ -1,79 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
MAX_FD=maximum
|
||||
|
||||
warn ( ) {
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
} >&2
|
||||
|
||||
die ( ) {
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
@@ -82,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
@@ -90,75 +140,95 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
53
gradlew.bat
vendored
53
gradlew.bat
vendored
@@ -1,3 +1,19 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@@ -8,20 +24,23 @@
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@@ -35,7 +54,7 @@ goto fail
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
@@ -45,34 +64,14 @@ echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
apply plugin: 'maven'
|
||||
|
||||
ext.optionalDeps = []
|
||||
ext.providedDeps = []
|
||||
|
||||
ext.optional = { optionalDeps << it }
|
||||
ext.provided = { providedDeps << it }
|
||||
|
||||
install {
|
||||
repositories.mavenInstaller {
|
||||
customizePom(pom, project)
|
||||
}
|
||||
}
|
||||
|
||||
def customizePom(pom, gradleProject) {
|
||||
pom.whenConfigured { generatedPom ->
|
||||
// respect 'optional' and 'provided' dependencies
|
||||
gradleProject.optionalDeps.each { dep ->
|
||||
generatedPom.dependencies.find { it.artifactId == dep.name }?.optional = true
|
||||
}
|
||||
gradleProject.providedDeps.each { dep ->
|
||||
generatedPom.dependencies.find { it.artifactId == dep.name }?.scope = 'provided'
|
||||
}
|
||||
|
||||
// eliminate test-scoped dependencies (no need in maven central poms)
|
||||
generatedPom.dependencies.removeAll { dep ->
|
||||
dep.scope == 'test'
|
||||
}
|
||||
|
||||
// add all items necessary for maven central publication
|
||||
generatedPom.project {
|
||||
name = gradleProject.description
|
||||
description = gradleProject.description
|
||||
url = 'https://projects.spring.io/spring-security-kerberos'
|
||||
organization {
|
||||
name = 'SpringSource'
|
||||
url = 'https://projects.spring.io/spring-security-kerberos/'
|
||||
}
|
||||
licenses {
|
||||
license {
|
||||
name 'The Apache Software License, Version 2.0'
|
||||
url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
distribution 'repo'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/SpringSource/spring-security-kerberos'
|
||||
connection = 'scm:git:git://github.com/SpringSource/spring-security-kerberos'
|
||||
developerConnection = 'scm:git:git://github.com/SpringSource/spring-security-kerberos'
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'mwiesner'
|
||||
name = 'Mike Wiesner'
|
||||
email = 'mwiesner@vmware.com'
|
||||
}
|
||||
developer {
|
||||
id = 'jvalkeal'
|
||||
name = 'Janne Valkealahti'
|
||||
email = 'jvalkealahti@pivotal.io'
|
||||
properties {
|
||||
twitter = 'tunebluez'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,41 @@
|
||||
rootProject.name = 'spring-security-kerberos'
|
||||
|
||||
include 'spring-security-kerberos-core'
|
||||
include 'spring-security-kerberos-client'
|
||||
include 'spring-security-kerberos-test'
|
||||
include 'spring-security-kerberos-web'
|
||||
include 'spring-security-kerberos-samples'
|
||||
include 'spring-security-kerberos-samples:sec-server-client-auth'
|
||||
include 'spring-security-kerberos-samples:sec-server-spnego-form-auth'
|
||||
include 'spring-security-kerberos-samples:sec-server-spnego-form-auth-xml'
|
||||
include 'spring-security-kerberos-samples:sec-server-win-auth'
|
||||
include 'spring-security-kerberos-samples:sec-client-rest-template'
|
||||
|
||||
rootProject.children.find {
|
||||
if (it.name == 'spring-security-kerberos-samples') {
|
||||
it.name = 'spring-security-kerberos-samples-common'
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven { url 'https://repo.spring.io/release' }
|
||||
if (version.contains('-')) {
|
||||
maven { url 'https://repo.spring.io/milestone' }
|
||||
}
|
||||
if (version.endsWith('-SNAPSHOT')) {
|
||||
maven { url 'https://repo.spring.io/snapshot' }
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id 'org.springframework.boot' version "$springBootVersion"
|
||||
id 'io.spring.dependency-management' version '1.1.0'
|
||||
// id 'com.gradle.enterprise' version "$gradleEnterpriseVersion"
|
||||
// id 'io.spring.ge.conventions' version "$springGeConventionsVersion"
|
||||
}
|
||||
}
|
||||
|
||||
// plugins {
|
||||
// id "com.gradle.enterprise"
|
||||
// id "io.spring.ge.conventions"
|
||||
// }
|
||||
|
||||
rootProject.name = 'spring-security-kerberos'
|
||||
|
||||
include 'spring-security-kerberos-management'
|
||||
include 'spring-security-kerberos-core'
|
||||
include 'spring-security-kerberos-client'
|
||||
include 'spring-security-kerberos-web'
|
||||
include 'spring-security-kerberos-samples:sec-server-spnego-form-auth'
|
||||
|
||||
rootProject.children.each { project ->
|
||||
project.buildFileName = "${project.name}.gradle"
|
||||
if (project.name == 'spring-security-kerberos-samples') {
|
||||
project.children.each { sampleProject ->
|
||||
sampleProject.buildFileName = "${sampleProject.name}.gradle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
id 'org.springframework.security.kerberos.module'
|
||||
}
|
||||
|
||||
description = 'Spring Security Kerberos Client'
|
||||
|
||||
dependencies {
|
||||
management platform(project(":spring-security-kerberos-management"))
|
||||
implementation project(':spring-security-kerberos-core')
|
||||
implementation project(':spring-security-kerberos-web')
|
||||
// api('org.apache.httpcomponents:httpclient')
|
||||
api('org.apache.httpcomponents.client5:httpclient5')
|
||||
optional 'org.springframework.security:spring-security-ldap'
|
||||
// api('org.springframework.security:spring-security-web')
|
||||
// api('jakarta.servlet:jakarta.servlet-api')
|
||||
testImplementation 'org.springframework:spring-test'
|
||||
testImplementation 'org.springframework.security:spring-security-config'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter'
|
||||
testImplementation 'org.assertj:assertj-core'
|
||||
}
|
||||
@@ -36,17 +36,27 @@ import javax.security.auth.login.Configuration;
|
||||
import javax.security.auth.login.LoginContext;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import org.apache.http.auth.AuthSchemeProvider;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.Credentials;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.AuthSchemes;
|
||||
import org.apache.http.config.Lookup;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.impl.auth.SPNegoSchemeFactory;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemeFactory;
|
||||
import org.apache.hc.client5.http.auth.AuthScope;
|
||||
import org.apache.hc.client5.http.auth.Credentials;
|
||||
import org.apache.hc.client5.http.classic.HttpClient;
|
||||
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
|
||||
import org.apache.hc.client5.http.impl.auth.SPNegoSchemeFactory;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||
import org.apache.hc.core5.http.config.Lookup;
|
||||
|
||||
// import org.apache.http.auth.AuthSchemeProvider;
|
||||
// import org.apache.http.auth.AuthScope;
|
||||
// import org.apache.http.auth.Credentials;
|
||||
// import org.apache.http.client.HttpClient;
|
||||
// import org.apache.http.client.config.AuthSchemes;
|
||||
// import org.apache.http.config.Lookup;
|
||||
// import org.apache.http.config.RegistryBuilder;
|
||||
// import org.apache.http.impl.auth.SPNegoSchemeFactory;
|
||||
// import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
// import org.apache.http.impl.client.CloseableHttpClient;
|
||||
// import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -197,11 +207,12 @@ public class KerberosRestTemplate extends RestTemplate {
|
||||
*/
|
||||
private static HttpClient buildHttpClient() {
|
||||
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||
Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create()
|
||||
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build();
|
||||
// Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create()
|
||||
// .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build();
|
||||
Lookup<AuthSchemeFactory> authSchemeRegistry = null;
|
||||
builder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
|
||||
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
credentialsProvider.setCredentials(new AuthScope(null, -1, null), credentials);
|
||||
credentialsProvider.setCredentials(new AuthScope(null, -1), credentials);
|
||||
builder.setDefaultCredentialsProvider(credentialsProvider);
|
||||
CloseableHttpClient httpClient = builder.build();
|
||||
return httpClient;
|
||||
@@ -303,7 +314,7 @@ public class KerberosRestTemplate extends RestTemplate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
public char[] getPassword() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,249 +15,249 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.client;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
// import static org.hamcrest.CoreMatchers.is;
|
||||
// import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.net.InetAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
// import java.io.File;
|
||||
// import java.io.IOException;
|
||||
// import java.lang.annotation.Documented;
|
||||
// import java.lang.annotation.ElementType;
|
||||
// import java.lang.annotation.Retention;
|
||||
// import java.lang.annotation.RetentionPolicy;
|
||||
// import java.lang.annotation.Target;
|
||||
// import java.net.InetAddress;
|
||||
// import java.util.concurrent.CountDownLatch;
|
||||
// import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.security.kerberos.client.KerberosRestTemplate;
|
||||
import org.springframework.security.kerberos.test.KerberosSecurityTestcase;
|
||||
import org.springframework.security.kerberos.test.MiniKdc;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
// import org.junit.After;
|
||||
// import org.junit.Test;
|
||||
// import org.springframework.boot.SpringApplication;
|
||||
// import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||
// import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
// import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
// import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
// import org.springframework.context.ApplicationListener;
|
||||
// import org.springframework.context.ConfigurableApplicationContext;
|
||||
// import org.springframework.context.annotation.Bean;
|
||||
// import org.springframework.context.annotation.Configuration;
|
||||
// import org.springframework.context.annotation.Import;
|
||||
// import org.springframework.http.client.ClientHttpResponse;
|
||||
// import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
// import org.springframework.security.kerberos.client.KerberosRestTemplate;
|
||||
// import org.springframework.security.kerberos.test.KerberosSecurityTestcase;
|
||||
// import org.springframework.security.kerberos.test.MiniKdc;
|
||||
// import org.springframework.stereotype.Controller;
|
||||
// import org.springframework.web.bind.annotation.RequestMapping;
|
||||
// import org.springframework.web.bind.annotation.RequestMethod;
|
||||
// import org.springframework.web.bind.annotation.ResponseBody;
|
||||
// import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
// import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class KerberosRestTemplateTests extends KerberosSecurityTestcase {
|
||||
public class KerberosRestTemplateTests /*extends KerberosSecurityTestcase */{
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
// private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
context = null;
|
||||
}
|
||||
// @After
|
||||
// public void close() {
|
||||
// if (context != null) {
|
||||
// context.close();
|
||||
// }
|
||||
// context = null;
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testSpnego() throws Exception {
|
||||
// @Test
|
||||
// public void testSpnego() throws Exception {
|
||||
|
||||
MiniKdc kdc = getKdc();
|
||||
File workDir = getWorkDir();
|
||||
String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
// MiniKdc kdc = getKdc();
|
||||
// File workDir = getWorkDir();
|
||||
// String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
|
||||
String serverPrincipal = "HTTP/" + host;
|
||||
File serverKeytab = new File(workDir, "server.keytab");
|
||||
kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
// String serverPrincipal = "HTTP/" + host;
|
||||
// File serverKeytab = new File(workDir, "server.keytab");
|
||||
// kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
|
||||
String clientPrincipal = "client/" + host;
|
||||
File clientKeytab = new File(workDir, "client.keytab");
|
||||
kdc.createPrincipal(clientKeytab, clientPrincipal);
|
||||
// String clientPrincipal = "client/" + host;
|
||||
// File clientKeytab = new File(workDir, "client.keytab");
|
||||
// kdc.createPrincipal(clientKeytab, clientPrincipal);
|
||||
|
||||
|
||||
context = SpringApplication.run(new Object[] { WebSecurityConfig.class, VanillaWebConfiguration.class,
|
||||
WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
"--security.user.name=username", "--security.user.password=password",
|
||||
"--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
// context = SpringApplication.run(new Object[] { WebSecurityConfig.class, VanillaWebConfiguration.class,
|
||||
// WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
// "--security.user.name=username", "--security.user.password=password",
|
||||
// "--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
|
||||
PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
int port = portInitListener.port;
|
||||
// PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
// assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
// int port = portInitListener.port;
|
||||
|
||||
KerberosRestTemplate restTemplate = new KerberosRestTemplate(clientKeytab.getAbsolutePath(), clientPrincipal);
|
||||
// KerberosRestTemplate restTemplate = new KerberosRestTemplate(clientKeytab.getAbsolutePath(), clientPrincipal);
|
||||
|
||||
String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
assertThat(response, is("home"));
|
||||
}
|
||||
// String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
// assertThat(response, is("home"));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testSpnegoWithPassword() throws Exception {
|
||||
// @Test
|
||||
// public void testSpnegoWithPassword() throws Exception {
|
||||
|
||||
MiniKdc kdc = getKdc();
|
||||
File workDir = getWorkDir();
|
||||
String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
// MiniKdc kdc = getKdc();
|
||||
// File workDir = getWorkDir();
|
||||
// String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
|
||||
String serverPrincipal = "HTTP/" + host;
|
||||
File serverKeytab = new File(workDir, "server.keytab");
|
||||
kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
// String serverPrincipal = "HTTP/" + host;
|
||||
// File serverKeytab = new File(workDir, "server.keytab");
|
||||
// kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
|
||||
String userPrincipal = "testuser";
|
||||
String password = "testpassword";
|
||||
kdc.createPrincipal(userPrincipal, password);
|
||||
// String userPrincipal = "testuser";
|
||||
// String password = "testpassword";
|
||||
// kdc.createPrincipal(userPrincipal, password);
|
||||
|
||||
|
||||
context = SpringApplication.run(new Object[] { WebSecurityConfig.class, VanillaWebConfiguration.class,
|
||||
WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
"--security.user.name=username", "--security.user.password=password",
|
||||
"--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
// context = SpringApplication.run(new Object[] { WebSecurityConfig.class, VanillaWebConfiguration.class,
|
||||
// WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
// "--security.user.name=username", "--security.user.password=password",
|
||||
// "--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
|
||||
PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
int port = portInitListener.port;
|
||||
// PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
// assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
// int port = portInitListener.port;
|
||||
|
||||
KerberosRestTemplate restTemplate = new KerberosRestTemplate(null, userPrincipal, password, null);
|
||||
// KerberosRestTemplate restTemplate = new KerberosRestTemplate(null, userPrincipal, password, null);
|
||||
|
||||
String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
assertThat(response, is("home"));
|
||||
}
|
||||
// String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
// assertThat(response, is("home"));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testSpnegoWithForward() throws Exception {
|
||||
// @Test
|
||||
// public void testSpnegoWithForward() throws Exception {
|
||||
|
||||
MiniKdc kdc = getKdc();
|
||||
File workDir = getWorkDir();
|
||||
String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
// MiniKdc kdc = getKdc();
|
||||
// File workDir = getWorkDir();
|
||||
// String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
|
||||
String serverPrincipal = "HTTP/" + host;
|
||||
File serverKeytab = new File(workDir, "server.keytab");
|
||||
kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
// String serverPrincipal = "HTTP/" + host;
|
||||
// File serverKeytab = new File(workDir, "server.keytab");
|
||||
// kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
|
||||
context = SpringApplication.run(new Object[] { WebSecurityConfigSpnegoForward.class, VanillaWebConfiguration.class,
|
||||
WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
"--security.user.name=username", "--security.user.password=password",
|
||||
"--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
// context = SpringApplication.run(new Object[] { WebSecurityConfigSpnegoForward.class, VanillaWebConfiguration.class,
|
||||
// WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
// "--security.user.name=username", "--security.user.password=password",
|
||||
// "--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
|
||||
PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
int port = portInitListener.port;
|
||||
// PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
// assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
// int port = portInitListener.port;
|
||||
|
||||
// TODO: should tweak minikdc so that we can use kerberos principals
|
||||
// which are not valid, for now just use plain RestTemplate
|
||||
// // TODO: should tweak minikdc so that we can use kerberos principals
|
||||
// // which are not valid, for now just use plain RestTemplate
|
||||
|
||||
// just checking that we get 401 which we skip and
|
||||
// get login page content
|
||||
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
}
|
||||
});
|
||||
// // just checking that we get 401 which we skip and
|
||||
// // get login page content
|
||||
// RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
|
||||
// restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
// @Override
|
||||
// public void handleError(ClientHttpResponse response) throws IOException {
|
||||
// }
|
||||
// });
|
||||
|
||||
String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
assertThat(response, is("login"));
|
||||
}
|
||||
// String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
// assertThat(response, is("login"));
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testSpnegoWithSuccessHandler() throws Exception {
|
||||
// @Test
|
||||
// public void testSpnegoWithSuccessHandler() throws Exception {
|
||||
|
||||
MiniKdc kdc = getKdc();
|
||||
File workDir = getWorkDir();
|
||||
String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
// MiniKdc kdc = getKdc();
|
||||
// File workDir = getWorkDir();
|
||||
// String host = InetAddress.getLocalHost().getCanonicalHostName();
|
||||
|
||||
String serverPrincipal = "HTTP/" + host;
|
||||
File serverKeytab = new File(workDir, "server.keytab");
|
||||
kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
// String serverPrincipal = "HTTP/" + host;
|
||||
// File serverKeytab = new File(workDir, "server.keytab");
|
||||
// kdc.createPrincipal(serverKeytab, serverPrincipal);
|
||||
|
||||
String clientPrincipal = "client/" + host;
|
||||
File clientKeytab = new File(workDir, "client.keytab");
|
||||
kdc.createPrincipal(clientKeytab, clientPrincipal);
|
||||
// String clientPrincipal = "client/" + host;
|
||||
// File clientKeytab = new File(workDir, "client.keytab");
|
||||
// kdc.createPrincipal(clientKeytab, clientPrincipal);
|
||||
|
||||
|
||||
context = SpringApplication.run(new Object[] { WebSecurityConfigSuccessHandler.class, VanillaWebConfiguration.class,
|
||||
WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
"--security.user.name=username", "--security.user.password=password",
|
||||
"--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
// context = SpringApplication.run(new Object[] { WebSecurityConfigSuccessHandler.class, VanillaWebConfiguration.class,
|
||||
// WebConfiguration.class }, new String[] { "--security.basic.enabled=true",
|
||||
// "--security.user.name=username", "--security.user.password=password",
|
||||
// "--serverPrincipal=" + serverPrincipal, "--serverKeytab=" + serverKeytab.getAbsolutePath() });
|
||||
|
||||
PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
int port = portInitListener.port;
|
||||
// PortInitListener portInitListener = context.getBean(PortInitListener.class);
|
||||
// assertThat(portInitListener.latch.await(10, TimeUnit.SECONDS), is(true));
|
||||
// int port = portInitListener.port;
|
||||
|
||||
KerberosRestTemplate restTemplate = new KerberosRestTemplate(clientKeytab.getAbsolutePath(), clientPrincipal);
|
||||
// KerberosRestTemplate restTemplate = new KerberosRestTemplate(clientKeytab.getAbsolutePath(), clientPrincipal);
|
||||
|
||||
String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
assertThat(response, is("home"));
|
||||
}
|
||||
// String response = restTemplate.getForObject("http://" + host + ":" + port + "/hello", String.class);
|
||||
// assertThat(response, is("home"));
|
||||
// }
|
||||
|
||||
protected static class PortInitListener implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
// protected static class PortInitListener implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
public int port;
|
||||
public CountDownLatch latch = new CountDownLatch(1);
|
||||
// public int port;
|
||||
// public CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
|
||||
port = event.getEmbeddedServletContainer().getPort();
|
||||
latch.countDown();
|
||||
}
|
||||
// @Override
|
||||
// public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
|
||||
// port = event.getEmbeddedServletContainer().getPort();
|
||||
// latch.countDown();
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
@Configuration
|
||||
protected static class VanillaWebConfiguration {
|
||||
// @Configuration
|
||||
// protected static class VanillaWebConfiguration {
|
||||
|
||||
@Bean
|
||||
public PortInitListener portListener() {
|
||||
return new PortInitListener();
|
||||
}
|
||||
// @Bean
|
||||
// public PortInitListener portListener() {
|
||||
// return new PortInitListener();
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
|
||||
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
|
||||
factory.setPort(0);
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
// @Bean
|
||||
// public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
|
||||
// TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
|
||||
// factory.setPort(0);
|
||||
// return factory;
|
||||
// }
|
||||
// }
|
||||
|
||||
@MinimalWebConfiguration
|
||||
@Import(SecurityAutoConfiguration.class)
|
||||
@Controller
|
||||
protected static class WebConfiguration {
|
||||
// @MinimalWebConfiguration
|
||||
// @Import(SecurityAutoConfiguration.class)
|
||||
// @Controller
|
||||
// protected static class WebConfiguration {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String home() {
|
||||
return "home";
|
||||
}
|
||||
// @RequestMapping(method = RequestMethod.GET)
|
||||
// @ResponseBody
|
||||
// public String home() {
|
||||
// return "home";
|
||||
// }
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/login")
|
||||
@ResponseBody
|
||||
public String login() {
|
||||
return "login";
|
||||
}
|
||||
// @RequestMapping(method = RequestMethod.GET, value = "/login")
|
||||
// @ResponseBody
|
||||
// public String login() {
|
||||
// return "login";
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
@Configuration
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import({ EmbeddedServletContainerAutoConfiguration.class,
|
||||
ServerPropertiesAutoConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class,
|
||||
ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
protected static @interface MinimalWebConfiguration {
|
||||
}
|
||||
// @Configuration
|
||||
// @Target(ElementType.TYPE)
|
||||
// @Retention(RetentionPolicy.RUNTIME)
|
||||
// @Documented
|
||||
// @Import({ EmbeddedServletContainerAutoConfiguration.class,
|
||||
// ServerPropertiesAutoConfiguration.class,
|
||||
// DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
// HttpMessageConvertersAutoConfiguration.class,
|
||||
// ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
// protected static @interface MinimalWebConfiguration {
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -30,164 +29,163 @@ import org.springframework.security.kerberos.authentication.KerberosServiceAuthe
|
||||
import org.springframework.security.kerberos.authentication.KerberosServiceRequestToken;
|
||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
||||
import org.springframework.security.kerberos.test.KerberosSecurityTestcase;
|
||||
import org.springframework.security.kerberos.test.MiniKdc;
|
||||
// import org.springframework.security.kerberos.test.KerberosSecurityTestcase;
|
||||
// import org.springframework.security.kerberos.test.MiniKdc;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Bogdan Mustiata
|
||||
*/
|
||||
public class TestMultiTierAuthentication extends KerberosSecurityTestcase {
|
||||
public class TestMultiTierAuthentication /* extends KerberosSecurityTestcase*/ {
|
||||
|
||||
public static final String REALM_NAME = "EXAMPLE.COM";
|
||||
// public static final String REALM_NAME = "EXAMPLE.COM";
|
||||
|
||||
public static final String USER_LOGIN_NAME = "user1";
|
||||
public static final String USER_FQDN_NAME = "user1@EXAMPLE.COM";
|
||||
public static final String USER_PASSWORD = "secret";
|
||||
// public static final String USER_LOGIN_NAME = "user1";
|
||||
// public static final String USER_FQDN_NAME = "user1@EXAMPLE.COM";
|
||||
// public static final String USER_PASSWORD = "secret";
|
||||
|
||||
public static final String WEB_TIER_SPN = "HTTP/webtier@EXAMPLE.COM";
|
||||
public static final String WEB_TIER_USER_PASSWORD = "secret";
|
||||
// public static final String WEB_TIER_SPN = "HTTP/webtier@EXAMPLE.COM";
|
||||
// public static final String WEB_TIER_USER_PASSWORD = "secret";
|
||||
|
||||
public static final String SERVICE_TIER_SPN = "HTTP/servicetier@EXAMPLE.COM";
|
||||
public static final String SERVICE_TIER_USER_PASSWORD = "secret";
|
||||
// public static final String SERVICE_TIER_SPN = "HTTP/servicetier@EXAMPLE.COM";
|
||||
// public static final String SERVICE_TIER_USER_PASSWORD = "secret";
|
||||
|
||||
@Test
|
||||
public void testServer() throws Exception {
|
||||
MiniKdc kdc = getKdc();
|
||||
File workDir = getWorkDir();
|
||||
// @Test
|
||||
// public void testServer() throws Exception {
|
||||
// MiniKdc kdc = getKdc();
|
||||
// File workDir = getWorkDir();
|
||||
|
||||
File webTierKeytabFile = new File(workDir, "webtier.keytab");
|
||||
kdc.createKeyabFile(webTierKeytabFile, WEB_TIER_SPN, WEB_TIER_USER_PASSWORD);
|
||||
// File webTierKeytabFile = new File(workDir, "webtier.keytab");
|
||||
// kdc.createKeyabFile(webTierKeytabFile, WEB_TIER_SPN, WEB_TIER_USER_PASSWORD);
|
||||
|
||||
File serviceTierKeytabFile = new File(workDir, "servicetier.keytab");
|
||||
kdc.createKeyabFile(serviceTierKeytabFile, SERVICE_TIER_SPN, SERVICE_TIER_USER_PASSWORD);
|
||||
// File serviceTierKeytabFile = new File(workDir, "servicetier.keytab");
|
||||
// kdc.createKeyabFile(serviceTierKeytabFile, SERVICE_TIER_SPN, SERVICE_TIER_USER_PASSWORD);
|
||||
|
||||
//
|
||||
// User logs in as user1/secret
|
||||
//
|
||||
KerberosAuthenticationProvider kerberosAuthProvider =
|
||||
createUserPassAuthenticator(/* debug: */ true);
|
||||
// //
|
||||
// // User logs in as user1/secret
|
||||
// //
|
||||
// KerberosAuthenticationProvider kerberosAuthProvider =
|
||||
// createUserPassAuthenticator(/* debug: */ true);
|
||||
|
||||
Authentication authentication = kerberosAuthProvider
|
||||
.authenticate(new UsernamePasswordAuthenticationToken(USER_LOGIN_NAME, USER_PASSWORD));
|
||||
// Authentication authentication = kerberosAuthProvider
|
||||
// .authenticate(new UsernamePasswordAuthenticationToken(USER_LOGIN_NAME, USER_PASSWORD));
|
||||
|
||||
assertEquals(USER_FQDN_NAME, authentication.getName());
|
||||
// assertEquals(USER_FQDN_NAME, authentication.getName());
|
||||
|
||||
//
|
||||
// User creates a ticket for the HTTP/webtier@EXAMPLE.COM, using
|
||||
// and then calls the service, using the tokenData
|
||||
//
|
||||
authentication = KerberosMultiTier.authenticateService(
|
||||
authentication, USER_LOGIN_NAME, 3600, WEB_TIER_SPN);
|
||||
// //
|
||||
// // User creates a ticket for the HTTP/webtier@EXAMPLE.COM, using
|
||||
// // and then calls the service, using the tokenData
|
||||
// //
|
||||
// authentication = KerberosMultiTier.authenticateService(
|
||||
// authentication, USER_LOGIN_NAME, 3600, WEB_TIER_SPN);
|
||||
|
||||
byte[] tokenData = KerberosMultiTier
|
||||
.getTokenForService(authentication, WEB_TIER_SPN);
|
||||
// byte[] tokenData = KerberosMultiTier
|
||||
// .getTokenForService(authentication, WEB_TIER_SPN);
|
||||
|
||||
assertNotNull(tokenData);
|
||||
assertTrue(tokenData.length != 0);
|
||||
// assertNotNull(tokenData);
|
||||
// assertTrue(tokenData.length != 0);
|
||||
|
||||
//
|
||||
// The service HTTP/webtier@EXAMPLE.COM authenticates via tokens.
|
||||
//
|
||||
KerberosServiceAuthenticationProvider webTierAuthenticatorProvider =
|
||||
createServiceAuthenticator(
|
||||
true,
|
||||
WEB_TIER_SPN,
|
||||
REALM_NAME,
|
||||
webTierKeytabFile.getCanonicalPath()
|
||||
);
|
||||
// //
|
||||
// // The service HTTP/webtier@EXAMPLE.COM authenticates via tokens.
|
||||
// //
|
||||
// KerberosServiceAuthenticationProvider webTierAuthenticatorProvider =
|
||||
// createServiceAuthenticator(
|
||||
// true,
|
||||
// WEB_TIER_SPN,
|
||||
// REALM_NAME,
|
||||
// webTierKeytabFile.getCanonicalPath()
|
||||
// );
|
||||
|
||||
|
||||
//
|
||||
// The service HTTP/webtier@EXAMPLE.COM authenticates the user1@EXAMPLE.COM
|
||||
// using the previously stored token, then authenticates itself further as
|
||||
// user1@EXAMPLE.COM to the HTTP/servicetier@EXAMPLE.COM.
|
||||
//
|
||||
Authentication webTierAuthentication = webTierAuthenticatorProvider
|
||||
.authenticate(new KerberosServiceRequestToken(tokenData));
|
||||
// //
|
||||
// // The service HTTP/webtier@EXAMPLE.COM authenticates the user1@EXAMPLE.COM
|
||||
// // using the previously stored token, then authenticates itself further as
|
||||
// // user1@EXAMPLE.COM to the HTTP/servicetier@EXAMPLE.COM.
|
||||
// //
|
||||
// Authentication webTierAuthentication = webTierAuthenticatorProvider
|
||||
// .authenticate(new KerberosServiceRequestToken(tokenData));
|
||||
|
||||
assertEquals(USER_FQDN_NAME, webTierAuthentication.getName());
|
||||
// assertEquals(USER_FQDN_NAME, webTierAuthentication.getName());
|
||||
|
||||
webTierAuthentication = KerberosMultiTier.authenticateService(
|
||||
webTierAuthentication, USER_FQDN_NAME, 3600, SERVICE_TIER_SPN);
|
||||
// webTierAuthentication = KerberosMultiTier.authenticateService(
|
||||
// webTierAuthentication, USER_FQDN_NAME, 3600, SERVICE_TIER_SPN);
|
||||
|
||||
byte[] workplaceTokenData = KerberosMultiTier.getTokenForService(
|
||||
webTierAuthentication, SERVICE_TIER_SPN);
|
||||
// byte[] workplaceTokenData = KerberosMultiTier.getTokenForService(
|
||||
// webTierAuthentication, SERVICE_TIER_SPN);
|
||||
|
||||
//
|
||||
// The service HTTP/icr@EXAMPLE.COM authenticates via tokens.
|
||||
//
|
||||
webTierAuthenticatorProvider =
|
||||
createServiceAuthenticator(
|
||||
true,
|
||||
SERVICE_TIER_SPN,
|
||||
REALM_NAME,
|
||||
serviceTierKeytabFile.getCanonicalPath()
|
||||
);
|
||||
// //
|
||||
// // The service HTTP/icr@EXAMPLE.COM authenticates via tokens.
|
||||
// //
|
||||
// webTierAuthenticatorProvider =
|
||||
// createServiceAuthenticator(
|
||||
// true,
|
||||
// SERVICE_TIER_SPN,
|
||||
// REALM_NAME,
|
||||
// serviceTierKeytabFile.getCanonicalPath()
|
||||
// );
|
||||
|
||||
//
|
||||
// The service HTTP/servicetier@EXAMPLE.COM authenticates via the previously saved
|
||||
// token, received from the HTTP/webtier@EXAMPLE.COM on behalf of user1@EXAMPLE.COM
|
||||
//
|
||||
Authentication serviceTierAuthentication = webTierAuthenticatorProvider
|
||||
.authenticate(new KerberosServiceRequestToken(workplaceTokenData));
|
||||
// //
|
||||
// // The service HTTP/servicetier@EXAMPLE.COM authenticates via the previously saved
|
||||
// // token, received from the HTTP/webtier@EXAMPLE.COM on behalf of user1@EXAMPLE.COM
|
||||
// //
|
||||
// Authentication serviceTierAuthentication = webTierAuthenticatorProvider
|
||||
// .authenticate(new KerberosServiceRequestToken(workplaceTokenData));
|
||||
|
||||
assertEquals(USER_FQDN_NAME, serviceTierAuthentication.getName());
|
||||
}
|
||||
// assertEquals(USER_FQDN_NAME, serviceTierAuthentication.getName());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create a username/password authenticator.
|
||||
* @return
|
||||
*/
|
||||
private KerberosAuthenticationProvider createUserPassAuthenticator(boolean debug) {
|
||||
KerberosAuthenticationProvider kerberosAuthenticationProvider =
|
||||
new KerberosAuthenticationProvider();
|
||||
// /**
|
||||
// * Create a username/password authenticator.
|
||||
// * @return
|
||||
// */
|
||||
// private KerberosAuthenticationProvider createUserPassAuthenticator(boolean debug) {
|
||||
// KerberosAuthenticationProvider kerberosAuthenticationProvider =
|
||||
// new KerberosAuthenticationProvider();
|
||||
|
||||
SunJaasKerberosClient sunJaasKerberosClient = new SunJaasKerberosClient();
|
||||
// SunJaasKerberosClient sunJaasKerberosClient = new SunJaasKerberosClient();
|
||||
|
||||
sunJaasKerberosClient.setDebug(debug);
|
||||
sunJaasKerberosClient.setMultiTier(true);
|
||||
// sunJaasKerberosClient.setDebug(debug);
|
||||
// sunJaasKerberosClient.setMultiTier(true);
|
||||
|
||||
kerberosAuthenticationProvider.setKerberosClient(sunJaasKerberosClient);
|
||||
kerberosAuthenticationProvider.setUserDetailsService(userDetailsService());
|
||||
// kerberosAuthenticationProvider.setKerberosClient(sunJaasKerberosClient);
|
||||
// kerberosAuthenticationProvider.setUserDetailsService(userDetailsService());
|
||||
|
||||
return kerberosAuthenticationProvider;
|
||||
}
|
||||
// return kerberosAuthenticationProvider;
|
||||
// }
|
||||
|
||||
private KerberosServiceAuthenticationProvider createServiceAuthenticator(boolean debug,
|
||||
String serviceName,
|
||||
String realmName,
|
||||
String keytabFileLocation) throws Exception {
|
||||
KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider =
|
||||
new KerberosServiceAuthenticationProvider();
|
||||
// private KerberosServiceAuthenticationProvider createServiceAuthenticator(boolean debug,
|
||||
// String serviceName,
|
||||
// String realmName,
|
||||
// String keytabFileLocation) throws Exception {
|
||||
// KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider =
|
||||
// new KerberosServiceAuthenticationProvider();
|
||||
|
||||
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
ticketValidator.setDebug(debug);
|
||||
ticketValidator.setServicePrincipal(serviceName);
|
||||
ticketValidator.setRealmName(realmName);
|
||||
ticketValidator.setKeyTabLocation(new FileSystemResource(keytabFileLocation));
|
||||
ticketValidator.setMultiTier(true);
|
||||
// SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
// ticketValidator.setDebug(debug);
|
||||
// ticketValidator.setServicePrincipal(serviceName);
|
||||
// ticketValidator.setRealmName(realmName);
|
||||
// ticketValidator.setKeyTabLocation(new FileSystemResource(keytabFileLocation));
|
||||
// ticketValidator.setMultiTier(true);
|
||||
|
||||
ticketValidator.afterPropertiesSet();
|
||||
// ticketValidator.afterPropertiesSet();
|
||||
|
||||
kerberosServiceAuthenticationProvider.setTicketValidator(ticketValidator);
|
||||
kerberosServiceAuthenticationProvider.setUserDetailsService(userDetailsService());
|
||||
// kerberosServiceAuthenticationProvider.setTicketValidator(ticketValidator);
|
||||
// kerberosServiceAuthenticationProvider.setUserDetailsService(userDetailsService());
|
||||
|
||||
return kerberosServiceAuthenticationProvider;
|
||||
}
|
||||
// return kerberosServiceAuthenticationProvider;
|
||||
// }
|
||||
|
||||
private UserDetailsService userDetailsService() {
|
||||
return new UserDetailsService() {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return new User(username, "notUsed", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
// private UserDetailsService userDetailsService() {
|
||||
// return new UserDetailsService() {
|
||||
// @Override
|
||||
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// return new User(username, "notUsed", true, true, true, true,
|
||||
// AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
// import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
// import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@@ -35,9 +35,9 @@ import org.springframework.security.kerberos.web.authentication.SpnegoAuthentica
|
||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvcSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
// @Configuration
|
||||
// @EnableWebMvcSecurity
|
||||
public class WebSecurityConfig /*extends WebSecurityConfigurerAdapter*/ {
|
||||
|
||||
@Value("${serverPrincipal}")
|
||||
private String serverPrincipal;
|
||||
@@ -45,66 +45,66 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Value("${serverKeytab}")
|
||||
private String serverKeytab;
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home").permitAll()
|
||||
.antMatchers("/hello").access("hasRole('ROLE_USER')")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http
|
||||
// .exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and()
|
||||
// .authorizeRequests()
|
||||
// .antMatchers("/", "/home").permitAll()
|
||||
// .antMatchers("/hello").access("hasRole('ROLE_USER')")
|
||||
// .anyRequest().authenticated()
|
||||
// .and()
|
||||
|
||||
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||
}
|
||||
// .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// auth.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SpnegoEntryPoint spnegoEntryPoint() {
|
||||
return new SpnegoEntryPoint();
|
||||
}
|
||||
// @Bean
|
||||
// public SpnegoEntryPoint spnegoEntryPoint() {
|
||||
// return new SpnegoEntryPoint();
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
AuthenticationManager authenticationManager) {
|
||||
SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
filter.setAuthenticationManager(authenticationManager);
|
||||
return filter;
|
||||
}
|
||||
// @Bean
|
||||
// public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
// AuthenticationManager authenticationManager) {
|
||||
// SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
// filter.setAuthenticationManager(authenticationManager);
|
||||
// return filter;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
|
||||
KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
|
||||
provider.setTicketValidator(sunJaasKerberosTicketValidator());
|
||||
provider.setUserDetailsService(dummyUserDetailsService());
|
||||
return provider;
|
||||
}
|
||||
// @Bean
|
||||
// public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
|
||||
// KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
|
||||
// provider.setTicketValidator(sunJaasKerberosTicketValidator());
|
||||
// provider.setUserDetailsService(dummyUserDetailsService());
|
||||
// return provider;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
ticketValidator.setServicePrincipal(serverPrincipal);
|
||||
ticketValidator.setKeyTabLocation(new FileSystemResource(serverKeytab));
|
||||
ticketValidator.setDebug(true);
|
||||
return ticketValidator;
|
||||
}
|
||||
// @Bean
|
||||
// public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||
// SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
// ticketValidator.setServicePrincipal(serverPrincipal);
|
||||
// ticketValidator.setKeyTabLocation(new FileSystemResource(serverKeytab));
|
||||
// ticketValidator.setDebug(true);
|
||||
// return ticketValidator;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public DummyUserDetailsService dummyUserDetailsService() {
|
||||
return new DummyUserDetailsService();
|
||||
}
|
||||
// @Bean
|
||||
// public DummyUserDetailsService dummyUserDetailsService() {
|
||||
// return new DummyUserDetailsService();
|
||||
// }
|
||||
|
||||
static class DummyUserDetailsService implements UserDetailsService {
|
||||
// static class DummyUserDetailsService implements UserDetailsService {
|
||||
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return new User(username, "notUsed", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
}
|
||||
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// return new User(username, "notUsed", true, true, true, true,
|
||||
// AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
// import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
// import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@@ -35,76 +35,76 @@ import org.springframework.security.kerberos.web.authentication.SpnegoAuthentica
|
||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvcSecurity
|
||||
public class WebSecurityConfigSpnegoForward extends WebSecurityConfigurerAdapter {
|
||||
// @Configuration
|
||||
// @EnableWebMvcSecurity
|
||||
public class WebSecurityConfigSpnegoForward /*extends WebSecurityConfigurerAdapter*/ {
|
||||
|
||||
@Value("${serverPrincipal}")
|
||||
private String serverPrincipal;
|
||||
// @Value("${serverPrincipal}")
|
||||
// private String serverPrincipal;
|
||||
|
||||
@Value("${serverKeytab}")
|
||||
private String serverKeytab;
|
||||
// @Value("${serverKeytab}")
|
||||
// private String serverKeytab;
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home", "/login").permitAll()
|
||||
.antMatchers("/hello").access("hasRole('ROLE_USER')")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http
|
||||
// .exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and()
|
||||
// .authorizeRequests()
|
||||
// .antMatchers("/", "/home", "/login").permitAll()
|
||||
// .antMatchers("/hello").access("hasRole('ROLE_USER')")
|
||||
// .anyRequest().authenticated()
|
||||
// .and()
|
||||
|
||||
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||
}
|
||||
// .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// auth.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SpnegoEntryPoint spnegoEntryPoint() {
|
||||
return new SpnegoEntryPoint("/login");
|
||||
}
|
||||
// @Bean
|
||||
// public SpnegoEntryPoint spnegoEntryPoint() {
|
||||
// return new SpnegoEntryPoint("/login");
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
AuthenticationManager authenticationManager) {
|
||||
SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
filter.setAuthenticationManager(authenticationManager);
|
||||
return filter;
|
||||
}
|
||||
// @Bean
|
||||
// public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
// AuthenticationManager authenticationManager) {
|
||||
// SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
// filter.setAuthenticationManager(authenticationManager);
|
||||
// return filter;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
|
||||
KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
|
||||
provider.setTicketValidator(sunJaasKerberosTicketValidator());
|
||||
provider.setUserDetailsService(dummyUserDetailsService());
|
||||
return provider;
|
||||
}
|
||||
// @Bean
|
||||
// public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
|
||||
// KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
|
||||
// provider.setTicketValidator(sunJaasKerberosTicketValidator());
|
||||
// provider.setUserDetailsService(dummyUserDetailsService());
|
||||
// return provider;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
ticketValidator.setServicePrincipal(serverPrincipal);
|
||||
ticketValidator.setKeyTabLocation(new FileSystemResource(serverKeytab));
|
||||
ticketValidator.setDebug(true);
|
||||
return ticketValidator;
|
||||
}
|
||||
// @Bean
|
||||
// public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||
// SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
// ticketValidator.setServicePrincipal(serverPrincipal);
|
||||
// ticketValidator.setKeyTabLocation(new FileSystemResource(serverKeytab));
|
||||
// ticketValidator.setDebug(true);
|
||||
// return ticketValidator;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public DummyUserDetailsService dummyUserDetailsService() {
|
||||
return new DummyUserDetailsService();
|
||||
}
|
||||
// @Bean
|
||||
// public DummyUserDetailsService dummyUserDetailsService() {
|
||||
// return new DummyUserDetailsService();
|
||||
// }
|
||||
|
||||
static class DummyUserDetailsService implements UserDetailsService {
|
||||
// static class DummyUserDetailsService implements UserDetailsService {
|
||||
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return new User(username, "notUsed", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
}
|
||||
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// return new User(username, "notUsed", true, true, true, true,
|
||||
// AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
// import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
// import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@@ -36,80 +36,80 @@ import org.springframework.security.kerberos.web.authentication.SpnegoAuthentica
|
||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvcSecurity
|
||||
public class WebSecurityConfigSuccessHandler extends WebSecurityConfigurerAdapter {
|
||||
// @Configuration
|
||||
// @EnableWebMvcSecurity
|
||||
public class WebSecurityConfigSuccessHandler /* extends WebSecurityConfigurerAdapter*/ {
|
||||
|
||||
@Value("${serverPrincipal}")
|
||||
private String serverPrincipal;
|
||||
// @Value("${serverPrincipal}")
|
||||
// private String serverPrincipal;
|
||||
|
||||
@Value("${serverKeytab}")
|
||||
private String serverKeytab;
|
||||
// @Value("${serverKeytab}")
|
||||
// private String serverKeytab;
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home").permitAll()
|
||||
.antMatchers("/hello").access("hasRole('ROLE_USER')")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http
|
||||
// .exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and()
|
||||
// .authorizeRequests()
|
||||
// .antMatchers("/", "/home").permitAll()
|
||||
// .antMatchers("/hello").access("hasRole('ROLE_USER')")
|
||||
// .anyRequest().authenticated()
|
||||
// .and()
|
||||
|
||||
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||
}
|
||||
// .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// auth.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SpnegoEntryPoint spnegoEntryPoint() {
|
||||
return new SpnegoEntryPoint();
|
||||
}
|
||||
// @Bean
|
||||
// public SpnegoEntryPoint spnegoEntryPoint() {
|
||||
// return new SpnegoEntryPoint();
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
AuthenticationManager authenticationManager) {
|
||||
SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
// @Bean
|
||||
// public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
// AuthenticationManager authenticationManager) {
|
||||
// SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
|
||||
ResponseHeaderSettingKerberosAuthenticationSuccessHandler successHandler = new ResponseHeaderSettingKerberosAuthenticationSuccessHandler();
|
||||
filter.setSuccessHandler(successHandler);
|
||||
// ResponseHeaderSettingKerberosAuthenticationSuccessHandler successHandler = new ResponseHeaderSettingKerberosAuthenticationSuccessHandler();
|
||||
// filter.setSuccessHandler(successHandler);
|
||||
|
||||
filter.setAuthenticationManager(authenticationManager);
|
||||
return filter;
|
||||
}
|
||||
// filter.setAuthenticationManager(authenticationManager);
|
||||
// return filter;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
|
||||
KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
|
||||
provider.setTicketValidator(sunJaasKerberosTicketValidator());
|
||||
provider.setUserDetailsService(dummyUserDetailsService());
|
||||
return provider;
|
||||
}
|
||||
// @Bean
|
||||
// public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
|
||||
// KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
|
||||
// provider.setTicketValidator(sunJaasKerberosTicketValidator());
|
||||
// provider.setUserDetailsService(dummyUserDetailsService());
|
||||
// return provider;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
ticketValidator.setServicePrincipal(serverPrincipal);
|
||||
ticketValidator.setKeyTabLocation(new FileSystemResource(serverKeytab));
|
||||
ticketValidator.setDebug(true);
|
||||
return ticketValidator;
|
||||
}
|
||||
// @Bean
|
||||
// public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
|
||||
// SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
|
||||
// ticketValidator.setServicePrincipal(serverPrincipal);
|
||||
// ticketValidator.setKeyTabLocation(new FileSystemResource(serverKeytab));
|
||||
// ticketValidator.setDebug(true);
|
||||
// return ticketValidator;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public DummyUserDetailsService dummyUserDetailsService() {
|
||||
return new DummyUserDetailsService();
|
||||
}
|
||||
// @Bean
|
||||
// public DummyUserDetailsService dummyUserDetailsService() {
|
||||
// return new DummyUserDetailsService();
|
||||
// }
|
||||
|
||||
static class DummyUserDetailsService implements UserDetailsService {
|
||||
// static class DummyUserDetailsService implements UserDetailsService {
|
||||
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return new User(username, "notUsed", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
}
|
||||
// public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
// return new User(username, "notUsed", true, true, true, true,
|
||||
// AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
plugins {
|
||||
id 'org.springframework.security.kerberos.module'
|
||||
}
|
||||
|
||||
description = 'Spring Security Kerberos Core'
|
||||
|
||||
dependencies {
|
||||
management platform(project(":spring-security-kerberos-management"))
|
||||
// implementation project(':spring-shell-table')
|
||||
api('org.springframework.security:spring-security-core')
|
||||
// api('org.springframework:spring-core')
|
||||
// api('org.springframework.boot:spring-boot-starter-validation')
|
||||
// api('org.springframework:spring-messaging')
|
||||
// api('org.jline:jline')
|
||||
// api('org.antlr:ST4')
|
||||
// api('commons-io:commons-io')
|
||||
// compileOnly 'com.google.code.findbugs:jsr305'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter'
|
||||
testImplementation 'org.assertj:assertj-core'
|
||||
// testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
// testImplementation 'org.awaitility:awaitility'
|
||||
// testImplementation 'com.google.jimfs:jimfs'
|
||||
}
|
||||
@@ -15,13 +15,16 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
@@ -49,7 +52,7 @@ public class KerberosAuthenticationProviderTest {
|
||||
private static final UserDetails USER_DETAILS = new User(TEST_USER, "empty", true, true, true,true, AUTHORITY_LIST);
|
||||
private static final JaasSubjectHolder JAAS_SUBJECT_HOLDER = new JaasSubjectHolder(null, TEST_USER);
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
// mocking
|
||||
this.kerberosClient = mock(KerberosClient.class);
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.authentication;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.security.authentication.AccountExpiredException;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.CredentialsExpiredException;
|
||||
@@ -39,6 +38,12 @@ import org.springframework.security.kerberos.authentication.KerberosServiceReque
|
||||
import org.springframework.security.kerberos.authentication.KerberosTicketValidation;
|
||||
import org.springframework.security.kerberos.authentication.KerberosTicketValidator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test class for {@link KerberosServiceAuthenticationProvider}
|
||||
*
|
||||
@@ -63,7 +68,7 @@ public class KerberosServiceAuthenticationProviderTest {
|
||||
private static final UserDetails USER_DETAILS = new User(TEST_USER, "empty", true, true, true,true, AUTHORITY_LIST);
|
||||
private static final KerberosServiceRequestToken INPUT_TOKEN = new KerberosServiceRequestToken(TEST_TOKEN);
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
// mocking
|
||||
this.ticketValidator = mock(KerberosTicketValidator.class);
|
||||
@@ -91,48 +96,60 @@ public class KerberosServiceAuthenticationProviderTest {
|
||||
assertEquals(requestToken.getDetails(), output.getDetails());
|
||||
}
|
||||
|
||||
@Test(expected=DisabledException.class)
|
||||
@Test
|
||||
public void testUserIsDisabled() throws Exception {
|
||||
User disabledUser = new User(TEST_USER, "empty", false, true, true,true, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(disabledUser, INPUT_TOKEN);
|
||||
assertThatThrownBy(() -> {
|
||||
User disabledUser = new User(TEST_USER, "empty", false, true, true,true, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(disabledUser, INPUT_TOKEN);
|
||||
}).isInstanceOf(DisabledException.class);
|
||||
}
|
||||
|
||||
@Test(expected=AccountExpiredException.class)
|
||||
@Test
|
||||
public void testUserAccountIsExpired() throws Exception {
|
||||
User expiredUser = new User(TEST_USER, "empty", true, false, true,true, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(expiredUser, INPUT_TOKEN);
|
||||
assertThatThrownBy(() -> {
|
||||
User expiredUser = new User(TEST_USER, "empty", true, false, true,true, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(expiredUser, INPUT_TOKEN);
|
||||
}).isInstanceOf(AccountExpiredException.class);
|
||||
}
|
||||
|
||||
@Test(expected=CredentialsExpiredException.class)
|
||||
@Test
|
||||
public void testUserCredentialsExpired() throws Exception {
|
||||
User credExpiredUser = new User(TEST_USER, "empty", true, true, false ,true, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(credExpiredUser, INPUT_TOKEN);
|
||||
assertThatThrownBy(() -> {
|
||||
User credExpiredUser = new User(TEST_USER, "empty", true, true, false ,true, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(credExpiredUser, INPUT_TOKEN);
|
||||
}).isInstanceOf(CredentialsExpiredException.class);
|
||||
}
|
||||
|
||||
@Test(expected=LockedException.class)
|
||||
@Test
|
||||
public void testUserAccountLockedCredentialsExpired() throws Exception {
|
||||
User lockedUser = new User(TEST_USER, "empty", true, true, true ,false, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(lockedUser, INPUT_TOKEN);
|
||||
assertThatThrownBy(() -> {
|
||||
User lockedUser = new User(TEST_USER, "empty", true, true, true ,false, AUTHORITY_LIST);
|
||||
callProviderAndReturnUser(lockedUser, INPUT_TOKEN);
|
||||
}).isInstanceOf(LockedException.class);
|
||||
}
|
||||
|
||||
@Test(expected=UsernameNotFoundException.class)
|
||||
@Test
|
||||
public void testUsernameNotFound() throws Exception {
|
||||
// stubbing
|
||||
when(ticketValidator.validateTicket(TEST_TOKEN)).thenReturn(TICKET_VALIDATION);
|
||||
when(userDetailsService.loadUserByUsername(TEST_USER)).thenThrow(new UsernameNotFoundException(""));
|
||||
|
||||
// testing
|
||||
provider.authenticate(INPUT_TOKEN);
|
||||
assertThatThrownBy(() -> {
|
||||
provider.authenticate(INPUT_TOKEN);
|
||||
}).isInstanceOf(UsernameNotFoundException.class);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=BadCredentialsException.class)
|
||||
@Test
|
||||
public void testTicketValidationWrong() throws Exception {
|
||||
// stubbing
|
||||
when(ticketValidator.validateTicket(TEST_TOKEN)).thenThrow(new BadCredentialsException(""));
|
||||
|
||||
// testing
|
||||
provider.authenticate(INPUT_TOKEN);
|
||||
assertThatThrownBy(() -> {
|
||||
provider.authenticate(INPUT_TOKEN);
|
||||
}).isInstanceOf(BadCredentialsException.class);
|
||||
}
|
||||
|
||||
private Authentication callProviderAndReturnUser(UserDetails userDetails, Authentication inputToken) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package org.springframework.security.kerberos.authentication;
|
||||
|
||||
import org.ietf.jgss.GSSContext;
|
||||
import org.ietf.jgss.GSSCredential;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.security.auth.Subject;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.ietf.jgss.GSSContext;
|
||||
import org.ietf.jgss.GSSCredential;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class KerberosTicketValidationTest {
|
||||
|
||||
@@ -30,7 +31,7 @@ public class KerberosTicketValidationTest {
|
||||
assertEquals(responseToken, ticketValidation.responseToken());
|
||||
assertEquals(gssContext, ticketValidation.getGssContext());
|
||||
|
||||
assertNull("With no credential delegation", ticketValidation.getDelegationCredential());
|
||||
assertNull(ticketValidation.getDelegationCredential(), "With no credential delegation");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,6 +48,6 @@ public class KerberosTicketValidationTest {
|
||||
assertEquals(responseToken, ticketValidation.responseToken());
|
||||
assertEquals(gssContext, ticketValidation.getGssContext());
|
||||
|
||||
assertEquals("With credential delegation", delegationCredential, ticketValidation.getDelegationCredential());
|
||||
assertEquals(delegationCredential, ticketValidation.getDelegationCredential(), "With credential delegation");
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.authentication.sun;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.crypto.codec.Base64;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class SunJaasKerberosTicketValidatorTests {
|
||||
|
||||
// copy of token taken from a test where windows host
|
||||
@@ -66,17 +65,29 @@ public class SunJaasKerberosTicketValidatorTests {
|
||||
+ "PB1vJdIMjc8benP9/+EUhX1LkwvV/rOO3ocwjtdLY1rcmNXSbhnf8jDcVjOe"
|
||||
+ "eL2PHBfvkne/FgxC";
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
// @Rule
|
||||
// public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
// @Test
|
||||
// public void testJdkMsKrb5OIDRegressionTweak() throws Exception {
|
||||
// thrown.expect(BadCredentialsException.class);
|
||||
// thrown.expectMessage(not(containsString("GSSContext name of the context initiator is null")));
|
||||
// thrown.expectMessage(containsString("Kerberos validation not successful"));
|
||||
// SunJaasKerberosTicketValidator validator = new SunJaasKerberosTicketValidator();
|
||||
// byte[] kerberosTicket = Base64.decode(header.getBytes());
|
||||
// validator.validateTicket(kerberosTicket);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testJdkMsKrb5OIDRegressionTweak() throws Exception {
|
||||
thrown.expect(BadCredentialsException.class);
|
||||
thrown.expectMessage(not(containsString("GSSContext name of the context initiator is null")));
|
||||
thrown.expectMessage(containsString("Kerberos validation not successful"));
|
||||
SunJaasKerberosTicketValidator validator = new SunJaasKerberosTicketValidator();
|
||||
byte[] kerberosTicket = Base64.decode(header.getBytes());
|
||||
validator.validateTicket(kerberosTicket);
|
||||
public void testJdkMsKrb5OIDRegressionTweak() {
|
||||
assertThatThrownBy(() -> {
|
||||
SunJaasKerberosTicketValidator validator = new SunJaasKerberosTicketValidator();
|
||||
byte[] kerberosTicket = Base64.decode(header.getBytes());
|
||||
validator.validateTicket(kerberosTicket);
|
||||
})
|
||||
.isInstanceOf(BadCredentialsException.class)
|
||||
.hasMessageNotContaining("GSSContext name of the context initiator is null")
|
||||
.hasMessageContaining("Kerberos validation not successful");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id 'java-platform'
|
||||
}
|
||||
|
||||
javaPlatform {
|
||||
allowDependencies()
|
||||
}
|
||||
|
||||
description = 'Spring Security Kerberos Management'
|
||||
|
||||
dependencies {
|
||||
api platform("org.springframework:spring-framework-bom:$springFrameworkVersion")
|
||||
api platform("org.springframework.security:spring-security-bom:$springSecurityVersion")
|
||||
api platform("org.junit:junit-bom:$junitVersion")
|
||||
api platform("org.mockito:mockito-bom:$mockitoVersion")
|
||||
constraints {
|
||||
// api "org.apache.httpcomponents:httpclient:$httpclientVersion"
|
||||
api "org.apache.httpcomponents.client5:httpclient5:$httpclient5Version"
|
||||
api "org.assertj:assertj-core:$assertjVersion"
|
||||
api "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
description = 'Spring Security Kerberos Samples Common'
|
||||
|
||||
project('sec-server-win-auth') {
|
||||
description = 'Security Server Windows Auth Sample'
|
||||
}
|
||||
|
||||
project('sec-server-client-auth') {
|
||||
description = 'Security Server Side Auth Sample'
|
||||
}
|
||||
|
||||
project('sec-server-spnego-form-auth') {
|
||||
description = 'Security Server Spnego and Form Auth Sample'
|
||||
}
|
||||
|
||||
project('sec-server-spnego-form-auth-xml') {
|
||||
description = 'Security Server Spnego and Form Auth Xml Sample'
|
||||
}
|
||||
|
||||
project('sec-client-rest-template') {
|
||||
description = 'Security Client RestTemplate Sample'
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
plugins {
|
||||
id 'org.springframework.security.kerberos.sample'
|
||||
id 'org.springframework.boot'
|
||||
id 'io.spring.dependency-management'
|
||||
}
|
||||
|
||||
description = 'Security Server Spnego and Form Auth Sample'
|
||||
|
||||
dependencies {
|
||||
management platform(project(":spring-security-kerberos-management"))
|
||||
implementation project(':spring-security-kerberos-core')
|
||||
implementation project(':spring-security-kerberos-web')
|
||||
implementation 'org.springframework.security:spring-security-config'
|
||||
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
testImplementation 'org.springframework:spring-test'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter'
|
||||
testImplementation 'org.assertj:assertj-core'
|
||||
}
|
||||
@@ -1,16 +1,27 @@
|
||||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package demo.app;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class)
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package demo.app;
|
||||
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
public class DummyUserDetailsService implements UserDetailsService {
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return new User(username, "{noop}notUsed", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER"));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,26 @@
|
||||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package demo.app;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class MvcConfig extends WebMvcConfigurerAdapter {
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
@@ -14,5 +29,4 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
|
||||
registry.addViewController("/hello").setViewName("hello");
|
||||
registry.addViewController("/login").setViewName("login");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package demo.app;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -5,23 +20,20 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
||||
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
||||
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
|
||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||
|
||||
import demo.DummyUserDetailsService;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvcSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig {
|
||||
|
||||
@Value("${app.service-principal}")
|
||||
private String servicePrincipal;
|
||||
@@ -29,33 +41,30 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Value("${app.keytab-location}")
|
||||
private String keytabLocation;
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
|
||||
http
|
||||
.authorizeHttpRequests((authz) -> authz
|
||||
.requestMatchers("/", "/home").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(spnegoEntryPoint())
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login").permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll()
|
||||
.and()
|
||||
.addFilterBefore(
|
||||
spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
|
||||
BasicAuthenticationFilter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth
|
||||
.authenticationProvider(kerberosAuthenticationProvider())
|
||||
.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
}
|
||||
.authenticationProvider(kerberosServiceAuthenticationProvider())
|
||||
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManager),
|
||||
BasicAuthenticationFilter.class)
|
||||
;
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KerberosAuthenticationProvider kerberosAuthenticationProvider() {
|
||||
@@ -72,7 +81,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
return new SpnegoEntryPoint("/login");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
|
||||
AuthenticationManager authenticationManager) {
|
||||
SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
|
||||
@@ -101,5 +109,4 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
public DummyUserDetailsService dummyUserDetailsService() {
|
||||
return new DummyUserDetailsService();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
server:
|
||||
port: 8080
|
||||
app:
|
||||
service-principal: HTTP/neo.example.org@EXAMPLE.ORG
|
||||
service-principal: HTTP/cypher.localdomain@KERBOS.ORG
|
||||
keytab-location: /tmp/tomcat.keytab
|
||||
logging:
|
||||
level:
|
||||
root: debug
|
||||
@@ -1,10 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
|
||||
<head>
|
||||
<title>Spring Security Kerberos Example</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 th:inline="text">Hello [[${#httpServletRequest.remoteUser}]]!</h1>
|
||||
<div th:text="${#authentication}"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beansProjectDescription>
|
||||
<version>1</version>
|
||||
<pluginVersion><![CDATA[3.6.4.201503051146-RELEASE]]></pluginVersion>
|
||||
<configSuffixes>
|
||||
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||
</configSuffixes>
|
||||
<enableImports><![CDATA[false]]></enableImports>
|
||||
<configs>
|
||||
</configs>
|
||||
<autoconfigs>
|
||||
</autoconfigs>
|
||||
<configSets>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
||||
@@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
id 'org.springframework.security.kerberos.module'
|
||||
}
|
||||
|
||||
description = 'Spring Security Kerberos Web'
|
||||
|
||||
dependencies {
|
||||
management platform(project(":spring-security-kerberos-management"))
|
||||
implementation project(':spring-security-kerberos-core')
|
||||
api('org.springframework.security:spring-security-web')
|
||||
api('jakarta.servlet:jakarta.servlet-api')
|
||||
testImplementation 'org.springframework:spring-test'
|
||||
testImplementation 'org.springframework.security:spring-security-config'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter'
|
||||
testImplementation 'org.assertj:assertj-core'
|
||||
}
|
||||
@@ -17,9 +17,9 @@ package org.springframework.security.kerberos.web.authentication;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.kerberos.authentication.KerberosServiceRequestToken;
|
||||
|
||||
@@ -17,12 +17,12 @@ package org.springframework.security.kerberos.web.authentication;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.authentication.AuthenticationDetailsSource;
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.springframework.security.web.util.UrlUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,35 +19,35 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
// import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
// import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||
|
||||
//tag::snippetA[]
|
||||
@Configuration
|
||||
@EnableWebMvcSecurity
|
||||
public class AuthProviderConfig extends WebSecurityConfigurerAdapter {
|
||||
// @EnableWebMvcSecurity
|
||||
public class AuthProviderConfig /*extends WebSecurityConfigurerAdapter*/ {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login").permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll();
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http
|
||||
// .authorizeRequests()
|
||||
// .antMatchers("/", "/home").permitAll()
|
||||
// .anyRequest().authenticated()
|
||||
// .and()
|
||||
// .formLogin()
|
||||
// .loginPage("/login").permitAll()
|
||||
// .and()
|
||||
// .logout()
|
||||
// .permitAll();
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth
|
||||
.authenticationProvider(kerberosAuthenticationProvider());
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
// auth
|
||||
// .authenticationProvider(kerberosAuthenticationProvider());
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public KerberosAuthenticationProvider kerberosAuthenticationProvider() {
|
||||
|
||||
@@ -13,12 +13,13 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.docs;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(locations= {"AuthProviderConfig.xml"})
|
||||
public class AuthProviderConfigTest {
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
// import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
// import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
|
||||
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
||||
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||
@@ -33,37 +33,37 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
|
||||
|
||||
//tag::snippetA[]
|
||||
@Configuration
|
||||
@EnableWebMvcSecurity
|
||||
public class SpnegoConfig extends WebSecurityConfigurerAdapter {
|
||||
// @EnableWebMvcSecurity
|
||||
public class SpnegoConfig /*extends WebSecurityConfigurerAdapter*/ {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(spnegoEntryPoint())
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login").permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll()
|
||||
.and()
|
||||
.addFilterBefore(
|
||||
spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
|
||||
BasicAuthenticationFilter.class);
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http
|
||||
// .exceptionHandling()
|
||||
// .authenticationEntryPoint(spnegoEntryPoint())
|
||||
// .and()
|
||||
// .authorizeRequests()
|
||||
// .antMatchers("/", "/home").permitAll()
|
||||
// .anyRequest().authenticated()
|
||||
// .and()
|
||||
// .formLogin()
|
||||
// .loginPage("/login").permitAll()
|
||||
// .and()
|
||||
// .logout()
|
||||
// .permitAll()
|
||||
// .and()
|
||||
// .addFilterBefore(
|
||||
// spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
|
||||
// BasicAuthenticationFilter.class);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth)
|
||||
throws Exception {
|
||||
auth
|
||||
.authenticationProvider(kerberosAuthenticationProvider())
|
||||
.authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
}
|
||||
// @Override
|
||||
// protected void configure(AuthenticationManagerBuilder auth)
|
||||
// throws Exception {
|
||||
// auth
|
||||
// .authenticationProvider(kerberosAuthenticationProvider())
|
||||
// .authenticationProvider(kerberosServiceAuthenticationProvider());
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public KerberosAuthenticationProvider kerberosAuthenticationProvider() {
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.web;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -25,16 +22,17 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
@@ -50,6 +48,11 @@ import org.springframework.security.web.authentication.AuthenticationFailureHand
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
|
||||
|
||||
/**
|
||||
* Test class for {@link SpnegoAuthenticationProcessingFilter}
|
||||
*
|
||||
@@ -96,7 +99,7 @@ public class SpnegoAuthenticationProcessingFilterTest {
|
||||
|
||||
private static final BadCredentialsException BCE = new BadCredentialsException("");
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() throws Exception {
|
||||
// mocking
|
||||
authenticationManager = mock(AuthenticationManager.class);
|
||||
@@ -266,7 +269,7 @@ public class SpnegoAuthenticationProcessingFilterTest {
|
||||
filter.setFailureHandler(failureHandler);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@@ -15,15 +15,19 @@
|
||||
*/
|
||||
package org.springframework.security.kerberos.web;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Test class for {@link SpnegoEntryPoint}
|
||||
@@ -75,9 +79,11 @@ public class SpnegoEntryPointTest {
|
||||
verify(requestDispatcher).forward(request, response);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testEntryPointForwardAbsolute() throws Exception {
|
||||
new SpnegoEntryPoint("http://test/login");
|
||||
assertThatThrownBy(() -> {
|
||||
new SpnegoEntryPoint("http://test/login");
|
||||
}).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user