当前位置: 首页>>代码示例>>Java>>正文


Java BasicUserPrincipal类代码示例

本文整理汇总了Java中org.apache.http.auth.BasicUserPrincipal的典型用法代码示例。如果您正苦于以下问题:Java BasicUserPrincipal类的具体用法?Java BasicUserPrincipal怎么用?Java BasicUserPrincipal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BasicUserPrincipal类属于org.apache.http.auth包,在下文中一共展示了BasicUserPrincipal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testLoginWrongRealmForLoginModule

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Test
public void testLoginWrongRealmForLoginModule() throws Exception {
	Principal principal = new BasicUserPrincipal("foo");
	PasswordCredential cred = new PasswordCredential("foo",
			"bar".toCharArray(), "dummyJdbcRealm");
	Subject subject = new Subject(true, new HashSet<>(
			Arrays.asList(principal)), new HashSet<>(), new HashSet<>(
			Arrays.asList(cred)));
	JDBCLoginModule module = new JDBCLoginModule();
	module.initialize(subject, callbackHandler, new HashMap<>(),
			new HashMap<>());

	expectedException.expect(LoginException.class);
	expectedException.expectMessage("JDBCLoginModule requires JDBCRealm");
	module.login();
}
 
开发者ID:scheuchzer,项目名称:glassfish-jdbc-realm-salted,代码行数:17,代码来源:JDBCLoginModuleTest.java

示例2: testGetIdWithUserIdURI

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Test
public void testGetIdWithUserIdURI() throws RepositoryException {

    // test with an absolute user uri
    final String userUri = TEST_USER_AGENT_BASE_URI + FEDORA_USER;
    when(request.getRemoteUser()).thenReturn(userUri);
    when(request.getUserPrincipal()).thenReturn(new BasicUserPrincipal(userUri));
    when(request.isUserInRole(eq("admin"))).thenReturn(true);

    ServletCredentials credentials = new ServletCredentials(request);
    FedoraSession session = repo.login(credentials);

    assertEquals("User agent URI invalid.", URI.create(userUri), session.getUserURI());

    // test with an Opaque user uri
    final String opaqueUserUri = "user:info:" + FEDORA_USER;
    when(request.getRemoteUser()).thenReturn(opaqueUserUri);
    when(request.getUserPrincipal()).thenReturn(new BasicUserPrincipal(opaqueUserUri));
    when(request.isUserInRole(eq("admin"))).thenReturn(true);

    credentials = new ServletCredentials(request);
    session = repo.login(credentials);

    assertEquals("User agent URI invalid.", URI.create(opaqueUserUri), session.getUserURI());
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:26,代码来源:FedoraSessionImplIT.java

示例3: testPermissiveFAD

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Test
public void testPermissiveFAD() throws RepositoryException {
    when(request.getRemoteUser()).thenReturn("fred");
    when(request.getUserPrincipal()).thenReturn(
            new BasicUserPrincipal("fred"));
    when(
            request.isUserInRole(Mockito
                    .eq(ServletContainerAuthenticationProvider.FEDORA_USER_ROLE)))
            .thenReturn(true);
    Mockito.reset(fad);
    when(fad.hasPermission(any(Session.class), any(Path.class), any(String[].class))).thenReturn(true);

    final ServletCredentials credentials =
            new ServletCredentials(request);
    final FedoraSession session = repo.login(credentials);
    final Session jcrSession = getJcrSession(session);
    final Privilege[] rootPrivs = jcrSession.getAccessControlManager().getPrivileges("/");
    for (final Privilege p : rootPrivs) {
        logger.debug("got priv: " + p.getName());
    }
    final ContainerService os = new ContainerServiceImpl();
    os.findOrCreate(session, "/myobject");
    verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:25,代码来源:ModeShapeHonorsFADResponseIT.java

示例4: testRestrictiveFAD

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Test(expected = AccessDeniedException.class)
public void testRestrictiveFAD() throws Throwable {
    when(request.getRemoteUser()).thenReturn("fred");
    when(request.getUserPrincipal()).thenReturn(
            new BasicUserPrincipal("fred"));
    when(
            request.isUserInRole(Mockito
                    .eq(ServletContainerAuthenticationProvider.FEDORA_USER_ROLE)))
            .thenReturn(true);

    // first permission check is for login
    Mockito.reset(fad);
    when(fad.hasPermission(any(Session.class), any(Path.class), any(String[].class))).thenReturn(true, false);

    final ServletCredentials credentials = new ServletCredentials(request);
    final FedoraSession session = repo.login(credentials);
    final ContainerService os = new ContainerServiceImpl();
    try {
        os.findOrCreate(session, "/myobject");
    } catch (final RepositoryRuntimeException e) {
        throw e.getCause();
    }
    verify(fad, times(5)).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:25,代码来源:ModeShapeHonorsFADResponseIT.java

示例5: testEmptyPrincipalProvider

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Test
public void testEmptyPrincipalProvider() throws RepositoryException {
    when(request.getRemoteUser()).thenReturn("fred");
    when(request.getUserPrincipal()).thenReturn(
            new BasicUserPrincipal("fred"));
    when(
            request.isUserInRole(Mockito
                    .eq(ServletContainerAuthenticationProvider.FEDORA_USER_ROLE)))
            .thenReturn(true);
    Mockito.reset(fad);
    when(fad.hasPermission(any(Session.class), any(Path.class), any(String[].class))).thenReturn(true);

    final ServletCredentials credentials =
            new ServletCredentials(request);
    final FedoraSession session = repo.login(credentials);
    final Session jcrSession = getJcrSession(session);
    final Privilege[] rootPrivs = jcrSession.getAccessControlManager().getPrivileges("/");
    for (final Privilege p : rootPrivs) {
        logger.debug("got priv: " + p.getName());
    }
    final ContainerService os = new ContainerServiceImpl();
    os.findOrCreate(session, "/myobject");
    verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:25,代码来源:HttpHeaderPrincipalProviderIT.java

示例6: testEmptyPrincipalProvider

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Test
public void testEmptyPrincipalProvider() throws RepositoryException {
    when(request.getRemoteUser()).thenReturn("fred");
    when(request.getUserPrincipal()).thenReturn(
            new BasicUserPrincipal("fred"));
    when(
            request.isUserInRole(Mockito
                    .eq(ServletContainerAuthenticationProvider.FEDORA_USER_ROLE)))
            .thenReturn(true);
    Mockito.reset(fad);
    when(fad.hasPermission(any(Session.class), any(Path.class), any(String[].class))).thenReturn(true);

    final ServletCredentials credentials =
            new ServletCredentials(request);
    final FedoraSession session = repo.login(credentials);
    final Session jcrSession = getJcrSession(session);
    final Privilege[] rootPrivs =
            jcrSession.getAccessControlManager().getPrivileges("/");
    for (final Privilege p : rootPrivs) {
        logger.debug("got priv: " + p.getName());
    }
    final ContainerService os = new ContainerServiceImpl();
    os.findOrCreate(session, "/myobject");
    verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
 
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:26,代码来源:ContainerRolesPrincipalProviderIT.java

示例7: DiadocCredentials

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
/**
 * The constructor with the Diadoc API client ID and auth token arguments.
 *
 * @param apiClientId the Diadoc API client ID
 * @param authToken the Diadoc authorization token
 */
public DiadocCredentials(String apiClientId, String authToken) {
    super();
    if (apiClientId == null) {
        throw new IllegalArgumentException("ApiClientId may not be null");
    }
    this.principal = new BasicUserPrincipal(apiClientId);
    this.authToken = authToken;
}
 
开发者ID:diadoc,项目名称:diadocsdk-java,代码行数:15,代码来源:DiadocCredentials.java

示例8: returnsFailureIfCannotFindUser

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@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)));
}
 
开发者ID:celestial-winter,项目名称:vics,代码行数:11,代码来源:SessionServiceTest.java

示例9: setup

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Before
public void setup() {
    AddressSpace addressSpace = mock(AddressSpace.class);
    AddressSpaceApi addressSpaceApi = mock(AddressSpaceApi.class);
    addressApi = mock(AddressApi.class);
    securityContext = mock(SecurityContext.class);
    when(securityContext.getUserPrincipal()).thenReturn(new BasicUserPrincipal("me"));
    when(securityContext.isUserInRole(any())).thenReturn(true);
    when(addressSpaceApi.getAddressSpaceWithName(eq("test"))).thenReturn(Optional.of(addressSpace));
    when(addressSpaceApi.withAddressSpace(eq(addressSpace))).thenReturn(addressApi);
    helper = new AddressApiHelper(addressSpaceApi);
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:13,代码来源:AddressApiHelperTest.java

示例10: setup

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Before
public void setup() {
    addressSpaceApi = new TestAddressSpaceApi();
    addressSpaceService = new HttpAddressSpaceService(addressSpaceApi, "controller");
    securityContext = mock(SecurityContext.class);
    when(securityContext.getUserPrincipal()).thenReturn(new BasicUserPrincipal("me"));
    when(securityContext.isUserInRole(any())).thenReturn(true);
    when(securityContext.getAuthenticationScheme()).thenReturn("unknown");
    a1 = new AddressSpace.Builder()
            .setName("a1")
            .setNamespace("myspace")
            .setType(new StandardAddressSpaceType())
            .setEndpointList(Arrays.asList(
                    new Endpoint.Builder()
                        .setName("messaging")
                        .setService("messaging")
                        .setHost("messaging.example.com")
                    .build(),
                    new Endpoint.Builder()
                        .setName("mqtt")
                        .setService("mqtt")
                        .setHost("mqtt.example.com")
                    .build()))
            .build();

    a2 = new AddressSpace.Builder()
            .setName("a2")
            .setType(new StandardAddressSpaceType())
            .setNamespace("othernamespace")
            .build();
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:32,代码来源:HttpAddressSpaceServiceTest.java

示例11: setup

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Before
public void setup() {
    addressSpaceApi = new TestAddressSpaceApi();
    this.addressService = new HttpAddressService(addressSpaceApi);

    AddressSpace addressSpace = new AddressSpace.Builder()
            .setName("myspace")
            .setType(new StandardAddressSpaceType())
            .build();

    securityContext = mock(SecurityContext.class);
    when(securityContext.getUserPrincipal()).thenReturn(new BasicUserPrincipal("me"));
    when(securityContext.isUserInRole(any())).thenReturn(true);

    addressSpaceApi.createAddressSpace(addressSpace);
    addressApi = (TestAddressApi) addressSpaceApi.withAddressSpace(addressSpace);
    q1 = new Address.Builder()
            .setName("q1")
            .setType(StandardType.QUEUE)
            .build();
    a1 = new Address.Builder()
            .setName("a1")
            .setType(StandardType.ANYCAST)
            .build();
    addressApi.createAddress(q1);
    addressApi.createAddress(a1);
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:28,代码来源:HttpAddressServiceTest.java

示例12: getSecurityContext

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
protected SecurityContext getSecurityContext() {
    SecurityContext securityContext = mock(SecurityContext.class);
    when(securityContext.isUserInRole(any())).thenReturn(true);
    when(securityContext.isSecure()).thenReturn(true);
    when(securityContext.getUserPrincipal()).thenReturn(new BasicUserPrincipal("myuser"));
    return securityContext;
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:8,代码来源:OSBTestBase.java

示例13: getUserPrincipal

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Override
public Principal getUserPrincipal() {
	if (principal == null) {
		getCredentials();
		if (principal == null) {
			return new BasicUserPrincipal("");
		}
	}
	return principal;
}
 
开发者ID:mondo-project,项目名称:mondo-integration,代码行数:11,代码来源:LazyCredentials.java

示例14: getCredentials

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
protected void getCredentials() {
	try {
		// Search within the registered servers by prefix
		final List<Server> servers = Activator.getDefault().getServerStore().readAllServers();
		String storeKey = url;
		for (Server server : servers) {
			if (url.startsWith(server.getBaseURL())) {
				storeKey = server.getBaseURL();
				break;
			}
		}

		CredentialsStore.Credentials creds = Activator.getDefault().getCredentialsStore().get(storeKey);
		if (creds == null && PlatformUI.isWorkbenchRunning()) {
			final Display display = PlatformUI.getWorkbench().getDisplay();
			final CredentialsPrompter prompter = new CredentialsPrompter(display);
			display.syncExec(prompter);
			creds = prompter.getCredentials();
		}
		if (creds != null) {
			principal = new BasicUserPrincipal(creds.getUsername());
			password = creds.getPassword();
		}
	} catch (Exception e) {
		Activator.getDefault().logError(e);
	}
}
 
开发者ID:mondo-project,项目名称:mondo-integration,代码行数:28,代码来源:LazyCredentials.java

示例15: authenticate

import org.apache.http.auth.BasicUserPrincipal; //导入依赖的package包/类
@Override
public Optional<BasicUserPrincipal> authenticate(BasicCredentials credentials) throws AuthenticationException {
	String loginUserName = credentials.getUsername();
	String loginPassword = credentials.getPassword();
	String htUsersPass = readHtUsers().getPassword(loginUserName);
	if(negate(comparePasswords(loginPassword, htUsersPass))) {
		logger.info("Failed to login " + loginUserName);
		return Optional.empty();
	}
	return Optional.of(new BasicUserPrincipal(loginUserName));
}
 
开发者ID:rrauschenbach,项目名称:FeedExpander,代码行数:12,代码来源:HtUserAuthenticator.java


注:本文中的org.apache.http.auth.BasicUserPrincipal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。