Search in sources :

Example 1 with WildFlyElytronProvider

use of org.wildfly.security.WildFlyElytronProvider in project fuse-karaf by jboss-fuse.

the class CreateCredentialStoreTest method shouldCreateInitializeAndPersistCredentialStore.

@Test
public void shouldCreateInitializeAndPersistCredentialStore() throws IOException, GeneralSecurityException {
    final File storeFile = new File(tmp.getRoot(), "credential.store");
    final Map<String, String> attributes = Collections.singletonMap("location", storeFile.getAbsolutePath());
    final Provider provider = new WildFlyElytronProvider();
    final CredentialSource credentialSource = IdentityCredentials.NONE.withCredential(new PasswordCredential(ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, "test".toCharArray())));
    CreateCredentialStore.createCredentialStore(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE, attributes, credentialSource, provider);
    assertThat(storeFile).exists().isFile();
}
Also used : PasswordCredential(org.wildfly.security.credential.PasswordCredential) File(java.io.File) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) Provider(java.security.Provider) CredentialSource(org.wildfly.security.credential.source.CredentialSource) Test(org.junit.Test)

Example 2 with WildFlyElytronProvider

use of org.wildfly.security.WildFlyElytronProvider in project wildfly-swarm by wildfly-swarm.

the class ArqSecuredManagementInterfaceTest method testClient.

@Test
@RunAsClient
public void testClient() throws Exception {
    Security.addProvider(new WildFlyElytronProvider());
    ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990, new AuthCallbackHandler("TestRealm", "bob", "tacos!"));
    ModelNode response = client.execute(Operations.createOperation("whoami"));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    ModelNode result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    ModelNode identity = result.get("identity");
    assertThat(identity).isNotNull();
    assertThat(identity.isDefined()).isTrue();
    assertThat(identity.get("username").asString()).isEqualTo("bob");
    // ===
    response = client.execute(Operations.createOperation("read-resource", PathAddress.pathAddress(PathElement.pathElement("deployment", "*")).toModelNode()));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    assertThat(result.getType()).isEqualTo(ModelType.LIST);
    assertThat(result.asList()).hasSize(1);
    ModelNode myapp = result.get(0);
    assertThat(myapp).isNotNull();
    assertThat(myapp.isDefined()).isTrue();
    ModelNode myappResult = myapp.get("result");
    assertThat(myappResult).isNotNull();
    assertThat(myappResult.isDefined()).isTrue();
    assertThat(myappResult.get("name").asString()).isEqualTo("myapp.jar");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 3 with WildFlyElytronProvider

use of org.wildfly.security.WildFlyElytronProvider in project wildfly by wildfly.

the class ElytronRemoteOutboundConnectionTestCase method callIntermediateWhoAmI.

private String callIntermediateWhoAmI(boolean useRestrictedMethod) {
    AuthenticationConfiguration common = AuthenticationConfiguration.empty().useProviders(() -> new Provider[] { new WildFlyElytronProvider() }).setSaslMechanismSelector(SaslMechanismSelector.ALL);
    AuthenticationContext authCtxEmpty = AuthenticationContext.empty();
    final AuthenticationContext authCtx = authCtxEmpty.with(MatchRule.ALL, common);
    final EJBClientContext.Builder ejbClientBuilder = new EJBClientContext.Builder();
    ejbClientBuilder.addTransportProvider(new RemoteTransportProvider());
    final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
    connBuilder.setDestination(URI.create("remote+http://" + TestSuiteEnvironment.getServerAddressNode1() + ":8180"));
    ejbClientBuilder.addClientConnection(connBuilder.build());
    final EJBClientContext ejbCtx = ejbClientBuilder.build();
    AuthenticationContext.getContextManager().setThreadDefault(authCtx);
    EJBClientContext.getContextManager().setThreadDefault(ejbCtx);
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
    String result;
    try {
        InitialContext ctx = new InitialContext(props);
        String lookupName = "ejb:/outbound-module/IntermediateWhoAmI!org.jboss.as.test.manualmode.ejb.client.outbound.connection.security.WhoAmI";
        WhoAmI intermediate = (WhoAmI) ctx.lookup(lookupName);
        if (useRestrictedMethod) {
            result = intermediate.whoAmIRestricted();
        } else {
            result = intermediate.whoAmI();
        }
        ctx.close();
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    return result;
}
Also used : AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) OperationBuilder(org.jboss.as.controller.client.OperationBuilder) EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) InitialContext(org.jboss.as.naming.InitialContext) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) Provider(java.security.Provider) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) NamingException(javax.naming.NamingException) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider)

Example 4 with WildFlyElytronProvider

use of org.wildfly.security.WildFlyElytronProvider in project wildfly-swarm by wildfly-swarm.

the class ArqSecuredManagementInterfaceWithPropertiesTest method testClient.

@Test
@RunAsClient
public void testClient() throws Exception {
    Security.addProvider(new WildFlyElytronProvider());
    ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990, new AuthCallbackHandler("ManagementRealm", "bob", "tacos!"));
    ModelNode response = client.execute(Operations.createOperation("whoami"));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    ModelNode result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    ModelNode identity = result.get("identity");
    assertThat(identity).isNotNull();
    assertThat(identity.isDefined()).isTrue();
    assertThat(identity.get("username").asString()).isEqualTo("bob");
    // ===
    response = client.execute(Operations.createOperation("read-resource", PathAddress.pathAddress(PathElement.pathElement("deployment", "*")).toModelNode()));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    assertThat(result.getType()).isEqualTo(ModelType.LIST);
    assertThat(result.asList()).hasSize(1);
    ModelNode myapp = result.get(0);
    assertThat(myapp).isNotNull();
    assertThat(myapp.isDefined()).isTrue();
    ModelNode myappResult = myapp.get("result");
    assertThat(myappResult).isNotNull();
    assertThat(myappResult.isDefined()).isTrue();
    assertThat(myappResult.get("name").asString()).isEqualTo("myapp.jar");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 5 with WildFlyElytronProvider

use of org.wildfly.security.WildFlyElytronProvider in project wildfly-swarm by wildfly-swarm.

the class ArqSecuredManagementInterfaceTest method testClient.

@Test
@RunAsClient
public void testClient() throws Exception {
    Security.addProvider(new WildFlyElytronProvider());
    ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9990, new AuthCallbackHandler("ManagementRealm", "bob", "tacos!"));
    ModelNode response = client.execute(Operations.createOperation("whoami"));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    ModelNode result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    ModelNode identity = result.get("identity");
    assertThat(identity).isNotNull();
    assertThat(identity.isDefined()).isTrue();
    assertThat(identity.get("username").asString()).isEqualTo("bob");
    // ===
    response = client.execute(Operations.createOperation("read-resource", PathAddress.pathAddress(PathElement.pathElement("deployment", "*")).toModelNode()));
    assertThat(response.get("outcome").asString()).isEqualTo("success");
    result = response.get("result");
    assertThat(result).isNotNull();
    assertThat(result.isDefined()).isTrue();
    assertThat(result.getType()).isEqualTo(ModelType.LIST);
    assertThat(result.asList()).hasSize(1);
    ModelNode myapp = result.get(0);
    assertThat(myapp).isNotNull();
    assertThat(myapp.isDefined()).isTrue();
    ModelNode myappResult = myapp.get("result");
    assertThat(myappResult).isNotNull();
    assertThat(myappResult.isDefined()).isTrue();
    assertThat(myappResult.get("name").asString()).isEqualTo("ArqSecuredManagementInterfaceTest.war");
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) AuthCallbackHandler(org.wildfly.swarm.management.AuthCallbackHandler) ModelNode(org.jboss.dmr.ModelNode) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Aggregations

WildFlyElytronProvider (org.wildfly.security.WildFlyElytronProvider)10 Test (org.junit.Test)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)4 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)4 ModelNode (org.jboss.dmr.ModelNode)4 PasswordCredential (org.wildfly.security.credential.PasswordCredential)4 CredentialSource (org.wildfly.security.credential.source.CredentialSource)4 Provider (java.security.Provider)3 HashMap (java.util.HashMap)3 CredentialStore (org.wildfly.security.credential.store.CredentialStore)3 Password (org.wildfly.security.password.Password)3 ClearPassword (org.wildfly.security.password.interfaces.ClearPassword)3 ClearPasswordSpec (org.wildfly.security.password.spec.ClearPasswordSpec)3 File (java.io.File)2 Properties (java.util.Properties)2 PasswordFactory (org.wildfly.security.password.PasswordFactory)2 Collection (java.util.Collection)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 JMException (javax.management.JMException)1