Search in sources :

Example 6 with PasswordCredential

use of io.undertow.security.idm.PasswordCredential in project sigla-main by consiglionazionaledellericerche.

the class WSSEAuthenticationMechanism method authenticate.

/**
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@SuppressWarnings("unchecked")
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
    try {
        if (!securityContext.isAuthenticationRequired() || !exchange.getRequestURI().endsWith("WS"))
            return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
        final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
        HttpServletRequestImpl req = servletRequestContext.getOriginalRequest();
        AuthenticationRequestWrapper authenticationRequestWrapper = new AuthenticationRequestWrapper(req);
        servletRequestContext.setServletRequest(authenticationRequestWrapper);
        if (!authenticationRequestWrapper.isRequestPresent())
            return AuthenticationMechanismOutcome.AUTHENTICATED;
        SOAPMessage message = MessageFactory.newInstance().createMessage(null, authenticationRequestWrapper.getInputStream());
        SOAPPart sp = message.getSOAPPart();
        SOAPEnvelope envelope = sp.getEnvelope();
        SOAPHeader header = envelope.getHeader();
        if (header != null) {
            Name sName;
            // variable for user name and password
            String userName = null;
            String password = null;
            // look for authentication header element inside the HEADER block
            Iterator<SOAPElement> childElems = header.getChildElements();
            SOAPElement child = extractUserNameInfo(childElems);
            // get an iterator on child elements of SOAP element
            Iterator<SOAPElement> childElemsUserNameToken = child.getChildElements();
            // loop through child elements
            while (childElemsUserNameToken.hasNext()) {
                // get next child element
                Object elem = childElemsUserNameToken.next();
                if (elem instanceof SOAPElement) {
                    child = (SOAPElement) elem;
                    // get the name of SOAP element
                    sName = child.getElementName();
                    // get the value of username element
                    if (USERNAME_STRING.equalsIgnoreCase(sName.getLocalName())) {
                        userName = child.getValue();
                    } else if (PASSWORD_STRING.equalsIgnoreCase(sName.getLocalName())) {
                        password = child.getValue();
                    }
                }
            }
            final AuthenticationMechanismOutcome result;
            IdentityManager idm = getIdentityManager(securityContext);
            if (password == null)
                return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
            PasswordCredential credential = new PasswordCredential(password.toCharArray());
            Account account = idm.verify(userName, credential);
            if (account != null) {
                securityContext.authenticationComplete(account, name, false);
                result = AuthenticationMechanismOutcome.AUTHENTICATED;
            } else {
                securityContext.authenticationFailed(MESSAGES.authenticationFailed(userName), name);
                result = AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
            }
            return result;
        }
    } catch (IOException | SOAPException e1) {
        return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
    }
    return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
Also used : Account(io.undertow.security.idm.Account) IdentityManager(io.undertow.security.idm.IdentityManager) PasswordCredential(io.undertow.security.idm.PasswordCredential) ServletRequestContext(io.undertow.servlet.handlers.ServletRequestContext) IOException(java.io.IOException) HttpServletRequestImpl(io.undertow.servlet.spec.HttpServletRequestImpl)

Example 7 with PasswordCredential

use of io.undertow.security.idm.PasswordCredential in project droolsjbpm-integration by kiegroup.

the class KieServerRouterCommandTest method testDefaultIdentityServiceFromMain.

@Test
public void testDefaultIdentityServiceFromMain() throws Exception {
    // add instance
    KieServerRouter.main(new String[] { "-" + KieServerRouter.CMD_ADD_USER, "mainId", "mainpw" });
    IdentityService service = router.getIdentityService();
    Assert.assertNotNull(service.verify("mainId", new PasswordCredential("mainpw".toCharArray())));
    // remove instance
    KieServerRouter.main(new String[] { "-" + KieServerRouter.CMD_REMOVE_USER, "mainId", "mainpw" });
    Assert.assertNull(service.verify("mainId", new PasswordCredential("mainpw".toCharArray())));
}
Also used : IdentityService(org.kie.server.router.identity.IdentityService) PasswordCredential(io.undertow.security.idm.PasswordCredential) Test(org.junit.Test)

Example 8 with PasswordCredential

use of io.undertow.security.idm.PasswordCredential in project mangooio by svenkubiak.

the class IdentityTest method testValidVerify.

@Test
void testValidVerify() {
    // given
    Identity identity = new Identity("foo", "bar");
    PasswordCredential credential = new PasswordCredential(password);
    // when
    Account account = identity.verify("foo", credential);
    // then
    assertThat(account, not(nullValue()));
    assertThat(account.getPrincipal().getName(), equalTo("foo"));
}
Also used : Account(io.undertow.security.idm.Account) PasswordCredential(io.undertow.security.idm.PasswordCredential) Test(org.junit.jupiter.api.Test)

Example 9 with PasswordCredential

use of io.undertow.security.idm.PasswordCredential in project org.ops4j.pax.web by ops4j.

the class PropertiesIdentityManager method verify.

@Override
public Account verify(String id, Credential credential) {
    if (credential instanceof PasswordCredential) {
        char[] password = ((PasswordCredential) credential).getPassword();
        String userData = config.get(id);
        if (userData != null) {
            List<String> pieces = Arrays.asList(userData.split(","));
            if (pieces.get(0).equals(new String(password))) {
                Principal principal = new SimplePrincipal(id);
                Set<String> roles = new HashSet<>(pieces.subList(1, pieces.size()));
                return new AccountImpl(principal, roles);
            }
        }
    }
    return null;
}
Also used : PasswordCredential(io.undertow.security.idm.PasswordCredential) Principal(java.security.Principal) HashSet(java.util.HashSet)

Example 10 with PasswordCredential

use of io.undertow.security.idm.PasswordCredential in project openremote by openremote.

the class BasicIdentityProvider method secureDeployment.

@Override
public void secureDeployment(DeploymentInfo deploymentInfo) {
    LoginConfig loginConfig = new LoginConfig("OpenRemote");
    // Make it silent to prevent 401 WWW-Authenticate modal dialog
    deploymentInfo.addAuthenticationMechanism("BASIC-FIX", BasicFixAuthenticationMechanism.FACTORY);
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC-FIX", Collections.singletonMap("silent", "true")));
    deploymentInfo.setLoginConfig(loginConfig);
    deploymentInfo.setIdentityManager(new IdentityManager() {

        @Override
        public Account verify(Account account) {
            return null;
        }

        @Override
        public Account verify(String id, Credential credential) {
            if (credential instanceof PasswordCredential) {
                PasswordCredential passwordCredential = (PasswordCredential) credential;
                return verifyAccount(id, passwordCredential.getPassword());
            } else {
                LOG.fine("Verification of '" + id + "' failed, no password credentials found, but: " + credential);
                return null;
            }
        }

        @Override
        public Account verify(Credential credential) {
            return null;
        }
    });
}
Also used : Account(io.undertow.security.idm.Account) IdentityManager(io.undertow.security.idm.IdentityManager) Credential(io.undertow.security.idm.Credential) PasswordCredential(io.undertow.security.idm.PasswordCredential) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) LoginConfig(io.undertow.servlet.api.LoginConfig) PasswordCredential(io.undertow.security.idm.PasswordCredential)

Aggregations

PasswordCredential (io.undertow.security.idm.PasswordCredential)17 Account (io.undertow.security.idm.Account)8 IdentityManager (io.undertow.security.idm.IdentityManager)4 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)2 Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 IdentityService (org.kie.server.router.identity.IdentityService)2 Sponge (com.iota.iri.hash.Sponge)1 User (com.networknt.oauth.cache.model.User)1 Credential (io.undertow.security.idm.Credential)1 FormData (io.undertow.server.handlers.form.FormData)1 FormDataParser (io.undertow.server.handlers.form.FormDataParser)1 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)1 LoginConfig (io.undertow.servlet.api.LoginConfig)1 ServletRequestContext (io.undertow.servlet.handlers.ServletRequestContext)1 HttpServletRequestImpl (io.undertow.servlet.spec.HttpServletRequestImpl)1 HttpString (io.undertow.util.HttpString)1