org.apache.http.auth.BasicUserPrincipal Java Examples
The following examples show how to use
org.apache.http.auth.BasicUserPrincipal.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecureClusterTest.java From knox with Apache License 2.0 | 6 votes |
private CloseableHttpClient getHttpClient() { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new Credentials() { @Override public Principal getUserPrincipal() { return new BasicUserPrincipal("guest"); } @Override public String getPassword() { return "guest-password"; } }); return HttpClients.custom() .setDefaultCredentialsProvider(credentialsProvider) .build(); }
Example #2
Source File: WebRequestTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void credentialsAndPathWithDots() throws Exception { final URL url = new URL("http://john.smith:secret@localhost/../foo.html"); final WebRequest request = new WebRequest(url); final Credentials credentials = request.getUrlCredentials(); assertNotNull("Credentials object is null", credentials); assertEquals(new BasicUserPrincipal("john.smith"), credentials.getUserPrincipal()); assertEquals("secret", credentials.getPassword()); }
Example #3
Source File: SessionServiceTest.java From vics with MIT License | 5 votes |
@Test public void returnsFailureIfCannotFindUser() throws Exception { User amy = user().withFirstName("Amy").build(); given(userRepository.findOne(amy.getId())).willReturn(amy); Principal p = new BasicUserPrincipal("name"); Try<User> userTry = underTest.extractUserFromPrincipal(p); assertThat(userTry, isFailure(instanceOf(UserSessionFailure.class))); }
Example #4
Source File: MockAuthenticationPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void forward(String user, HttpServletRequest req, ServletResponse rsp, FilterChain chain) throws IOException, ServletException { if(user != null) { final Principal p = new BasicUserPrincipal(user); req = wrapWithPrincipal(req, p); } chain.doFilter(req, rsp); }
Example #5
Source File: TestExternalRoleRuleBasedAuthorizationPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override AuthorizationContext getMockContext(Map<String, Object> values) { return new MockAuthorizationContext(values) { @Override public Principal getUserPrincipal() { String userPrincipal = (String) values.get("userPrincipal"); return userPrincipal == null ? null : principals.get(userPrincipal) != null ? principals.get(userPrincipal) : new BasicUserPrincipal(userPrincipal); } }; }
Example #6
Source File: BaseTestRuleBasedAuthorizationPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
AuthorizationContext getMockContext(Map<String, Object> values) { return new MockAuthorizationContext(values) { @Override public Principal getUserPrincipal() { Object userPrincipal = values.get("userPrincipal"); return userPrincipal == null ? null : new BasicUserPrincipal(String.valueOf(userPrincipal)); } }; }
Example #7
Source File: ScipioUserLoginAuthPlugin.java From scipio-erp with Apache License 2.0 | 5 votes |
private HttpServletRequest makeAuthRequestWrapper(HttpServletRequest request, UserLoginInfo userLoginInfo) { // see BasicAuthPlugin implementation for reference of why this is here return new HttpServletRequestWrapper(request) { @Override public Principal getUserPrincipal() { return new BasicUserPrincipal(userLoginInfo.getSolrUsername()); } }; }
Example #8
Source File: WebRequestTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void credentialsEmptyURL() throws Exception { final URL url = new URL("http://:@localhost/"); final WebRequest request = new WebRequest(url); final Credentials credentials = request.getUrlCredentials(); assertEquals(new BasicUserPrincipal(""), credentials.getUserPrincipal()); assertEquals("", credentials.getPassword()); }
Example #9
Source File: WebRequestTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void credentialsOnlyPasswordInURL() throws Exception { final URL url = new URL("http://:secret@localhost/"); final WebRequest request = new WebRequest(url); final Credentials credentials = request.getUrlCredentials(); assertEquals(new BasicUserPrincipal(""), credentials.getUserPrincipal()); assertEquals("secret", credentials.getPassword()); }
Example #10
Source File: WebRequestTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void credentialsOnlyUsernameInURL() throws Exception { final URL url = new URL("http://john.smith@localhost/"); final WebRequest request = new WebRequest(url); final Credentials credentials = request.getUrlCredentials(); assertEquals(new BasicUserPrincipal("john.smith"), credentials.getUserPrincipal()); assertEquals("", credentials.getPassword()); }
Example #11
Source File: WebRequestTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void credentialsAndInternationalizedDomainName() throws Exception { final URL url = new URL("http://john.smith:secret@löcälhöst/"); final WebRequest request = new WebRequest(url); final Credentials credentials = request.getUrlCredentials(); assertNotNull("Credentials object is null", credentials); assertEquals(new BasicUserPrincipal("john.smith"), credentials.getUserPrincipal()); assertEquals("secret", credentials.getPassword()); }
Example #12
Source File: WebRequestTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void credentialsAndEmptyPath() throws Exception { final URL url = new URL("http://john.smith:secret@localhost"); final WebRequest request = new WebRequest(url); final Credentials credentials = request.getUrlCredentials(); assertNotNull("Credentials object is null", credentials); assertEquals(new BasicUserPrincipal("john.smith"), credentials.getUserPrincipal()); assertEquals("secret", credentials.getPassword()); }
Example #13
Source File: CertificateStoreX509KeyManagerTest.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Test public void testChooseClientAliasNotfound() throws Exception { final X509KeyManager m = new CertificateStoreX509KeyManager(new DisabledCertificateIdentityCallback(), new Host(new TestProtocol()), new DisabledCertificateStore()).init(); assertNull(m.chooseClientAlias(new String[]{"RSA", "DSA"}, new Principal[]{new BasicUserPrincipal("user")}, new Socket("test.cyberduck.ch", 443))); }
Example #14
Source File: PKIAuthenticationPlugin.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressForbidden(reason = "Needs currentTimeMillis to compare against time in header") @Override public boolean doAuthenticate(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { String requestURI = request.getRequestURI(); if (requestURI.endsWith(PublicKeyHandler.PATH)) { numPassThrough.inc(); filterChain.doFilter(request, response); return true; } long receivedTime = System.currentTimeMillis(); String header = request.getHeader(HEADER); if (header == null) { //this must not happen log.error("No SolrAuth header present"); numMissingCredentials.inc(); filterChain.doFilter(request, response); return true; } List<String> authInfo = StrUtils.splitWS(header, false); if (authInfo.size() < 2) { log.error("Invalid SolrAuth Header {}", header); numErrors.mark(); filterChain.doFilter(request, response); return true; } String nodeName = authInfo.get(0); String cipher = authInfo.get(1); PKIHeaderData decipher = decipherHeader(nodeName, cipher); if (decipher == null) { log.error("Could not decipher a header {} . No principal set", header); numMissingCredentials.inc(); filterChain.doFilter(request, response); return true; } if ((receivedTime - decipher.timestamp) > MAX_VALIDITY) { log.error("Invalid key request timestamp: {} , received timestamp: {} , TTL: {}", decipher.timestamp, receivedTime, MAX_VALIDITY); numErrors.mark(); filterChain.doFilter(request, response); return true; } final Principal principal = "$".equals(decipher.userName) ? SU : new BasicUserPrincipal(decipher.userName); numAuthenticated.inc(); filterChain.doFilter(wrapWithPrincipal(request, principal), response); return true; }
Example #15
Source File: ServiceRegistryFunctionsTest.java From knox with Apache License 2.0 | 4 votes |
SetupFilter( String userName ) { subject = new Subject(); subject.getPrincipals().add( new BasicUserPrincipal( userName ) ); }
Example #16
Source File: UsernameFunctionProcessorTest.java From knox with Apache License 2.0 | 4 votes |
SetupFilter( String userName ) { subject = new Subject(); subject.getPrincipals().add( new BasicUserPrincipal( userName ) ); }
Example #17
Source File: FrontendFunctionProcessorTest.java From knox with Apache License 2.0 | 4 votes |
SetupFilter( String userName ) { subject = new Subject(); subject.getPrincipals().add( new BasicUserPrincipal( userName ) ); }