本文整理汇总了Java中org.apereo.cas.authentication.principal.DefaultPrincipalFactory类的典型用法代码示例。如果您正苦于以下问题:Java DefaultPrincipalFactory类的具体用法?Java DefaultPrincipalFactory怎么用?Java DefaultPrincipalFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPrincipalFactory类属于org.apereo.cas.authentication.principal包,在下文中一共展示了DefaultPrincipalFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyGetSimpleCredentials
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyGetSimpleCredentials() {
final String myNtlmUser = "DOMAIN\\Username";
final String myNtlmUserWithNoDomain = USERNAME;
final String myKerberosUser = "[email protected]";
final PrincipalFactory factory = new DefaultPrincipalFactory();
final JcifsSpnegoAuthenticationHandler authenticationHandler = new JcifsSpnegoAuthenticationHandler("", null, null, new MockJcifsAuthentication(true),
true, true);
assertEquals(factory.createPrincipal(myNtlmUser), authenticationHandler.getPrincipal(myNtlmUser, true));
assertEquals(factory.createPrincipal(myNtlmUserWithNoDomain), authenticationHandler.getPrincipal(myNtlmUserWithNoDomain, false));
assertEquals(factory.createPrincipal(myKerberosUser), authenticationHandler.getPrincipal(myKerberosUser, false));
final JcifsSpnegoAuthenticationHandler handlerNoDomain = new JcifsSpnegoAuthenticationHandler("", null, null, new MockJcifsAuthentication(true), false,
true);
assertEquals(factory.createPrincipal(USERNAME), handlerNoDomain.getPrincipal(myNtlmUser, true));
assertEquals(factory.createPrincipal(USERNAME), handlerNoDomain.getPrincipal(myNtlmUserWithNoDomain, true));
assertEquals(factory.createPrincipal(USERNAME), handlerNoDomain.getPrincipal(myKerberosUser, false));
}
示例2: verifyResponse
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyResponse() throws Exception {
final Map<String, Object> model = new HashMap<>();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(TEST_ATTRIBUTE, TEST_VALUE);
attributes.put("testEmptyCollection", Collections.emptyList());
attributes.put("testAttributeCollection", Arrays.asList("tac1", "tac2"));
final Principal principal = new DefaultPrincipalFactory().createPrincipal(PRINCIPAL_ID, attributes);
final Map<String, Object> authAttributes = new HashMap<>();
authAttributes.put(
SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD,
SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
authAttributes.put("testSamlAttribute", "value");
final Authentication primary = CoreAuthenticationTestUtils.getAuthentication(principal, authAttributes);
final Assertion assertion = new ImmutableAssertion(
primary, Collections.singletonList(primary),
CoreAuthenticationTestUtils.getService(), true);
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains(PRINCIPAL_ID));
assertTrue(written.contains(TEST_ATTRIBUTE));
assertTrue(written.contains(TEST_VALUE));
assertFalse(written.contains("testEmptyCollection"));
assertTrue(written.contains("testAttributeCollection"));
assertTrue(written.contains("tac1"));
assertTrue(written.contains("tac2"));
assertTrue(written.contains(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
assertTrue(written.contains("AuthenticationMethod"));
assertTrue(written.contains("AssertionID"));
}
示例3: verifyResponseWithNoAttributes
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyResponseWithNoAttributes() throws Exception {
final Map<String, Object> model = new HashMap<>();
final Principal principal = new DefaultPrincipalFactory().createPrincipal(PRINCIPAL_ID);
final Map<String, Object> authAttributes = new HashMap<>();
authAttributes.put(
SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD,
SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
authAttributes.put("testSamlAttribute", "value");
final Authentication primary = CoreAuthenticationTestUtils.getAuthentication(principal, authAttributes);
final Assertion assertion = new ImmutableAssertion(
primary, Collections.singletonList(primary),
CoreAuthenticationTestUtils.getService(), true);
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains(PRINCIPAL_ID));
assertTrue(written.contains(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
assertTrue(written.contains("AuthenticationMethod="));
}
示例4: verifyResponseWithoutAuthMethod
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyResponseWithoutAuthMethod() throws Exception {
final Map<String, Object> model = new HashMap<>();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(TEST_ATTRIBUTE, TEST_VALUE);
final Principal principal = new DefaultPrincipalFactory().createPrincipal(PRINCIPAL_ID, attributes);
final Map<String, Object> authnAttributes = new HashMap<>();
authnAttributes.put("authnAttribute1", "authnAttrbuteV1");
authnAttributes.put("authnAttribute2", "authnAttrbuteV2");
authnAttributes.put(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, Boolean.TRUE);
final Authentication primary = CoreAuthenticationTestUtils.getAuthentication(principal, authnAttributes);
final Assertion assertion = new ImmutableAssertion(
primary, Collections.singletonList(primary),
CoreAuthenticationTestUtils.getService(), true);
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains(PRINCIPAL_ID));
assertTrue(written.contains(TEST_ATTRIBUTE));
assertTrue(written.contains(TEST_VALUE));
assertTrue(written.contains("authnAttribute1"));
assertTrue(written.contains("authnAttribute2"));
assertTrue(written.contains(CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME));
assertTrue(written.contains("urn:oasis:names:tc:SAML:1.0:am:unspecified"));
}
示例5: verifyEncodeDecodeTGTImpl
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyEncodeDecodeTGTImpl() throws Exception {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final AuthenticationBuilder bldr = new DefaultAuthenticationBuilder(
new DefaultPrincipalFactory()
.createPrincipal("user", new HashMap<>(this.principalAttributes)));
bldr.setAttributes(new HashMap<>(this.principalAttributes));
bldr.setAuthenticationDate(ZonedDateTime.now());
bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
bldr.addFailure("error", AccountNotFoundException.class);
bldr.addSuccess("authn", new DefaultHandlerResult(
new AcceptUsersAuthenticationHandler(""),
new BasicCredentialMetaData(userPassCredential)));
final TicketGrantingTicket expectedTGT =
new TicketGrantingTicketImpl(TGT_ID,
RegisteredServiceTestUtils.getService(),
null, bldr.build(),
new NeverExpiresExpirationPolicy());
final ServiceTicket ticket = expectedTGT.grantServiceTicket(ST_ID,
RegisteredServiceTestUtils.getService(),
new NeverExpiresExpirationPolicy(), false, true);
CachedData result = transcoder.encode(expectedTGT);
final TicketGrantingTicket resultTicket = (TicketGrantingTicket) transcoder.decode(result);
assertEquals(expectedTGT, resultTicket);
result = transcoder.encode(ticket);
final ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
}
示例6: verifySuccess
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifySuccess() throws Exception {
final Principal principalWritten = new DefaultPrincipalFactory().createPrincipal("casuser");
final ObjectMapper mapper = new ObjectMapper();
final StringWriter writer = new StringWriter();
mapper.writeValue(writer, principalWritten);
server.andRespond(withSuccess(writer.toString(), MediaType.APPLICATION_JSON));
final HandlerResult res = authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
assertEquals(res.getPrincipal().getId(), "casuser");
}
示例7: newTGT
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
static TicketGrantingTicket newTGT() {
final Principal principal = new DefaultPrincipalFactory().createPrincipal(
"bob", Collections.singletonMap("displayName", "Bob"));
return new TicketGrantingTicketImpl(
ID_GENERATOR.getNewTicketId(TicketGrantingTicket.PREFIX),
CoreAuthenticationTestUtils.getAuthentication(principal),
EXP_POLICY_TGT);
}
示例8: verifyReturnedPrincipal
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyReturnedPrincipal() {
assertEquals("test", this.resolver.resolve(
new PrincipalBearingCredential(new DefaultPrincipalFactory().createPrincipal("test")),
CoreAuthenticationTestUtils.getPrincipal(),
new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
}
示例9: verifyToStringWithPrincipal
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyToStringWithPrincipal() {
final SpnegoCredential credentials = new SpnegoCredential(new byte[] {});
final Principal principal = new DefaultPrincipalFactory().createPrincipal("test");
credentials.setPrincipal(principal);
assertEquals("test", credentials.toString());
}
示例10: verifyPrincipalAffectsHash
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
/**
* Make sure that when the Principal becomes populated / changes we return a new hash
*/
@Test
public void verifyPrincipalAffectsHash(){
final SpnegoCredential credential = new SpnegoCredential(new byte[] {});
final int hash1 = credential.hashCode();
final Principal principal = new DefaultPrincipalFactory().createPrincipal("test");
credential.setPrincipal(principal);
final int hash2 = credential.hashCode();
assertNotEquals(hash1, hash2);
}
示例11: verifyValidCredentials
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Test
public void verifyValidCredentials() {
this.spnegoCredentials.setPrincipal(new DefaultPrincipalFactory().createPrincipal("test"));
assertEquals("test", this.resolver.resolve(this.spnegoCredentials,
CoreAuthenticationTestUtils.getPrincipal(),
new SimpleTestUsernamePasswordAuthenticationHandler()).getId());
}
示例12: AbstractAuthenticationHandler
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
/**
* Instantiates a new Abstract authentication handler.
*
* @param name Handler name.
* @param servicesManager the services manager.
* @param principalFactory the principal factory
* @param order the order
*/
public AbstractAuthenticationHandler(final String name, final ServicesManager servicesManager, final PrincipalFactory principalFactory,
final Integer order) {
this.name = StringUtils.isNotBlank(name) ? name : getClass().getSimpleName();
this.servicesManager = servicesManager;
this.principalFactory = principalFactory == null ? new DefaultPrincipalFactory() : principalFactory;
if (order == null) {
this.order = RandomUtils.nextInt(1, Integer.MAX_VALUE);
} else {
this.order = order;
}
}
示例13: authenticate
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
@Override
public HandlerResult authenticate(final Credential credential)
throws GeneralSecurityException, PreventedException {
final OneTimePasswordCredential otp = (OneTimePasswordCredential) credential;
final String valueOnRecord = credentialMap.get(otp.getId());
if (otp.getPassword().equals(valueOnRecord)) {
return new DefaultHandlerResult(this, new BasicCredentialMetaData(otp),
new DefaultPrincipalFactory().createPrincipal(otp.getId()));
}
throw new FailedLoginException();
}
示例14: newMockHandler
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
/**
* Creates a new named mock authentication handler that either successfully validates all credentials or fails to
* validate all credentials.
*
* @param name Authentication handler name.
* @param success True to authenticate all credentials, false to fail all credentials.
* @return New mock authentication handler instance.
* @throws Exception On errors.
*/
private static AuthenticationHandler newMockHandler(final String name, final boolean success) throws Exception {
final AuthenticationHandler mock = mock(AuthenticationHandler.class);
when(mock.getName()).thenReturn(name);
when(mock.supports(any(Credential.class))).thenReturn(true);
if (success) {
final Principal p = new DefaultPrincipalFactory().createPrincipal("nobody");
final HandlerResult result = new DefaultHandlerResult(mock, mock(CredentialMetaData.class), p);
when(mock.authenticate(any(Credential.class))).thenReturn(result);
} else {
when(mock.authenticate(any(Credential.class))).thenThrow(new FailedLoginException());
}
return mock;
}
示例15: AcceptUsersAuthenticationHandlerTests
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory; //导入依赖的package包/类
public AcceptUsersAuthenticationHandlerTests() throws Exception {
final Map<String, String> users = new HashMap<>();
users.put(SCOTT, RUTGERS);
users.put("dima", "javarules");
users.put("bill", "thisisAwesoME");
users.put("brian", "t�st");
this.authenticationHandler = new AcceptUsersAuthenticationHandler("", null, new DefaultPrincipalFactory(), null, users);
}