use of java.security.Principal in project presto by prestodb.
the class LdapFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain nextFilter) throws IOException, ServletException {
// skip auth for http
if (!servletRequest.isSecure()) {
nextFilter.doFilter(servletRequest, servletResponse);
return;
}
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
try {
String header = request.getHeader(AUTHORIZATION);
Credentials credentials = getCredentials(header);
Principal principal = getPrincipal(credentials);
// ldap authentication ok, continue
nextFilter.doFilter(new HttpServletRequestWrapper(request) {
@Override
public Principal getUserPrincipal() {
return principal;
}
}, servletResponse);
} catch (AuthenticationException e) {
log.debug(e, "LDAP authentication failed");
processAuthenticationException(e, request, response);
}
}
use of java.security.Principal in project presto by prestodb.
the class SpnegoFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain nextFilter) throws IOException, ServletException {
// skip auth for http
if (!servletRequest.isSecure()) {
nextFilter.doFilter(servletRequest, servletResponse);
return;
}
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String header = request.getHeader(HttpHeaders.AUTHORIZATION);
boolean includeRealm = "true".equalsIgnoreCase(request.getHeader(INCLUDE_REALM_HEADER));
String requestSpnegoToken = null;
if (header != null) {
String[] parts = header.split("\\s+");
if (parts.length == 2 && parts[0].equals(NEGOTIATE_SCHEME)) {
try {
requestSpnegoToken = parts[1];
Optional<Result> authentication = authenticate(parts[1]);
if (authentication.isPresent()) {
authentication.get().getToken().ifPresent(token -> response.setHeader(HttpHeaders.WWW_AUTHENTICATE, formatAuthenticationHeader(includeRealm, Optional.ofNullable(token))));
nextFilter.doFilter(new HttpServletRequestWrapper(request) {
@Override
public Principal getUserPrincipal() {
return authentication.get().getPrincipal();
}
}, servletResponse);
return;
}
} catch (GSSException | RuntimeException e) {
throw new RuntimeException("Authentication error for token: " + parts[1], e);
}
}
}
sendChallenge(request, response, includeRealm, requestSpnegoToken);
}
use of java.security.Principal in project robovm by robovm.
the class JarUtils method createChain.
private static X509Certificate[] createChain(X509Certificate signer, X509Certificate[] candidates) {
LinkedList chain = new LinkedList();
chain.add(0, signer);
// Signer is self-signed
if (signer.getSubjectDN().equals(signer.getIssuerDN())) {
return (X509Certificate[]) chain.toArray(new X509Certificate[1]);
}
Principal issuer = signer.getIssuerDN();
X509Certificate issuerCert;
int count = 1;
while (true) {
issuerCert = findCert(issuer, candidates);
if (issuerCert == null) {
break;
}
chain.add(issuerCert);
count++;
if (issuerCert.getSubjectDN().equals(issuerCert.getIssuerDN())) {
break;
}
issuer = issuerCert.getIssuerDN();
}
return (X509Certificate[]) chain.toArray(new X509Certificate[count]);
}
use of java.security.Principal in project robovm by robovm.
the class AttributeCertificateIssuer method getPrincipals.
/**
* Return any principal objects inside the attribute certificate issuer
* object.
*
* @return an array of Principal objects (usually X500Principal)
*/
public Principal[] getPrincipals() {
Object[] p = this.getNames();
List l = new ArrayList();
for (int i = 0; i != p.length; i++) {
if (p[i] instanceof Principal) {
l.add(p[i]);
}
}
return (Principal[]) l.toArray(new Principal[l.size()]);
}
use of java.security.Principal in project robovm by robovm.
the class SSLSessionTest method test_getPeerPrincipal.
/**
* javax.net.ssl.SSLSession#getPeerPrincipal()
*/
public void test_getPeerPrincipal() throws Exception {
Principal p1 = clientSession.getPeerPrincipal();
KeyStore store = server.getStore();
X509Certificate cert = (X509Certificate) store.getCertificate("mykey");
Principal p2 = cert.getSubjectX500Principal();
assertEquals(p1, p2);
}
Aggregations