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);
}
});
}
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));
}
}
}
Aggregations