本文整理汇总了Java中org.jasig.cas.authentication.principal.Principal类的典型用法代码示例。如果您正苦于以下问题:Java Principal类的具体用法?Java Principal怎么用?Java Principal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Principal类属于org.jasig.cas.authentication.principal包,在下文中一共展示了Principal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyServiceAttributeFilterAllowedAttributes
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void verifyServiceAttributeFilterAllowedAttributes() {
final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAllowedAttributes(Arrays.asList("attr1", "attr3"));
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = policy.getAttributes(p);
assertEquals(attr.size(), 2);
assertTrue(attr.containsKey("attr1"));
assertTrue(attr.containsKey("attr3"));
final byte[] data = SerializationUtils.serialize(policy);
final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
assertNotNull(p2);
assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:25,代码来源:RegisteredServiceAttributeReleasePolicyTests.java
示例2: resolvePrincipal
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
/**
* Resolve principal.
*
* @param handlerName the handler name
* @param resolver the resolver
* @param credential the credential
* @return the principal
*/
protected Principal resolvePrincipal(
final String handlerName, final PrincipalResolver resolver, final Credential credential) {
if (resolver.supports(credential)) {
try {
final Principal p = resolver.resolve(credential);
logger.debug("{} resolved {} from {}", resolver, p, credential);
return p;
} catch (final Exception e) {
logger.error("{} failed to resolve principal from {}", resolver, credential, e);
}
} else {
logger.warn(
"{} is configured to use {} but it does not support {}, which suggests a configuration problem.",
handlerName,
resolver,
credential);
}
return null;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:28,代码来源:PolicyBasedAuthenticationManager.java
示例3: authenticateUsernamePasswordInternal
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
throws GeneralSecurityException, PreventedException {
if (this.kerberosKdcSystemProperty != null) {
logger.debug("Setting kerberos system property {} to {}", SYS_PROP_KERB5_KDC, this.kerberosKdcSystemProperty);
System.setProperty(SYS_PROP_KERB5_KDC, this.kerberosKdcSystemProperty);
}
if (this.kerberosRealmSystemProperty != null) {
logger.debug("Setting kerberos system property {} to {}", SYS_PROP_KRB5_REALM, this.kerberosRealmSystemProperty);
System.setProperty(SYS_PROP_KRB5_REALM, this.kerberosRealmSystemProperty);
}
final String username = credential.getUsername();
final String password = getPasswordEncoder().encode(credential.getPassword());
final LoginContext lc = new LoginContext(
this.realm,
new UsernamePasswordCallbackHandler(username, password));
try {
logger.debug("Attempting authentication for: {}", username);
lc.login();
} finally {
lc.logout();
}
Principal principal = null;
final Set<java.security.Principal> principals = lc.getSubject().getPrincipals();
if (principals != null && !principals.isEmpty()) {
final java.security.Principal secPrincipal = principals.iterator().next();
principal = this.principalFactory.createPrincipal(secPrincipal.getName());
}
return createHandlerResult(credential, principal, null);
}
示例4: authenticate
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException {
final OpenIdCredential c = (OpenIdCredential) credential;
final TicketGrantingTicket t = this.ticketRegistry.getTicket(c.getTicketGrantingTicketId(),
TicketGrantingTicket.class);
if (t == null || t.isExpired()) {
throw new FailedLoginException("TGT is null or expired.");
}
final Principal principal = t.getAuthentication().getPrincipal();
if (!principal.getId().equals(c.getUsername())) {
throw new FailedLoginException("Principal ID mismatch");
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(c), principal);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:OpenIdCredentialsAuthenticationHandler.java
示例5: verifyServiceAttributeFilterMappedAttributes
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void verifyServiceAttributeFilterMappedAttributes() {
prepareService();
final ReturnMappedAttributeReleasePolicy policy = new ReturnMappedAttributeReleasePolicy();
final Map<String, String> mappedAttr = new HashMap<>();
mappedAttr.put("attr1", "newAttr1");
policy.setAllowedAttributes(mappedAttr);
this.r.setAttributeReleasePolicy(policy);
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = this.r.getAttributeReleasePolicy().getAttributes(p);
assertEquals(attr.size(), 1);
assertTrue(attr.containsKey("newAttr1"));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:25,代码来源:AbstractRegisteredServiceTests.java
示例6: verifyValidPrincipal
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void verifyValidPrincipal() throws InvalidTicketException {
final CentralAuthenticationService cas = mock(CentralAuthenticationService.class);
final Authentication authn = mock(Authentication.class);
when(authn.getPrincipal()).thenReturn(
org.jasig.cas.authentication.TestUtils.getPrincipal("cas"));
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getAuthentication()).thenReturn(authn);
when(cas.getTicket(any(String.class), any(Ticket.class.getClass()))).thenReturn(tgt);
final GenericSuccessViewAction action = new GenericSuccessViewAction(cas);
final Principal p = action.getAuthenticationPrincipal("TGT-1");
assertNotNull(p);
assertEquals(p.getId(), "cas");
}
示例7: resolveUsername
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Override
public String resolveUsername(final Principal principal, final Service service) {
String principalId = principal.getId();
if (principal.getAttributes().containsKey(this.usernameAttribute)) {
principalId = principal.getAttributes().get(this.usernameAttribute).toString();
} else {
logger.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot "
+ "provide the user attribute the service expects. "
+ "CAS will instead return the default principal id [{}]",
principalId,
this.usernameAttribute,
principal.getAttributes(),
principalId);
}
logger.debug("Principal id to return is [{}]. The default principal id is [{}].",
principalId, principal.getId());
return principalId;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:PrincipalAttributeRegisteredServiceUsernameProvider.java
示例8: verifyServiceAttributeFilterAllowedAttributes
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void verifyServiceAttributeFilterAllowedAttributes() {
prepareService();
final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAllowedAttributes(Arrays.asList("attr1", "attr3"));
this.r.setAttributeReleasePolicy(policy);
final Principal p = mock(Principal.class);
final Map<String, Object> map = new HashMap<>();
map.put("attr1", "value1");
map.put("attr2", "value2");
map.put("attr3", Arrays.asList("v3", "v4"));
when(p.getAttributes()).thenReturn(map);
when(p.getId()).thenReturn("principalId");
final Map<String, Object> attr = this.r.getAttributeReleasePolicy().getAttributes(p);
assertEquals(attr.size(), 2);
assertTrue(attr.containsKey("attr1"));
assertTrue(attr.containsKey("attr3"));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:AbstractRegisteredServiceTests.java
示例9: convertPrincipalAttributesToPersonAttributes
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
/***
* Convert principal attributes to person attributes.
* @param p the principal carrying attributes
* @return person attributes
*/
private Map<String, List<Object>> convertPrincipalAttributesToPersonAttributes(final Principal p) {
final Map<String, List<Object>> convertedAttributes = new HashMap<>(p.getAttributes().size());
final Map<String, Object> principalAttributes = p.getAttributes();
for (final Map.Entry<String, Object> entry : principalAttributes.entrySet()) {
final Object values = entry.getValue();
final String key = entry.getKey();
if (values instanceof List) {
convertedAttributes.put(key, (List) values);
} else {
convertedAttributes.put(key, Collections.singletonList(values));
}
}
return convertedAttributes;
}
示例10: checkServiceAttributeFilterAllAttributesWithCachingTurnedOn
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void checkServiceAttributeFilterAllAttributesWithCachingTurnedOn() {
final ReturnAllAttributeReleasePolicy policy = new ReturnAllAttributeReleasePolicy();
final Map<String, List<Object>> attributes = new HashMap<>();
attributes.put("values", Arrays.asList(new Object[]{"v1", "v2", "v3"}));
attributes.put("cn", Arrays.asList(new Object[]{"commonName"}));
attributes.put("username", Arrays.asList(new Object[]{"uid"}));
final IPersonAttributeDao dao = new StubPersonAttributeDao(attributes);
final IPersonAttributes person = mock(IPersonAttributes.class);
when(person.getName()).thenReturn("uid");
when(person.getAttributes()).thenReturn(attributes);
final CachingPrincipalAttributesRepository repository =
new CachingPrincipalAttributesRepository(TimeUnit.MILLISECONDS, 100);
repository.setAttributeRepository(dao);
final Principal p = new DefaultPrincipalFactory().createPrincipal("uid",
Collections.<String, Object>singletonMap("mail", "[email protected]"));
policy.setPrincipalAttributesRepository(repository);
final Map<String, Object> attr = policy.getAttributes(p);
assertEquals(attr.size(), attributes.size());
}
示例11: verifyUsernameByPrincipalAttributeNotFound
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void verifyUsernameByPrincipalAttributeNotFound() {
final PrincipalAttributeRegisteredServiceUsernameProvider provider =
new PrincipalAttributeRegisteredServiceUsernameProvider("cn");
final Map<String, Object> attrs = new HashMap<>();
attrs.put("userid", "u1");
final Principal p = mock(Principal.class);
when(p.getId()).thenReturn("person");
when(p.getAttributes()).thenReturn(attrs);
final String id = provider.resolveUsername(p, TestUtils.getService());
assertEquals(id, p.getId());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:PrincipalAttributeRegisteredServiceUsernameProviderTests.java
示例12: verify
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Override
public boolean verify(final RequestContext requestContext, final Credential credential) {
final Principal principal = getPrincipal(requestContext);
final Map<String, Object> attributes = principal.getAttributes();
logger.debug("Principal attributes found for {} are {}", principal.getId(), attributes);
if (attributes != null && attributes.containsKey(this.aupAttributeName)) {
final Object value = attributes.get(this.aupAttributeName);
logger.debug("Evaluating attribute value {} found for {}", value, this.aupAttributeName);
if (value.toString().equalsIgnoreCase(Boolean.TRUE.toString())) {
return true;
}
}
logger.warn("Usage policy has not been accepted by {}", principal.getId());
return false;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:AbstractPrincipalAttributeAcceptableUsagePolicyRepository.java
示例13: verifyRegServiceUsername
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Test
public void verifyRegServiceUsername() {
final DefaultRegisteredServiceUsernameProvider provider =
new DefaultRegisteredServiceUsernameProvider();
final Principal principal = mock(Principal.class);
when(principal.getId()).thenReturn("id");
final String id = provider.resolveUsername(principal, TestUtils.getService());
assertEquals(id, principal.getId());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:11,代码来源:DefaultRegisteredServiceUsernameProviderTests.java
示例14: getAuthentication
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
public static Authentication getAuthentication(final Principal principal, final Map<String, Object> attributes) {
final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
return new DefaultAuthenticationBuilder(principal)
.addCredential(meta)
.addSuccess("testHandler", new DefaultHandlerResult(handler, meta))
.setAttributes(attributes)
.build();
}
示例15: getAttributes
import org.jasig.cas.authentication.principal.Principal; //导入依赖的package包/类
@Override
public final Map<String, Object> getAttributes(final Principal p) {
final Map<String, Object> cachedAttributes = getPrincipalAttributes(p);
if (cachedAttributes != null && !cachedAttributes.isEmpty()) {
LOGGER.debug("Found [{}] cached attributes for principal [{}]", cachedAttributes.size(), p.getId());
return cachedAttributes;
}
if (getAttributeRepository() == null) {
LOGGER.debug("No attribute repository is defined for [{}]. Returning default principal attributes for {}",
getClass().getName(), p.getId());
return cachedAttributes;
}
final Map<String, List<Object>> sourceAttributes = retrievePersonAttributesToPrincipalAttributes(p.getId());
LOGGER.debug("Found [{}] attributes for principal [{}] from the attribute repository.",
sourceAttributes.size(), p.getId());
if (this.mergingStrategy == null || this.mergingStrategy.getAttributeMerger() == null) {
LOGGER.debug("No merging strategy found, so attributes retrieved from the repository will be used instead.");
return convertAttributesToPrincipalAttributesAndCache(p, sourceAttributes);
}
final Map<String, List<Object>> principalAttributes = convertPrincipalAttributesToPersonAttributes(p);
LOGGER.debug("Merging current principal attributes with that of the repository via strategy [{}]",
this.mergingStrategy.getClass().getSimpleName());
final Map<String, List<Object>> mergedAttributes =
this.mergingStrategy.getAttributeMerger().mergeAttributes(principalAttributes, sourceAttributes);
return convertAttributesToPrincipalAttributesAndCache(p, mergedAttributes);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:33,代码来源:AbstractPrincipalAttributesRepository.java