本文整理汇总了Java中org.jasig.cas.authentication.Credential类的典型用法代码示例。如果您正苦于以下问题:Java Credential类的具体用法?Java Credential怎么用?Java Credential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credential类属于org.jasig.cas.authentication包,在下文中一共展示了Credential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setResponseHeader
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
private void setResponseHeader(final RequestContext context,
final Credential credential) {
if (credential == null) {
return;
}
final HttpServletResponse response = WebUtils
.getHttpServletResponse(context);
final SpnegoCredential spnegoCredentials = (SpnegoCredential) credential;
final byte[] nextToken = spnegoCredentials.getNextToken();
if (nextToken != null) {
if (logger.isDebugEnabled()) {
logger.debug("Obtained output token: " + new String(nextToken));
}
response.setHeader(SpnegoConstants.HEADER_AUTHENTICATE, (this.ntlm
? SpnegoConstants.NTLM : SpnegoConstants.NEGOTIATE)
+ " " + Base64.encode(nextToken));
} else {
logger.debug("Unable to obtain the output token required.");
}
if (spnegoCredentials.getPrincipal() == null && send401OnAuthenticationFailure) {
logger.debug("Setting HTTP Status to 401");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
}
示例2: verifySuccessfulAuthenticationWithServiceAndWarn
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void verifySuccessfulAuthenticationWithServiceAndWarn()
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockRequestContext context = new MockRequestContext();
WebUtils.putLoginTicket(context, "LOGIN");
request.addParameter("lt", "LOGIN");
request.addParameter("username", "test");
request.addParameter("password", "test");
request.addParameter("warn", "true");
request.addParameter("service", "test");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, response));
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
putCredentialInRequestScope(context, c);
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("success", this.action.submit(context, c, messageContext).getId());
assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:AuthenticationViaFormActionTests.java
示例3: authenticate
import org.jasig.cas.authentication.Credential; //导入依赖的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 HandlerResult(this, new BasicCredentialMetaData(c), principal);
}
示例4: verifyRenewWithServiceAndDifferentCredentials
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void verifyRenewWithServiceAndDifferentCredentials() throws Exception {
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils.getAuthenticationContext(
getAuthenticationSystemSupport(), TestUtils.getService("test"), c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putLoginTicket(context, "LOGIN");
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", TestUtils.getService("test").getId());
request.addParameter("username", "test2");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("success", this.action.submit(context, c, messageContext).getId());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:26,代码来源:AuthenticationViaFormActionTests.java
示例5: setResponseHeader
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
/**
* Sets the response header based on the retrieved tocken.
*
* @param context the context
* @param credential the credential
*/
private void setResponseHeader(final RequestContext context,
final Credential credential) {
if (credential == null) {
return;
}
final HttpServletResponse response = WebUtils
.getHttpServletResponse(context);
final SpnegoCredential spnegoCredentials = (SpnegoCredential) credential;
final byte[] nextToken = spnegoCredentials.getNextToken();
if (nextToken != null) {
logger.debug("Obtained output token: {}", new String(nextToken, Charset.defaultCharset()));
response.setHeader(SpnegoConstants.HEADER_AUTHENTICATE, (this.ntlm
? SpnegoConstants.NTLM : SpnegoConstants.NEGOTIATE)
+ ' ' + CompressionUtils.encodeBase64(nextToken));
} else {
logger.debug("Unable to obtain the output token required.");
}
if (spnegoCredentials.getPrincipal() == null && send401OnAuthenticationFailure) {
logger.debug("Setting HTTP Status to 401");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
}
示例6: verifyAttributePopulationWithPasswordWithDifferentCredentialsType
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void verifyAttributePopulationWithPasswordWithDifferentCredentialsType() {
final Authentication auth = TestUtils.getAuthentication();
final Map<String, String> map = new HashMap<>();
final CacheCredentialsMetaDataPopulator populator = new CacheCredentialsMetaDataPopulator(map);
final Credential c = new Credential() {
@Override
public String getId() {
return "something";
}
};
if (populator.supports(c)) {
populator.populateAttributes(DefaultAuthenticationBuilder.newInstance(auth), c);
}
assertEquals(map.size(), 0);
}
示例7: verifyResolverServiceTicket
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void verifyResolverServiceTicket() throws Exception {
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
final AuthenticationContext ctx = TestUtils.getAuthenticationContext(getAuthenticationSystemSupport(), c);
final TicketGrantingTicket ticketId = getCentralAuthenticationService()
.createTicketGrantingTicket(ctx);
final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(),
TestUtils.getService(), ctx);
final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
final JoinPoint jp = mock(JoinPoint.class);
when(jp.getArgs()).thenReturn(new Object[] {st.getId()});
final String result = res.resolveFrom(jp, null);
assertNotNull(result);
assertEquals(result, c.getId());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:20,代码来源:TicketOrCredentialPrincipalResolverTests.java
示例8: MockTicketGrantingTicket
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
public MockTicketGrantingTicket(final String id, final Credential credential) {
this.id = id;
final CredentialMetaData credentialMetaData = new BasicCredentialMetaData(credential);
final AuthenticationBuilder builder = new AuthenticationBuilder();
final Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("nickname", "bob");
builder.setPrincipal(new SimplePrincipal("handymanbob", attributes));
builder.setAuthenticationDate(new Date());
builder.addCredential(credentialMetaData);
final AuthenticationHandler handler = new MockAuthenticationHandler();
try {
builder.addSuccess(handler.getName(), handler.authenticate(credential));
} catch (final Exception e) {
throw new RuntimeException(e);
}
builder.addFailure(handler.getName(), FailedLoginException.class);
this.authentication = builder.build();
}
示例9: constructCredentialsFromRequest
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Override
protected Credential constructCredentialsFromRequest(
final RequestContext context) {
final HttpServletRequest request = WebUtils
.getHttpServletRequest(context);
final Principal principal = request.getUserPrincipal();
if (principal != null) {
logger.debug("UserPrincipal [{}] found in HttpServletRequest", principal.getName());
return new PrincipalBearingCredential(this.principalFactory.createPrincipal(principal.getName()));
}
logger.debug("UserPrincipal not found in HttpServletRequest.");
return null;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:PrincipalFromRequestUserPrincipalNonInteractiveCredentialsAction.java
示例10: verifyResolverServiceTicket
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void verifyResolverServiceTicket() throws Exception {
final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
final TicketGrantingTicket ticketId = getCentralAuthenticationService()
.createTicketGrantingTicket(c);
final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(),
TestUtils.getService());
final TicketOrCredentialPrincipalResolver res =
new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
final JoinPoint jp = mock(JoinPoint.class);
when(jp.getArgs()).thenReturn(new Object[] {st.getId()});
final String result = res.resolveFrom(jp, null);
assertNotNull(result);
assertEquals(result, c.getId());
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:TicketOrCredentialPrincipalResolverTests.java
示例11: verifyRenewWithServiceAndDifferentCredentials
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void verifyRenewWithServiceAndDifferentCredentials() throws Exception {
final Credential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithSameUsernameAndPassword();
final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils.getAuthenticationContext(
getAuthenticationSystemSupport(), TestUtils.getService("test"), c);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
WebUtils.putLoginTicket(context, "LOGIN");
request.addParameter("lt", "LOGIN");
WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
request.addParameter("renew", "true");
request.addParameter("service", TestUtils.getService("test").getId());
request.addParameter("username", "test2");
request.addParameter("password", "test2");
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
final MessageContext messageContext = mock(MessageContext.class);
assertEquals("success", this.action.submit(context, c, messageContext).getId());
}
示例12: retrievePersonAttributes
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Override
protected Map<String, List<Object>> retrievePersonAttributes(final String principalId, final Credential credential) {
final WsFederationCredential wsFedCredentials = (WsFederationCredential) credential;
if (this.configuration.getAttributesType() == WsFedPrincipalResolutionAttributesType.WSFED) {
return wsFedCredentials.getAttributes();
}
if (this.configuration.getAttributesType() == WsFedPrincipalResolutionAttributesType.CAS) {
return super.retrievePersonAttributes(principalId, credential);
}
final Map<String, List<Object>> mergedAttributes = new HashMap<>(wsFedCredentials.getAttributes());
mergedAttributes.putAll(super.retrievePersonAttributes(principalId, credential));
return mergedAttributes;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:WsFederationCredentialsToPrincipalResolver.java
示例13: resolve
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Override
public Principal resolve(Credential credential) {
logger.debug("Attempting to resolve a principal...");
if (credential instanceof ClientCredential){
// do nothing
} else {
throw new RuntimeException("用户数据转换异常!");
}
ClientCredential oauthCredential = (ClientCredential) credential;
UserProfile userProfile = oauthCredential.getUserProfile();
logger.info("userProfile = {}", userProfile);
//String principalId = oauthCredential.getUserProfile().getId();
String principalId = oauthCredential.getId();
if (principalId == null) {
logger.debug("Got null for extracted principal ID; returning null.");
return null;
}
logger.debug("Creating SimplePrincipal for [{}]", principalId);
//UserProfile userProfile = oauthCredential.getUserProfile();
final Map<String, Object> attributes = userProfile.getAttributes();
if (attributes == null & !this.returnNullIfNoAttributes) {
return new SimplePrincipal(principalId);
}
if (attributes == null) {
return null;
}
return new SimplePrincipal(principalId, attributes);
}
示例14: testTestBindingWithCredentialsBinder
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
@Test
public void testTestBindingWithCredentialsBinder() throws Exception {
final MockRequestContext context = new MockRequestContext();
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), new MockHttpServletRequest(),
new MockHttpServletResponse()));
// context.setLastEvent(new Event(this, "test"));
final CredentialsBinder cb = new CredentialsBinder(){
public void bind(final HttpServletRequest request, final Credential credentials) {
((UsernamePasswordCredential) credentials)
.setUsername("test2");
((UsernamePasswordCredential) credentials)
.setPassword("test2");
}
public boolean supports(final Class<?> clazz) {
return true;
}
};
this.action.setCredentialsBinder(cb);
// this.action.bindAndValidate(context);
// assertEquals(
// "test2",
// ((UsernamePasswordCredential) context
// .getFlowScope().get(
// "credentials")).getUsername());
}
示例15: doAuthentication
import org.jasig.cas.authentication.Credential; //导入依赖的package包/类
/**
* Do an out of band request using the DuoWeb api (encapsulated in DuoAuthenticationService)
* to the hosted duo service. If it is successful
* it will return a String containing the username of the successfully authenticated user, but if not - will
* return a blank String or null.
* @param credential Credential to authenticate.
*
* @throws GeneralSecurityException general security exception for errors
* @throws PreventedException authentication failed exception
*/
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
try {
final DuoCredential duoCredential = (DuoCredential) credential;
if (!duoCredential.isValid()) {
throw new GeneralSecurityException("Duo credential validation failed. Ensure a username "
+ " and the signed Duo response is configured and passed. Credential received: " + duoCredential);
}
final String duoVerifyResponse = this.duoAuthenticationService.authenticate(duoCredential.getSignedDuoResponse());
logger.debug("Response from Duo verify: [{}]", duoVerifyResponse);
final String primaryCredentialsUsername = duoCredential.getUsername();
final boolean isGoodAuthentication = duoVerifyResponse.equals(primaryCredentialsUsername);
if (isGoodAuthentication) {
logger.info("Successful Duo authentication for [{}]", primaryCredentialsUsername);
final Principal principal = this.principalFactory.createPrincipal(duoVerifyResponse);
return createHandlerResult(credential, principal, new ArrayList<MessageDescriptor>());
}
throw new FailedLoginException("Duo authentication username "
+ primaryCredentialsUsername + " does not match Duo response: " + duoVerifyResponse);
} catch (final Exception e) {
logger.error(e.getMessage(), e);
throw new FailedLoginException(e.getMessage());
}
}