本文整理汇总了Java中org.apereo.cas.authentication.principal.Service类的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Service类属于org.apereo.cas.authentication.principal包,在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeServletApplicationContext
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@PostConstruct
public void initializeServletApplicationContext() {
final String oAuthCallbackUrl = casProperties.getServer().getPrefix() + BASE_OAUTH20_URL + '/' + CALLBACK_AUTHORIZE_URL_DEFINITION;
final Service callbackService = this.webApplicationServiceFactory.createService(oAuthCallbackUrl);
final RegisteredService svc = servicesManager.findServiceBy(callbackService);
if (svc == null || !svc.getServiceId().equals(oAuthCallbackUrl)) {
final RegexRegisteredService service = new RegexRegisteredService();
service.setId(Math.abs(new SecureRandom().nextLong()));
service.setEvaluationOrder(0);
service.setName(service.getClass().getSimpleName());
service.setDescription("OAuth Authentication Callback Request URL");
service.setServiceId(oAuthCallbackUrl);
service.setAttributeReleasePolicy(new DenyAllAttributeReleasePolicy());
servicesManager.save(service);
servicesManager.load();
}
}
示例2: produceTicketIdentifier
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
/**
* Produce ticket identifier.
*
* @param service the service
* @return the ticket id
*/
protected String produceTicketIdentifier(final Service service) {
final String uniqueTicketIdGenKey = service.getClass().getName();
LOGGER.debug("Looking up ticket id generator for [{}]", uniqueTicketIdGenKey);
UniqueTicketIdGenerator generator = this.uniqueTicketIdGeneratorsForService.get(uniqueTicketIdGenKey);
if (generator == null) {
generator = this.defaultTicketIdGenerator;
LOGGER.debug("Ticket id generator not found for [{}]. Using the default generator...", uniqueTicketIdGenKey);
}
String ticketId = generator.getNewTicketId(ProxyTicket.PROXY_TICKET_PREFIX);
if (this.cipherExecutor != null) {
LOGGER.debug("Attempting to encode proxy ticket [{}]", ticketId);
ticketId = this.cipherExecutor.encode(ticketId);
LOGGER.debug("Encoded proxy ticket id [{}]", ticketId);
}
return ticketId;
}
示例3: grantServiceTicket
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
/**
* Grant service ticket for the given credential based on the service and tgt
* that are found in the request context.
*
* @param context the context
* @return the resulting event. Warning, authentication failure or error.
* @since 4.1.0
*/
protected Event grantServiceTicket(final RequestContext context) {
final String ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
final Credential credential = getCredentialFromContext(context);
try {
final Service service = WebUtils.getService(context);
final AuthenticationResult authenticationResult =
this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicketId, service, authenticationResult);
WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
WebUtils.putWarnCookieIfRequestParameterPresent(this.warnCookieGenerator, context);
return newEvent(CasWebflowConstants.TRANSITION_ID_WARN);
} catch (final AuthenticationException | AbstractTicketException e) {
return newEvent(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, e);
}
}
示例4: handleAuthenticationTransactionAndGrantTicketGrantingTicket
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
/**
* Handle authentication transaction and grant ticket granting ticket.
*
* @param context the context
* @return the set
*/
protected Set<Event> handleAuthenticationTransactionAndGrantTicketGrantingTicket(final RequestContext context) {
try {
final Credential credential = getCredentialFromContext(context);
AuthenticationResultBuilder builder = WebUtils.getAuthenticationResultBuilder(context);
LOGGER.debug("Handling authentication transaction for credential [{}]", credential);
final Service service = WebUtils.getService(context);
builder = this.authenticationSystemSupport.handleAuthenticationTransaction(service, builder, credential);
LOGGER.debug("Issuing ticket-granting tickets for service [{}]", service);
return Collections.singleton(grantTicketGrantingTicketToAuthenticationResult(context, builder, service));
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
final MessageContext messageContext = context.getMessageContext();
messageContext.addMessage(new MessageBuilder().error()
.code(DEFAULT_MESSAGE_BUNDLE_PREFIX.concat(e.getClass().getSimpleName())).build());
return Collections.singleton(new EventFactorySupport().error(this));
}
}
示例5: resolveUsernameFromInlineGroovyScript
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
private String resolveUsernameFromInlineGroovyScript(final Principal principal, final Service service, final String script) {
try {
LOGGER.debug("Found groovy script to execute [{}]", this.groovyScript);
final Object result = getGroovyAttributeValue(principal, script);
if (result != null) {
LOGGER.debug("Found username [{}] from script [{}]", result, this.groovyScript);
return result.toString();
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
LOGGER.warn("Groovy script [{}] returned no value for username attribute. Fallback to default [{}]",
this.groovyScript, principal.getId());
return principal.getId();
}
示例6: buildCallbackUrlResponseType
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
protected String buildCallbackUrlResponseType(Authentication authentication, Service service, String redirectUri, AccessToken accessToken, List<NameValuePair> params) throws Exception {
String state = authentication.getAttributes().get("state").toString();
String nonce = authentication.getAttributes().get("nonce").toString();
URIBuilder builder = new URIBuilder(redirectUri);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("access_token").append('=').append(accessToken.getId()).append('&').append("token_type").append('=').append("bearer").append('&').append("expires_in").append('=').append(this.casProperties.getTicket().getTgt().getTimeToKillInSeconds());
params.forEach((p) -> {
stringBuilder.append('&').append(p.getName()).append('=').append(p.getValue());
});
if(StringUtils.isNotBlank(state)) {
stringBuilder.append('&').append("state").append('=').append(EncodingUtils.urlEncode(state));
}
if(StringUtils.isNotBlank(nonce)) {
stringBuilder.append('&').append("nonce").append('=').append(EncodingUtils.urlEncode(nonce));
}
builder.setFragment(stringBuilder.toString());
String url = builder.toString();
return url;
}
示例7: trackServiceSession
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
/**
* Update service and track session.
*
* @param id the id
* @param service the service
* @param onlyTrackMostRecentSession the only track most recent session
*/
protected void trackServiceSession(final String id, final Service service, final boolean onlyTrackMostRecentSession) {
update();
service.setPrincipal(getRoot().getAuthentication().getPrincipal());
if (onlyTrackMostRecentSession) {
final String path = normalizePath(service);
final Collection<Service> existingServices = this.services.values();
// loop on existing services
existingServices.stream()
.filter(existingService -> path.equals(normalizePath(existingService)))
.findFirst().ifPresent(existingServices::remove);
}
this.services.put(id, service);
}
示例8: verifyMatchesExistingService
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@Test
public void verifyMatchesExistingService() {
final RegexRegisteredService r = new RegexRegisteredService();
r.setId(1000);
r.setName(TEST);
r.setServiceId(TEST);
final Service service = new SimpleService(TEST);
final Service service2 = new SimpleService("fdfa");
this.defaultServicesManager.save(r);
assertTrue(this.defaultServicesManager.matchesExistingService(service));
assertEquals(r, this.defaultServicesManager.findServiceBy(service));
assertNull(this.defaultServicesManager.findServiceBy(service2));
}
示例9: verifyValidServiceTicketWithDifferentEncoding
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@Test
public void verifyValidServiceTicketWithDifferentEncoding() throws Exception {
final Service svc = CoreAuthenticationTestUtils.getService("http://www.jasig.org?param=hello+world");
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler());
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), svc, ctx);
final String reqSvc = "http://www.jasig.org?param=hello%20world";
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(SERVICE_PARAM, CoreAuthenticationTestUtils.getService(reqSvc).getId());
request.addParameter(TICKET_PARAM, sId.getId());
assertTrue(this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse()).getView().toString().contains(SUCCESS));
}
示例10: constructCredentialsFromRequest
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@Override
protected Credential constructCredentialsFromRequest(final RequestContext context) {
final String ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
final String openidIdentityParameter = context.getRequestParameters().get(OpenIdProtocolConstants.OPENID_IDENTITY);
final String userName = getOpenIdSelectedIdentifier(context, ticketGrantingTicketId, openidIdentityParameter);
final Service service = WebUtils.getService(context);
// clear the service because otherwise we can fake the username
if (service instanceof OpenIdService && StringUtils.isBlank(userName)) {
context.getFlowScope().remove(CasProtocolConstants.PARAMETER_SERVICE);
}
if (StringUtils.isBlank(ticketGrantingTicketId) || StringUtils.isBlank(userName)) {
return null;
}
return new OpenIdCredential(ticketGrantingTicketId, userName);
}
示例11: ensurePrincipalAccessIsAllowedForService
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
/**
* Ensure service access is allowed.
*
* @param service the service
* @param registeredService the registered service
* @param authentication the authentication
* @throws UnauthorizedServiceException the unauthorized service exception
* @throws PrincipalException the principal exception
*/
public static void ensurePrincipalAccessIsAllowedForService(final Service service,
final RegisteredService registeredService,
final Authentication authentication)
throws UnauthorizedServiceException, PrincipalException {
ensureServiceAccessIsAllowed(service, registeredService);
final Principal principal = authentication.getPrincipal();
final Map<String, Object> principalAttrs = registeredService.getAttributeReleasePolicy().getAttributes(principal, service, registeredService);
if (!registeredService.getAccessStrategy().doPrincipalAttributesAllowServiceAccess(principal.getId(), principalAttrs)) {
LOGGER.warn("Cannot grant access to service [{}] because it is not authorized for use by [{}].", service.getId(), principal);
final Map<String, Class<? extends Exception>> handlerErrors = new HashMap<>();
handlerErrors.put(UnauthorizedServiceForPrincipalException.class.getSimpleName(),
UnauthorizedServiceForPrincipalException.class);
throw new PrincipalException(UnauthorizedServiceForPrincipalException.CODE_UNAUTHZ_SERVICE, handlerErrors, new HashMap<>());
}
}
示例12: verifyValidateServiceTicketWithInvalidUsernameAttribute
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@Test
public void verifyValidateServiceTicketWithInvalidUsernameAttribute() throws Exception {
final Service svc = getService("eduPersonTestInvalid");
final UsernamePasswordCredential cred = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), svc);
final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket serviceTicket = getCentralAuthenticationService().grantServiceTicket(ticketGrantingTicket.getId(), svc, ctx);
final Assertion assertion = getCentralAuthenticationService().validateServiceTicket(serviceTicket.getId(), svc);
final Authentication auth = assertion.getPrimaryAuthentication();
/*
* The attribute specified for this service does not resolve.
* Therefore, we expect the default to be returned.
*/
assertEquals(auth.getPrincipal().getId(), cred.getUsername());
}
示例13: TicketGrantingTicketImpl
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
/**
* Constructs a new TicketGrantingTicket.
* May throw an {@link IllegalArgumentException} if the Authentication object is null.
*
* @param id the id of the Ticket
* @param proxiedBy Service that produced this proxy ticket.
* @param parentTicketGrantingTicket the parent ticket
* @param authentication the Authentication request for this ticket
* @param policy the expiration policy for this ticket.
*/
@JsonCreator
public TicketGrantingTicketImpl(@JsonProperty("id") final String id,
@JsonProperty("proxiedBy") final Service proxiedBy,
@JsonProperty("grantingTicket") final TicketGrantingTicket parentTicketGrantingTicket,
@JsonProperty("authentication") final Authentication authentication,
@JsonProperty("expirationPolicy") final ExpirationPolicy policy) {
super(id, policy);
if (parentTicketGrantingTicket != null && proxiedBy == null) {
throw new IllegalArgumentException("Must specify proxiedBy when providing parent TGT");
}
Assert.notNull(authentication, "authentication cannot be null");
this.ticketGrantingTicket = parentTicketGrantingTicket;
this.authentication = authentication;
this.proxiedBy = proxiedBy;
}
示例14: doExecute
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final Service service = this.serviceSelectionStrategy.resolveService(WebUtils.getService(requestContext));
if (service != null) {
final RegisteredService registeredService = this.servicesManager.findServiceBy(service);
RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service, registeredService);
if (registeredService instanceof SamlRegisteredService) {
final SamlRegisteredService samlService = SamlRegisteredService.class.cast(registeredService);
final Optional<SamlRegisteredServiceServiceProviderMetadataFacade> adaptor =
SamlRegisteredServiceServiceProviderMetadataFacade.get(resolver, samlService, service.getId());
if (!adaptor.isPresent()) {
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE,
"Cannot find metadata linked to " + service.getId());
}
final SamlMetadataUIInfo mdui = MetadataUIUtils.locateMetadataUserInterfaceForEntityId(adaptor.get().getEntityDescriptor(),
service.getId(), registeredService);
WebUtils.putServiceUserInterfaceMetadata(requestContext, mdui);
}
}
return success();
}
示例15: verifyWebApplicationServices
import org.apereo.cas.authentication.principal.Service; //导入依赖的package包/类
@Test
public void verifyWebApplicationServices() {
final MockService testService = new MockService(TGT_ID);
final TicketGrantingTicket t = new TicketGrantingTicketImpl(TGT_ID, null, null,
CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
t.grantServiceTicket(ID_GENERATOR
.getNewTicketId(ServiceTicket.PREFIX), testService,
new NeverExpiresExpirationPolicy(), false, true);
Map<String, Service> services = t.getServices();
assertEquals(1, services.size());
final String ticketId = services.keySet().iterator().next();
assertEquals(testService, services.get(ticketId));
t.removeAllServices();
services = t.getServices();
assertEquals(0, services.size());
}