Search in sources :

Example 56 with Principal

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) Principal(java.security.Principal)

Example 57 with Principal

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) GSSException(org.ietf.jgss.GSSException) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Principal(java.security.Principal)

Example 58 with Principal

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]);
}
Also used : LinkedList(java.util.LinkedList) X509Certificate(java.security.cert.X509Certificate) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal)

Example 59 with Principal

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()]);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) X509Principal(org.bouncycastle.jce.X509Principal) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal)

Example 60 with Principal

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);
}
Also used : KeyStore(java.security.KeyStore) Principal(java.security.Principal) X509Certificate(java.security.cert.X509Certificate)

Aggregations

Principal (java.security.Principal)931 Test (org.junit.Test)243 Subject (javax.security.auth.Subject)114 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)114 HashSet (java.util.HashSet)89 User (org.apache.jackrabbit.api.security.user.User)75 Group (org.apache.jackrabbit.api.security.user.Group)74 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)58 Privilege (javax.jcr.security.Privilege)57 RepositoryException (javax.jcr.RepositoryException)51 IOException (java.io.IOException)50 ArrayList (java.util.ArrayList)48 HttpServletRequest (javax.servlet.http.HttpServletRequest)47 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)45 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)43 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)42 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)40 HashMap (java.util.HashMap)39 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)39 X500Principal (javax.security.auth.x500.X500Principal)38