Search in sources :

Example 1 with AuthenticationClient

use of com.okta.authn.sdk.client.AuthenticationClient in project okta-auth-java by okta.

the class ExampleApplication method configureJersey.

private void configureJersey(JerseyEnvironment jersey) {
    // Load any resource in the resources package
    String baseResourcePackage = getClass().getPackage().getName() + ".resources";
    jersey.packages(baseResourcePackage);
    AuthenticationClient client = AuthenticationClients.builder().build();
    // use @Inject to bind the DAOs
    jersey.register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(new DefaultStormtrooperDao()).to(StormtrooperDao.class);
            bind(new DefaultTieCraftDao()).to(TieCraftDao.class);
            bind(client).to(AuthenticationClient.class);
        }
    });
}
Also used : DefaultTieCraftDao(com.okta.authn.sdk.example.dao.DefaultTieCraftDao) DefaultStormtrooperDao(com.okta.authn.sdk.example.dao.DefaultStormtrooperDao) StormtrooperDao(com.okta.authn.sdk.example.dao.StormtrooperDao) DefaultStormtrooperDao(com.okta.authn.sdk.example.dao.DefaultStormtrooperDao) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) TieCraftDao(com.okta.authn.sdk.example.dao.TieCraftDao) DefaultTieCraftDao(com.okta.authn.sdk.example.dao.DefaultTieCraftDao) AuthenticationClient(com.okta.authn.sdk.client.AuthenticationClient)

Example 2 with AuthenticationClient

use of com.okta.authn.sdk.client.AuthenticationClient in project OpenUnison by TremoloSecurity.

the class OktaInsert method bind.

@Override
public void bind(BindInterceptorChain chain, DistinguishedName dn, Password pwd, LDAPConstraints constraints) throws LDAPException {
    if (!this.users) {
        throw new LDAPException("Unsupported", LDAPException.UNWILLING_TO_PERFORM, LDAPException.resultCodeToString(LDAPException.UNWILLING_TO_PERFORM));
    }
    RDN rdn = (RDN) dn.getDN().getRDNs().get(0);
    if (!rdn.getType().equalsIgnoreCase("login")) {
        throw new LDAPException("Unsupported", LDAPException.UNWILLING_TO_PERFORM, LDAPException.resultCodeToString(LDAPException.UNWILLING_TO_PERFORM));
    }
    String userid = rdn.getValue();
    userid = userid.replace("\\+", "+");
    OktaTarget os = null;
    try {
        os = (OktaTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.target).getProvider();
    } catch (ProvisioningException e1) {
        logger.error("Could not retrieve kubernetes target", e1);
        throw new LDAPException("Could not connect to kubernetes", LDAPException.OPERATIONS_ERROR, LDAPException.resultCodeToString(LDAPException.OPERATIONS_ERROR));
    }
    AuthenticationClient client = AuthenticationClients.builder().setOrgUrl(os.getDomain()).build();
    String pwdStr = new String(pwd.getValue());
    LDAPException ldapRes;
    try {
        OktaAuthResponse authResp = new OktaAuthResponse(userid);
        client.authenticate(userid, pwdStr.toCharArray(), "", authResp);
        if (authResp.getResult() != null) {
            throw authResp.getResult();
        }
    } catch (AuthenticationException e) {
        if (e.getStatus() == 401) {
            throw new LDAPException("Could not authenticate", LDAPException.INVALID_CREDENTIALS, LDAPException.resultCodeToString(LDAPException.INVALID_CREDENTIALS));
        } else {
            logger.error("Unexpected authenticaiton error", e);
            throw new LDAPException("Unexpected authentication error", LDAPException.OPERATIONS_ERROR, LDAPException.resultCodeToString(LDAPException.OPERATIONS_ERROR));
        }
    }
}
Also used : LDAPException(com.novell.ldap.LDAPException) AuthenticationException(com.okta.authn.sdk.AuthenticationException) OktaTarget(com.tremolosecurity.unison.okta.provisioning.OktaTarget) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) AuthenticationClient(com.okta.authn.sdk.client.AuthenticationClient) RDN(com.novell.ldap.util.RDN)

Aggregations

AuthenticationClient (com.okta.authn.sdk.client.AuthenticationClient)2 LDAPException (com.novell.ldap.LDAPException)1 RDN (com.novell.ldap.util.RDN)1 AuthenticationException (com.okta.authn.sdk.AuthenticationException)1 DefaultStormtrooperDao (com.okta.authn.sdk.example.dao.DefaultStormtrooperDao)1 DefaultTieCraftDao (com.okta.authn.sdk.example.dao.DefaultTieCraftDao)1 StormtrooperDao (com.okta.authn.sdk.example.dao.StormtrooperDao)1 TieCraftDao (com.okta.authn.sdk.example.dao.TieCraftDao)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 OktaTarget (com.tremolosecurity.unison.okta.provisioning.OktaTarget)1 AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)1