-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24877 from dmatej/jmactestfix
Fixed JmacHttpsTest - certificate authentication
- Loading branch information
Showing
25 changed files
with
655 additions
and
1,040 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
.../main/java/com/sun/enterprise/deployment/node/runtime/common/DescriptorPrincipalName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package com.sun.enterprise.deployment.node.runtime.common; | ||
|
||
import java.io.Serializable; | ||
import java.security.Principal; | ||
import java.util.Objects; | ||
|
||
import org.glassfish.security.common.UserPrincipal; | ||
|
||
/** | ||
* {@link Principal} loaded from XML descriptor. | ||
* When the equals method is used, it compares just principal names and that the other object | ||
* is an {@link Principal} instance too. | ||
*/ | ||
// Must be UserPrincipal, because RoleMapper.internalAssignRole knows just that and Group. | ||
public class DescriptorPrincipalName implements UserPrincipal, Serializable { | ||
|
||
private static final long serialVersionUID = -640182254691955451L; | ||
|
||
private final String name; | ||
|
||
/** | ||
* @param name must not be null. | ||
*/ | ||
public DescriptorPrincipalName(String name) { | ||
this.name = Objects.requireNonNull(name, "XML principal-name element must not be null."); | ||
} | ||
|
||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
|
||
|
||
/** | ||
* We match user principals just by name. | ||
* This is used in Jakarta Security to resolve authorisation. | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof Principal) { | ||
Principal other = (Principal) o; | ||
return getName().equals(other.getName()); | ||
} | ||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[" + getName() + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/TestUtilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.itest.tools; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Tools useful just for tests, so they don't belong to any application code. | ||
*/ | ||
public final class TestUtilities { | ||
|
||
private TestUtilities() { | ||
// hidden | ||
} | ||
|
||
|
||
/** | ||
* Deletes files if they exist. | ||
* If it existed but was not possible to delete the file, uses NIO to delete it again - NIO | ||
* throws an exception in such case. | ||
* <p> | ||
* Attempts to delete all files and throws the {@link IOException} if any of them was not | ||
* possible to delete. Therefore this method should be the last call in your cleanup method (ie. | ||
* AfterEach or AfterAll) | ||
* | ||
* @param files files to delete | ||
* @throws IOException some files were not deleted. | ||
*/ | ||
public static void delete(final File... files) throws IOException { | ||
final Set<File> failed = new HashSet<>(files.length); | ||
for (File file : files) { | ||
if (file == null || !file.exists() || file.delete()) { | ||
continue; | ||
} | ||
failed.add(file); | ||
} | ||
if (failed.isEmpty()) { | ||
return; | ||
} | ||
final IOException failures = new IOException("Could not delete files: " + failed); | ||
for (File file : failed) { | ||
try { | ||
Files.delete(file.toPath()); | ||
} catch (IOException e) { | ||
failures.addSuppressed(e); | ||
} | ||
} | ||
throw failures; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.