本文整理汇总了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();
}
示例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());
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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;
}
示例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)));
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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));
}