org.usergrid.security.providers.PingIdentityProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of usergrid-services Show documentation
Show all versions of usergrid-services Show documentation
Service layer for Usergrid system.
package org.usergrid.security.providers;
import com.sun.jersey.api.client.WebResource;
import com.fasterxml.jackson.databind.JsonNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usergrid.management.ManagementService;
import org.usergrid.persistence.EntityManager;
import org.usergrid.persistence.Identifier;
import org.usergrid.persistence.entities.User;
import org.usergrid.security.tokens.exceptions.BadTokenException;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
/**
* Provider implementation for accessing Ping Identity
*
* @author zznate
*/
public class PingIdentityProvider extends AbstractProvider {
private Logger logger = LoggerFactory.getLogger(PingIdentityProvider.class);
private String apiUrl;
private String clientId;
private String clientSecret;
PingIdentityProvider(EntityManager entityManager, ManagementService managementService) {
super(entityManager, managementService);
}
@Override
public User createOrAuthenticate(String externalToken) throws BadTokenException {
Map pingUser = userFromResource(externalToken);
User user = null;
try {
user = managementService.getAppUserByIdentifier(entityManager.getApplication().getUuid(),
Identifier.fromEmail(pingUser.get("username").toString()));
} catch (Exception ex) {
ex.printStackTrace();
// TODO what to do here?
}
if ( user == null ) {
Map properties = new LinkedHashMap();
properties.putAll(pingUser);
properties.put("activated", true);
properties.put("confirmed",true);
try {
user = entityManager.create("user", User.class, properties);
} catch (Exception ex) {
throw new BadTokenException("Could not create user for that token", ex);
}
} else {
user.setProperty("expiration",pingUser.get("expiration"));
try {
entityManager.update(user);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return user;
}
@Override
void configure() {
try {
Map config = loadConfigurationFor();
if ( config != null ) {
apiUrl = (String)config.get("api_url");
clientId = (String)config.get("client_id");
clientSecret = (String)config.get("client_secret");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public Map
© 2015 - 2024 Weber Informatics LLC | Privacy Policy