Skip to main content
Version: 3

Custom implementation

While using SAML SSO to log in to the system, the SAML response can be interpreted to change the default behavior to make the user log in to a specific company/partner in a specific role. Adeptia Connect allows you to do this by implementing a custom class to read and authenticate the users information. You need to define a new Java class and place that in the customClassesfolder.

This option lets you:

  • Access custom attributes and relay state information present in the SAML response
  • Provide a specific company/partner and also a specific role for logged in user
  • Provide a redirect URL to which user will be redirected after successful login

Follow the steps below to create the custom class:

  1. Create a new Java class that implements the below interface.

    InformationThis interface provides the ability to define a custom implementation for providing the authenticated user information.

    SAML SSO Authentication Interface SAML SSO Authentication Interface

Code

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.opensaml.saml2.core.Attribute;
import org.springframework.security.core.Authentication;
import org.springframework.security.saml.SAMLCredential;

import com.adeptia.indigo.security.AuthUtil;
import com.adeptia.indigo.security.IndigoGroup;
import com.adeptia.indigo.security.IndigoUser;
import com.adeptia.indigo.security.saml.SAMLSSOAuthenticationUserDetails;
import com.adeptia.indigo.security.saml.SubjectInfo;

public class SAMLUserDetailsImpl implements SAMLSSOAuthenticationUserDetails{

@SuppressWarnings("unchecked")
@Override
public SubjectInfo getSubjectInfo(Authentication authentication) {

SubjectInfo subjectInfo = new SubjectInfo();
subjectInfo.setUser(user);
subjectInfo.setGroupId(group);
subjectInfo.setPartner(partnerName);
subjectInfo.setRole(roleName);
return subjectInfo;


}

@Override
public String getRedirectUrl(Authentication authentication) {
return "home";
}

@Override
public Map getAttributes(Authentication authentication) {
SAMLCredential credential = (SAMLCredential) authentication.getCredentials();
Map userAttributesMap = new HashMap();
userAttributesMap.put("RelayState", credential.getRelayState());
List userAttributes = credential.getAttributes();
for (Attribute attribute : userAttributes) {
String
userAttributesMap.put(name, credential.getAttributeAsString(name));
}
return userAttributesMap;
}

}

Expand 'SAML User Details IMPL' for an example of implementation class:

SAML User Details IMPL SAML User Details IMPL

Code

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.opensaml.saml2.core.Attribute;
import org.springframework.security.core.Authentication;
import org.springframework.security.saml.SAMLCredential;

import com.adeptia.indigo.security.AuthUtil;
import com.adeptia.indigo.security.IndigoGroup;
import com.adeptia.indigo.security.IndigoUser;
import com.adeptia.indigo.security.saml.SAMLSSOAuthenticationUserDetails;
import com.adeptia.indigo.security.saml.SubjectInfo;

public class SAMLUserDetailsImpl implements SAMLSSOAuthenticationUserDetails{

@SuppressWarnings("unchecked")
@Override
public SubjectInfo getSubjectInfo(Authentication authentication) {

SubjectInfo subjectInfo = new SubjectInfo();
subjectInfo.setUser(user);
subjectInfo.setGroupId(group);
subjectInfo.setPartner(partnerName);
subjectInfo.setRole(roleName);
return subjectInfo;


}

@Override
public String getRedirectUrl(Authentication authentication) {
return "home";
}

@Override
public Map getAttributes(Authentication authentication) {
SAMLCredential credential = (SAMLCredential) authentication.getCredentials();
Map userAttributesMap = new HashMap();
userAttributesMap.put("RelayState", credential.getRelayState());
List userAttributes = credential.getAttributes();
for (Attribute attribute : userAttributes) {
String
userAttributesMap.put(name, credential.getAttributeAsString(name));
}
return userAttributesMap;
}

}
  1. Compile the above class and place it in customClassesfolder.

  2. Go to …< ConnectServerInstallFolder> \AdeptiaServer\ServerKernel\etclocation.

    1. Open applicationConfig.xml file.
    2. Search for bean id 'samlSSOAuthenticationUserDetails' in the xml file.
    3. Update the class value with your own custom class name.
    InformationRestart the Adeptia services to bring the changes into effect.

You may be interested in...

What's new​
Best practices​
Frequently asked questions​
Adeptia Connect APIs​