io.atlassian.util.adapter.jakarta.servlet.JakartaServletSecurityElementAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jakarta-adapters Show documentation
Show all versions of jakarta-adapters Show documentation
A collection of classes for adapting Servlet API 4.0 objects to Servlet API 5.0 and vice versa.
package io.atlassian.util.adapter.jakarta.servlet;
import io.atlassian.util.adapter.javax.servlet.JavaXServletSecurityElementAdapter;
import jakarta.servlet.HttpMethodConstraintElement;
import jakarta.servlet.ServletSecurityElement;
import jakarta.servlet.annotation.ServletSecurity;
import java.util.Collection;
import static io.atlassian.util.adapter.util.WrapperUtil.applyIfNonNull;
import static io.atlassian.util.adapter.util.WrapperUtil.transformIfNonNull;
import static java.util.Objects.requireNonNull;
public class JakartaServletSecurityElementAdapter extends ServletSecurityElement {
private final javax.servlet.ServletSecurityElement delegate;
public static ServletSecurityElement from(javax.servlet.ServletSecurityElement delegate) {
if (delegate instanceof JavaXServletSecurityElementAdapter castDelegate) {
return castDelegate.getDelegate();
}
return applyIfNonNull(delegate, JakartaServletSecurityElementAdapter::new);
}
JakartaServletSecurityElementAdapter(javax.servlet.ServletSecurityElement delegate) {
this.delegate = requireNonNull(delegate);
}
public javax.servlet.ServletSecurityElement getDelegate() {
return delegate;
}
@Override
public Collection getHttpMethodConstraints() {
return transformIfNonNull(delegate.getHttpMethodConstraints(), JakartaHttpMethodConstraintElementAdapter::from);
}
@Override
public Collection getMethodNames() {
return delegate.getMethodNames();
}
@Override
public ServletSecurity.EmptyRoleSemantic getEmptyRoleSemantic() {
return ServletSecurity.EmptyRoleSemantic.valueOf(delegate.getEmptyRoleSemantic().name());
}
@Override
public ServletSecurity.TransportGuarantee getTransportGuarantee() {
return ServletSecurity.TransportGuarantee.valueOf(delegate.getTransportGuarantee().name());
}
@Override
public String[] getRolesAllowed() {
return delegate.getRolesAllowed();
}
}