use of org.cloudfoundry.identity.uaa.mfa.exception.MfaAlreadyExistsException in project uaa by cloudfoundry.
the class MockMvcUtils method createMfaProvider.
public static MfaProvider createMfaProvider(ApplicationContext context, IdentityZone zone) {
String zoneId = zone.getId();
MfaProvider provider = new MfaProvider();
provider.setName(new RandomValueStringGenerator(5).generate().toLowerCase());
provider.setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
provider.setIdentityZoneId(zoneId);
provider.setConfig(new GoogleMfaProviderConfig());
provider.getConfig().setIssuer(zone.getName());
MfaProviderProvisioning provisioning = context.getBean(MfaProviderProvisioning.class);
try {
return provisioning.create(provider, zoneId);
} catch (MfaAlreadyExistsException x) {
return provisioning.update(provider, zoneId);
}
}
use of org.cloudfoundry.identity.uaa.mfa.exception.MfaAlreadyExistsException in project uaa by cloudfoundry.
the class MfaProviderEndpoints method deleteMfaProviderById.
@RequestMapping(value = "{id}", method = DELETE)
public ResponseEntity<MfaProvider> deleteMfaProviderById(@PathVariable String id) {
MfaProvider existing = mfaProviderProvisioning.retrieve(id, IdentityZoneHolder.get().getId());
MfaConfig currentMfaConfig = IdentityZoneHolder.get().getConfig().getMfaConfig();
if (currentMfaConfig.isEnabled() && currentMfaConfig.getProviderName().equals(existing.getName())) {
throw new MfaAlreadyExistsException("MFA provider is currently active on zone: " + IdentityZoneHolder.get().getId() + ". Please deactivate it from the zone or set another MFA provider");
}
publisher.publishEvent(new EntityDeletedEvent<>(existing, SecurityContextHolder.getContext().getAuthentication(), IdentityZoneHolder.getCurrentZoneId()));
return new ResponseEntity<>(existing, HttpStatus.OK);
}
use of org.cloudfoundry.identity.uaa.mfa.exception.MfaAlreadyExistsException in project uaa by cloudfoundry.
the class JdbcMfaProviderProvisioning method create.
@Override
public MfaProvider create(MfaProvider provider, String zoneId) {
mfaProviderValidator.validate(provider);
final String id = UUID.randomUUID().toString();
try {
jdbcTemplate.update(CREATE_PROVIDER_SQL, ps -> {
int pos = 1;
ps.setString(pos++, id);
ps.setString(pos++, provider.getName());
ps.setString(pos++, provider.getType().toValue());
ps.setString(pos++, JsonUtils.writeValueAsString(provider.getConfig()));
ps.setString(pos++, zoneId);
ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis()));
ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis()));
});
} catch (DuplicateKeyException e) {
String message = e.getMostSpecificCause().getMessage();
if (message.toUpperCase().contains("IDX_MFA_UNIQUE_NAME")) {
message = "An MFA Provider with that name already exists.";
}
throw new MfaAlreadyExistsException(message);
}
return retrieve(id, zoneId);
}
use of org.cloudfoundry.identity.uaa.mfa.exception.MfaAlreadyExistsException in project uaa by cloudfoundry.
the class JdbcMfaProviderProvisioning method update.
@Override
public MfaProvider update(MfaProvider provider, String zoneId) {
try {
jdbcTemplate.update(UPDATE_PROVIDER_SQL, ps -> {
int pos = 1;
ps.setString(pos++, provider.getName());
ps.setString(pos++, provider.getType().toValue());
ps.setString(pos++, JsonUtils.writeValueAsString(provider.getConfig()));
ps.setString(pos++, zoneId);
ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis()));
ps.setString(pos++, provider.getId().trim());
ps.setString(pos++, zoneId);
});
} catch (DuplicateKeyException e) {
String message = e.getMostSpecificCause().getMessage();
if (message.toUpperCase().contains("IDX_MFA_UNIQUE_NAME")) {
message = "An MFA Provider with that name already exists.";
}
throw new MfaAlreadyExistsException(message);
}
return retrieve(provider.getId(), zoneId);
}
Aggregations