Search in sources :

Example 16 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class SAML2ITCase method validateIdpInitiatedLoginResponseFailure.

// Make sure that the IdP initiated case is only supported when "supportUnsolicited" is true for that IdP
@Test
public void validateIdpInitiatedLoginResponseFailure() throws Exception {
    assumeTrue(SAML2SPDetector.isSAML2SPAvailable());
    SAML2SPService saml2Service = anonymous.getService(SAML2SPService.class);
    // Create a SAML Response using WSS4J
    SAML2ReceivedResponseTO response = new SAML2ReceivedResponseTO();
    response.setSpEntityID("http://recipient.apache.org/");
    response.setUrlContext("saml2sp");
    org.opensaml.saml.saml2.core.Response samlResponse = createResponse(null, true, SAML2Constants.CONF_BEARER, "urn:org:apache:cxf:fediz:idp:realm-A");
    Document doc = DOMUtils.newDocument();
    Element responseElement = OpenSAMLUtil.toDom(samlResponse, doc);
    String responseStr = DOM2Writer.nodeToString(responseElement);
    // Validate the SAML Response
    response.setSamlResponse(Base64.getEncoder().encodeToString(responseStr.getBytes()));
    response.setRelayState("idpInitiated");
    try {
        saml2Service.validateLoginResponse(response);
        fail("Failure expected on an unsolicited login");
    } catch (SyncopeClientException e) {
        assertNotNull(e);
    }
}
Also used : SAML2SPService(org.apache.syncope.common.rest.api.service.SAML2SPService) SAML2ReceivedResponseTO(org.apache.syncope.common.lib.to.SAML2ReceivedResponseTO) Element(org.w3c.dom.Element) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test)

Example 17 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class UserITCase method customPolicyRules.

@Test
public void customPolicyRules() {
    // Using custom policy rules with application/xml requires to overwrite
    // org.apache.syncope.common.lib.policy.AbstractAccountRuleConf's and / or
    // org.apache.syncope.common.lib.policy.AbstractPasswordRuleConf's
    // @XmlSeeAlso - the power of JAXB :-/
    assumeTrue(MediaType.APPLICATION_JSON_TYPE.equals(clientFactory.getContentType().getMediaType()));
    ImplementationTO implementationTO = new ImplementationTO();
    implementationTO.setKey("TestAccountRuleConf" + UUID.randomUUID().toString());
    implementationTO.setEngine(ImplementationEngine.JAVA);
    implementationTO.setType(ImplementationType.ACCOUNT_RULE);
    implementationTO.setBody(POJOHelper.serialize(new TestAccountRuleConf()));
    Response response = implementationService.create(implementationTO);
    implementationTO.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    AccountPolicyTO accountPolicy = new AccountPolicyTO();
    accountPolicy.setDescription("Account Policy with custom rules");
    accountPolicy.getRules().add(implementationTO.getKey());
    accountPolicy = createPolicy(PolicyType.ACCOUNT, accountPolicy);
    assertNotNull(accountPolicy);
    implementationTO = new ImplementationTO();
    implementationTO.setKey("TestPasswordRuleConf" + UUID.randomUUID().toString());
    implementationTO.setEngine(ImplementationEngine.JAVA);
    implementationTO.setType(ImplementationType.PASSWORD_RULE);
    implementationTO.setBody(POJOHelper.serialize(new TestPasswordRuleConf()));
    response = implementationService.create(implementationTO);
    implementationTO.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    PasswordPolicyTO passwordPolicy = new PasswordPolicyTO();
    passwordPolicy.setDescription("Password Policy with custom rules");
    passwordPolicy.getRules().add(implementationTO.getKey());
    passwordPolicy = createPolicy(PolicyType.PASSWORD, passwordPolicy);
    assertNotNull(passwordPolicy);
    RealmTO realm = realmService.list("/even/two").get(0);
    String oldAccountPolicy = realm.getAccountPolicy();
    realm.setAccountPolicy(accountPolicy.getKey());
    String oldPasswordPolicy = realm.getPasswordPolicy();
    realm.setPasswordPolicy(passwordPolicy.getKey());
    realmService.update(realm);
    try {
        UserTO user = getUniqueSampleTO("custompolicyrules@syncope.apache.org");
        user.setRealm(realm.getFullPath());
        try {
            createUser(user);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.InvalidUser, e.getType());
            assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword"));
        }
        user.setPassword(user.getPassword() + "XXX");
        try {
            createUser(user);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.InvalidUser, e.getType());
            assertTrue(e.getElements().iterator().next().startsWith("InvalidUsername"));
        }
        user.setUsername("YYY" + user.getUsername());
        user = createUser(user).getEntity();
        assertNotNull(user);
    } finally {
        realm.setAccountPolicy(oldAccountPolicy);
        realm.setPasswordPolicy(oldPasswordPolicy);
        realmService.update(realm);
        policyService.delete(PolicyType.PASSWORD, passwordPolicy.getKey());
        policyService.delete(PolicyType.ACCOUNT, accountPolicy.getKey());
    }
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) TestPasswordRuleConf(org.apache.syncope.fit.core.reference.TestPasswordRuleConf) UserTO(org.apache.syncope.common.lib.to.UserTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AccountPolicyTO(org.apache.syncope.common.lib.policy.AccountPolicyTO) TestAccountRuleConf(org.apache.syncope.fit.core.reference.TestAccountRuleConf) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Test(org.junit.jupiter.api.Test)

Example 18 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class NotificationITCase method issueSYNCOPE974.

@Test
public void issueSYNCOPE974() {
    NotificationTO notificationTO = new NotificationTO();
    notificationTO.setRecipientAttrName("email");
    notificationTO.setSelfAsRecipient(false);
    notificationTO.setSender("sender@ukr.net");
    notificationTO.setSubject("subject 21");
    notificationTO.setTemplate("requestPasswordReset");
    notificationTO.setTraceLevel(TraceLevel.ALL);
    notificationTO.setActive(true);
    try {
        notificationService.create(notificationTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
        assertTrue(e.getMessage().contains("events"));
    }
}
Also used : NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 19 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class NotificationITCase method issueSYNCOPE83.

@Test
public void issueSYNCOPE83() {
    NotificationTO notificationTO = buildNotificationTO();
    notificationTO.setSelfAsRecipient(true);
    NotificationTO actual = null;
    try {
        Response response = notificationService.create(notificationTO);
        actual = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
    } catch (SyncopeClientException e) {
        assertNotNull(e);
    }
    assertNotNull(actual);
    assertNotNull(actual.getKey());
    notificationTO.setKey(actual.getKey());
    assertEquals(actual, notificationTO);
}
Also used : Response(javax.ws.rs.core.Response) NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotificationService(org.apache.syncope.common.rest.api.service.NotificationService) Test(org.junit.jupiter.api.Test)

Example 20 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class NotificationITCase method issueSYNCOPE445.

@Test
public void issueSYNCOPE445() {
    NotificationTO notificationTO = buildNotificationTO();
    notificationTO.getStaticRecipients().add("syncope445@syncope.apache.org");
    NotificationTO actual = null;
    try {
        Response response = notificationService.create(notificationTO);
        actual = getObject(response.getLocation(), NotificationService.class, NotificationTO.class);
    } catch (SyncopeClientException e) {
        assertNotNull(e);
    }
    assertNotNull(actual);
    assertNotNull(actual.getKey());
    notificationTO.setKey(actual.getKey());
    assertEquals(actual, notificationTO);
}
Also used : Response(javax.ws.rs.core.Response) NotificationTO(org.apache.syncope.common.lib.to.NotificationTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotificationService(org.apache.syncope.common.rest.api.service.NotificationService) Test(org.junit.jupiter.api.Test)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11