Skip to content

Changewatchers #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ target/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

/.classpath
/.project
/.settings/
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.activestack</groupId>
<groupId>org.activestack</groupId>
<artifactId>syncengine</artifactId>
<version>1.1.15-SNAPSHOT</version>

Expand All @@ -14,6 +14,7 @@
<slf4j.version>1.6.1</slf4j.version>
<project.http.version>1.19.0</project.http.version>
<project.oauth.version>1.19.0</project.oauth.version>
<mockito-core.version>1.9.5</mockito-core.version>
</properties>

<dependencies>
Expand All @@ -33,6 +34,12 @@
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.codehaus.jackson</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public void setupUserRoles(String userId, List<ServiceUser> serviceUserList) thr
Boolean isInaccurateList = false;
for (ServiceUser nextServiceUser : serviceUserList) {
if (!nextServiceUser.getAreRoleNamesAccurate()) {
log.debug("Ignoring role names from " + nextServiceUser.getAuthProvider().toString());
log.debug("Ignoring role names from " + nextServiceUser.getAuthProviderID().toString());
isInaccurateList = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.percero.agents.auth.services;

import com.percero.agents.auth.vo.AuthProvider;
import com.percero.agents.auth.vo.ServiceIdentifier;
import com.percero.agents.auth.vo.ServiceOrganization;
import com.percero.agents.auth.vo.ServiceUser;
import com.percero.util.RandomStringGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
* Created by jonnysamps on 8/14/15.
*/
@Component
public class AnonAuthProvider implements IAuthProvider {
private static String ID = "anonymous";

@Autowired
@Value("$pf{anonAuth.enabled:false}")
Boolean anonAuthEnabled = false;
@Autowired @Value("$pf{anonAuth.code:ANON}")
String anonAuthCode = "ANON";
@Autowired @Value("$pf{anonAuth.roleNames:}")
String anonAuthRoleNames = "";

public String getID() {
return ID;
}

public ServiceUser authenticate(String credential) {
ServiceUser serviceUser = new ServiceUser();
serviceUser.setFirstName("ANON");
serviceUser.setLastName("ANON");
serviceUser.setId("ANON");
serviceUser.setAuthProviderID(AuthProvider.ANON.toString());

List<String> roles = new ArrayList<String>();
String[] roleNames = anonAuthRoleNames.split(",");
for(int i = 0; i < roleNames.length; i++) {
if (roleNames[i] != null && !roleNames[i].isEmpty())
roles.add(roleNames[i]);
}
serviceUser.setRoleNames(roles);
serviceUser.setAreRoleNamesAccurate(true);

String email = "anonymous@activestack.io";
serviceUser.getEmails().add(email);
serviceUser.getIdentifiers().add(new ServiceIdentifier("email", email));

return serviceUser;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.percero.agents.auth.services;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
* Class is the registration point for IAuthProviders.
*/
@Component
public class AuthProviderRegistry {
private static Logger logger = Logger.getLogger(AuthProviderRegistry.class);
private Map<String, IAuthProvider> providerMap = new HashMap<String, IAuthProvider>();

/**
* Intended to be a default registration point for all IAuthProviders in the application context
* @param providers
*/
@Autowired(required = false)
public void setProviders(Collection<IAuthProvider> providers){
for(IAuthProvider provider : providers){
this.addProvider(provider);
}
}

/**
* Add a provider to the registry
* @param provider
*/
public void addProvider(IAuthProvider provider){
if(providerMap.containsKey(provider.getID()))
logger.warn("Non-unique auth provider ID: "+provider.getID());

providerMap.put(provider.getID(), provider);
}

/**
* Find a provider by ID
* @param ID
* @return
*/
public IAuthProvider getProvider(String ID){
return providerMap.get(ID);
}

/**
* Returns true if registry has a provider registered for this key
* @param ID
* @return
*/
public boolean hasProvider(String ID){
return providerMap.containsKey(ID);
}
}
Loading