当前位置: 首页>>代码示例>>Java>>正文


Java TechnicalException类代码示例

本文整理汇总了Java中org.pac4j.core.exception.TechnicalException的典型用法代码示例。如果您正苦于以下问题:Java TechnicalException类的具体用法?Java TechnicalException怎么用?Java TechnicalException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TechnicalException类属于org.pac4j.core.exception包,在下文中一共展示了TechnicalException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkUnautorizedProtocol

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test
public void checkUnautorizedProtocol() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "BasicAuthClient");

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final BasicAuthClient basicAuthClient = new BasicAuthClient();
    final Clients clients = new Clients(MY_LOGIN_URL, basicAuthClient);
    final ClientAction action = new ClientAction(mock(CentralAuthenticationService.class), clients);

    try {
        action.execute(mockRequestContext);
        fail("Should fail as the HTTP protocol is not authorized");
    } catch (final TechnicalException e) {
        assertEquals("Only CAS, OAuth, OpenID and SAML protocols are supported: " + basicAuthClient, e.getMessage());
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:23,代码来源:ClientActionTests.java

示例2: checkUnautorizedProtocol

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test
public void checkUnautorizedProtocol() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "IndirectBasicAuthClient");

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient();
    final Clients clients = new Clients(MY_LOGIN_URL, basicAuthClient);
    final ClientAction action = new ClientAction();
    action.setCentralAuthenticationService(mock(CentralAuthenticationService.class));
    action.setClients(clients);

    try {
        action.execute(mockRequestContext);
        fail("Should fail as the HTTP protocol is not authorized");
    } catch (final TechnicalException e) {
        assertEquals("Only CAS, OAuth, OpenID and SAML protocols are supported: " + basicAuthClient, e.getMessage());
    }
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:25,代码来源:ClientActionTests.java

示例3: adapt

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Override
public Void adapt(int code, VertxAsyncWebContext context) {
    if (code == HttpConstants.UNAUTHORIZED) {
        sendFailureResponse(context, HttpConstants.UNAUTHORIZED);
    } else if (code == HttpConstants.FORBIDDEN) {
        sendFailureResponse(context, HttpConstants.FORBIDDEN);
    } else if (code == HttpConstants.TEMP_REDIRECT) {
        final Optional<String> location = getLocation(context);
        // This is clunkier than it should be due to Java 8 Optional limitation
        location.orElseThrow(() -> new TechnicalException("Redirect without a location header"));
        location.ifPresent(l -> redirect(l, context));
    } else if (code == HttpConstants.OK) {
        // Content should already have been written
        context.setResponseStatus(HttpConstants.OK);
        context.setResponseHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.HTML_CONTENT_TYPE);
        context.completeResponse();
    } else {
        final String message = "Unsupported HTTP action: " + code;
        LOG.error(message);
        throw new TechnicalException(message);
    }
    return null;
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:24,代码来源:DefaultHttpActionAdapter.java

示例4: testTicketExistsValidationOccurs

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test
public void testTicketExistsValidationOccurs() throws HttpAction {
    final CasConfiguration configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    configuration.setTicketValidator((ticket, service) -> {
        if (TICKET.equals(ticket) && CALLBACK_URL.equals(service)) {
            return new AssertionImpl(TICKET);
        }
        throw new TechnicalException("Bad ticket or service");
    });
    final DirectCasClient client = new DirectCasClient(configuration);
    final MockWebContext context = MockWebContext.create();
    context.setFullRequestURL(CALLBACK_URL + "?" + CasConfiguration.TICKET_PARAMETER + "=" + TICKET);
    context.addRequestParameter(CasConfiguration.TICKET_PARAMETER, TICKET);
    final TokenCredentials credentials = client.getCredentials(context);
    assertEquals(TICKET, credentials.getToken());
    final CommonProfile profile = credentials.getUserProfile();
    assertTrue(profile instanceof CasProfile);
    assertEquals(TICKET, profile.getId());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:21,代码来源:DirectCasClientTests.java

示例5: getEngine

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
public static VelocityEngine getEngine() {

        try {

            final Properties props =
                    new Properties();
            props.putAll(net.shibboleth.utilities.java.support.velocity.VelocityEngine.getDefaultProperties());
            props.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
            props.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8");
            props.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
            props.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SLF4JLogChute.class.getName());

            final VelocityEngine velocityEngine =
                    net.shibboleth.utilities.java.support.velocity.VelocityEngine
                    .newVelocityEngine(props);
            return velocityEngine;
        } catch (final Exception e) {
            throw new TechnicalException("Error configuring velocity", e);
        }

    }
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:22,代码来源:VelocityEngineFactory.java

示例6: noIndirectClientsAvailable

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test(timeout = 2000)
public void noIndirectClientsAvailable(final TestContext testContext) {
    final AsyncWebContext context = MockAsyncWebContextBuilder.from(rule.vertx(), asynchronousComputationAdapter)
            .build();
    final List<AsyncClient<? extends Credentials, CommonProfile>> clients = Arrays.asList(getDirectClient());
    final Async async = testContext.async();
    authInitiator.initiateIndirectFlow(context, clients)
        .handle((a, t) -> {
            assertThat(t, is(notNullValue()));
            assertThat(a, is(nullValue()));
            final Throwable unwrapped = unwrapAsyncException(t);
            assertThat(unwrapped, instanceOf(TechnicalException.class));
            assertThat(unwrapped.getMessage(), is("No indirect client available for redirect"));
            async.complete();
            return null;
        });
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:18,代码来源:AsyncIndirectAuthenticationInitiatorTest.java

示例7: getBase64DecodedMessage

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
protected InputStream getBase64DecodedMessage()
        throws MessageDecodingException {
    logger.debug("Getting Base64 encoded message from context, ignoring the given request");
    String encodedMessage = this.context.getRequestParameter("SAMLRequest");
    if(Strings.isNullOrEmpty(encodedMessage)) {
        encodedMessage = this.context.getRequestParameter("SAMLResponse");
    }

    if(Strings.isNullOrEmpty(encodedMessage)) {
        throw new MessageDecodingException("Request did not contain either a SAMLRequest or SAMLResponse parameter. Invalid request for SAML 2 HTTP POST binding.");
    } else {
        logger.trace("Base64 decoding SAML message:\n{}", encodedMessage);
        final byte[] decodedBytes = Base64Support.decode(encodedMessage);
        if(decodedBytes == null) {
            throw new MessageDecodingException("Unable to Base64 decode SAML message");
        } else {
            try {
                logger.trace("Decoded SAML message:\n{}", new String(decodedBytes, HttpConstants.UTF8_ENCODING));
            } catch(final UnsupportedEncodingException e) {
                throw new TechnicalException(e);
            }
            return new ByteArrayInputStream(decodedBytes);
        }
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:26,代码来源:Pac4jHTTPPostDecoder.java

示例8: testSaml2ConfigurationOfKeyStore

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test
public void testSaml2ConfigurationOfKeyStore() throws Exception {
    final Resource rs = CommonHelper.getResource("testKeystore.jks");
    if (rs.exists() && !rs.getFile().delete()) {
        throw new TechnicalException("File could not be deleted");
    }

    final SAML2ClientConfiguration cfg =
            new SAML2ClientConfiguration("testKeystore.jks",
                    "pac4j-test-passwd",
                    "pac4j-test-passwd",
                    "resource:testshib-providers.xml");
    assertNotNull(cfg.getKeyStore());
    assertTrue(cfg.getKeyStore().size() == 1);
    if (!rs.getFile().delete()) {
        throw new TechnicalException("File could not be deleted");
    }

    final KeyStoreCredentialProvider p = new KeyStoreCredentialProvider(cfg);
    assertNotNull(p.getKeyInfoGenerator());
    assertNotNull(p.getCredentialResolver());
    assertNotNull(p.getKeyInfo());
    assertNotNull(p.getKeyInfoCredentialResolver());
    assertNotNull(p.getCredential());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:26,代码来源:SAML2ClientTests.java

示例9: getClient

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Override
protected IndirectClient getClient() {
    final OidcConfiguration configuration = new OidcConfiguration();
    configuration.setClientId("test");
    configuration.setSecret("secret");
    configuration.setDiscoveryURI("http://localhost:1941/.well-known/openid-configuration");
    if (flow == Flow.IMPLICIT_FLOW) {
        // AllowedGrantTypes = GrantTypes.ImplicitAndClientCredentials,
        configuration.setResponseType("id_token");
        configuration.setResponseMode("form_post");
        configuration.setUseNonce(true);
        logger.warn("For the implicit flow, copy / paste the form body parameters after a ? as the returned url");
    } else if (flow == Flow.IMPLICIT_FLOW_CLIENT_SIDE) { // this flow can not be used in fact (as data ae passed as anchor parameters, only on client side)
        // AllowedGrantTypes = GrantTypes.ImplicitAndClientCredentials,
        configuration.setResponseType("id_token");
        configuration.setUseNonce(true);
    /*} else if (flow == Flow.AUTHORIZATION_CODE) {
        AllowedGrantTypes = GrantTypes.CodeAndClientCredentials,*/
    } else if (flow == Flow.HYBRID_FLOW) {
        // AllowAccessTokensViaBrowser = true, AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
        configuration.setResponseType("code id_token token");
        configuration.setUseNonce(true);
    } else if (flow != Flow.AUTHORIZATION_CODE) {
        throw new TechnicalException("Unsupported flow for tests");
    }
    final OidcClient client = new OidcClient(configuration);
    client.setCallbackUrl(PAC4J_BASE_URL);
    return client;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:30,代码来源:RunIdentityServer4.java

示例10: requestServiceTicket

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
public TokenCredentials requestServiceTicket(final String serviceURL, final CasRestProfile profile) {
    HttpURLConnection connection = null;
    try {
        final URL endpointURL = new URL(getCasRestAuthenticator().getCasRestUrl());
        final URL ticketURL = new URL(endpointURL, endpointURL.getPath() + "/" + profile.getTicketGrantingTicketId());

        connection = HttpUtils.openPostConnection(ticketURL);
        final String payload = HttpUtils.encodeQueryParam("service", serviceURL);

        final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), HttpConstants.UTF8_ENCODING));
        out.write(payload);
        out.close();

        final int responseCode = connection.getResponseCode();
        if (responseCode == HttpConstants.OK) {
            try (final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), HttpConstants.UTF8_ENCODING))) {
                return new TokenCredentials(in.readLine(), getClass().getSimpleName());
            }
        }
        throw new TechnicalException("Service ticket request for `" + profile + "` failed: " +
                HttpUtils.buildHttpErrorMessage(connection));
    } catch (final IOException e) {
        throw new TechnicalException(e);
    } finally {
        HttpUtils.closeConnection(connection);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:28,代码来源:AbstractCasRestClient.java

示例11: oAuth2Authorization

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
/**
 * Authorization for Facebook and Google profiles.
 */
private static TriFunction<CommonProfile, Stream<JsonObject>, DatabaseService, Boolean> oAuth2Authorization() {
    return (p, stream, database) -> {
        boolean isAuthorized = stream.anyMatch(json -> json.getString(USERNAME.getName()).equals(p.getEmail()));
        if (isAuthorized) {
            return true;
        }
        if (p.getEmail() == null) {
            // TODO: 2.03.2017 redirect user to login with message: "you need to allow access to email"
            throw new TechnicalException("User email not found.");
        }
        return database.insertUser(p.getEmail(), genString(), p.getFirstName(), p.getFamilyName())
                .rxSetHandler().toBlocking().value() != null;
    };
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:18,代码来源:DatabaseAuthorizer.java

示例12: testDecryptMissingKey

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test
public void testDecryptMissingKey() throws ParseException, JOSEException {
    final RSAEncryptionConfiguration config = new RSAEncryptionConfiguration(buildKeyPair());
    config.setAlgorithm(JWEAlgorithm.RSA_OAEP);
    config.setMethod(EncryptionMethod.A128GCM);

    final JWT jwt = new PlainJWT(buildClaims());
    final String token = config.encrypt(jwt);
    final EncryptedJWT encryptedJwt = (EncryptedJWT) JWTParser.parse(token);
    final RSAEncryptionConfiguration config2 = new RSAEncryptionConfiguration();
    config2.setAlgorithm(JWEAlgorithm.RSA_OAEP);
    config2.setMethod(EncryptionMethod.A128GCM);
    TestsHelper.expectException(() -> config2.decrypt(encryptedJwt), TechnicalException.class, "privateKey cannot be null");
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:RSAEncryptionConfigurationTests.java

示例13: writeResponseContent

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
public void writeResponseContent(String contentToWrite) {
    try {
        response.getWriter().write(contentToWrite);
    } catch (IOException e) {
        throw new TechnicalException("error writing content out", e);
    }
}
 
开发者ID:codematix,项目名称:pippo-pac4j,代码行数:8,代码来源:PippoWebContext.java

示例14: retrieveRedirectAction

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
protected RedirectAction retrieveRedirectAction(final WebContext context) throws HttpAction {
    final String userIdentifier = getUser(context);
    CommonHelper.assertNotBlank("openIdUser", userIdentifier);

    try {
        // perform discovery on the user-supplied identifier
        final List discoveries = this.consumerManager.discover(userIdentifier);

        // attempt to associate with the OpenID provider
        // and retrieve one service endpoint for authentication
        final DiscoveryInformation discoveryInformation = this.consumerManager.associate(discoveries);

        // save discovery information in session
        context.setSessionAttribute(getDiscoveryInformationSessionAttributeName(), discoveryInformation);

        // create authentication request to be sent to the OpenID provider
        final AuthRequest authRequest = this.consumerManager.authenticate(discoveryInformation,
                computeFinalCallbackUrl(context));

        // create fetch request for attributes
        final FetchRequest fetchRequest = getFetchRequest();
        if (fetchRequest != null) {
            authRequest.addExtension(fetchRequest);
        }

        final String redirectionUrl = authRequest.getDestinationUrl(true);
        logger.debug("redirectionUrl: {}", redirectionUrl);
        return RedirectAction.redirect(redirectionUrl);
    } catch (final OpenIDException e) {
        throw new TechnicalException("OpenID exception", e);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:35,代码来源:BaseOpenIdClient.java

示例15: testMissingProfileCreator

import org.pac4j.core.exception.TechnicalException; //导入依赖的package包/类
@Test
public void testMissingProfileCreator() {
    final HeaderClient client = new HeaderClient(NAME, new SimpleTestTokenAuthenticator());
    client.setProfileCreator(null);
    TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN, CLIENT_NAME),
            MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null");
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:8,代码来源:HeaderClientTests.java


注:本文中的org.pac4j.core.exception.TechnicalException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。