import java.util.Map.Entry;
import java.util.TreeMap;
-import org.apache.log4j.Logger;
+
import org.apache.log4j.PropertyConfigurator;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.onap.aaf.cadi.filter.MapBathConverter;
import org.onap.aaf.cadi.util.CSV;
import org.onap.aaf.misc.env.APIException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class AAFRealm extends AuthorizingRealm {
- final static Logger logger = Logger.getLogger(AAFRealm.class);
+ final static Logger logger = LoggerFactory.getLogger(AAFRealm.class);
public static final String AAF_REALM = "AAFRealm";
String cadi_prop_files = access.getProperty(Config.CADI_PROP_FILES);
if(cadi_prop_files==null) {
String msg = Config.CADI_PROP_FILES + " in VM Args is required to initialize AAFRealm.";
- access.log(Level.INIT,msg);
+ logger.info(msg);
throw new RuntimeException(msg);
} else {
- try {
- String log4jConfigFile = "./etc/org.ops4j.pax.logging.cfg";
- PropertyConfigurator.configure(log4jConfigFile);
- System.setOut(createLoggingProxy(System.out));
- System.setErr(createLoggingProxy(System.err));
- } catch(Exception e) {
- e.printStackTrace();
- }
- //System.out.println("Configuration done");
try {
acon = AAFCon.newInstance(access);
authn = acon.newAuthn();
}
}
idMap.put(oldID,newID);
+
}
} catch (IOException e) {
- logger.error(e.getMessage(), e);
+ logger.info(e.getMessage(), e);
}
}
} catch (APIException | CadiException | LocatorException e) {
supports = new HashSet<Class<? extends AuthenticationToken>>();
supports.add(UsernamePasswordToken.class);
}
- public static PrintStream createLoggingProxy(final PrintStream realPrintStream) {
- return new PrintStream(realPrintStream) {
- public void print(final String string) {
- realPrintStream.print(string);
- logger.info(string);
- }
- };
- }
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
- logger.debug("AAFRealm.doGetAuthenticationInfo :"+token);
-
+ logger.info("AAFRealm.doGetAuthenticationInfo :"+token);
final UsernamePasswordToken upt = (UsernamePasswordToken)token;
final String user = upt.getUsername();
String authUser = user;
int colon = bath.indexOf(':');
if(colon>=0) {
authUser = bath.substring(0, colon);
- authPassword = bath.substring(colon+1);
+ authPassword = bath.substring(colon+1);
}
}
} catch (IOException e) {
- logger.error(e.getMessage(), e);
+
+ logger.info(e.getMessage(), e);
+
}
}
String err;
err = authn.validate(authUser,authPassword);
} catch (IOException e) {
err = "Credential cannot be validated";
- logger.error(err, e);
+ logger.info(e.getMessage(), e);
}
if(err != null) {
- logger.debug(err);
+ logger.info(err);
throw new AuthenticationException(err);
}
@Override
protected void assertCredentialsMatch(AuthenticationToken atoken, AuthenticationInfo ai)throws AuthenticationException {
+
if(ai instanceof AAFAuthenticationInfo) {
if(!((AAFAuthenticationInfo)ai).matches(atoken)) {
throw new AuthenticationException("Credentials do not match");
+
}
+
} else {
throw new AuthenticationException("AuthenticationInfo is not an AAFAuthenticationInfo");
+
}
}
+
+
@Override
protected AAFAuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
- logger.debug("AAFRealm.doGetAuthenthorizationInfo");
Principal bait = (Principal)principals.getPrimaryPrincipal();
Principal newBait = bait;
if(idMap!=null) {
final String newID = idMap.get(bait.getName());
+ logger.info("Successful authentication attempt by " +bait.getName());
if(newID!=null) {
newBait = new Principal() {
@Override
}
List<Permission> pond = new ArrayList<>();
authz.fishAll(newBait,pond);
-
return new AAFAuthorizationInfo(access,bait,pond);
}