cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.ClassCastException: com.sap.security.um.provider.neo.local.UserProviderImpl cannot be cast to com.sap.security.um.user.UserProvider

ChrisPaine
Active Contributor
0 Kudos

In attempting to read the user attributes  as per:

SAP HANA Cloud Platform

I get a cast exception. it seems that the local UserProvider is not compatible with the general definition (is not a subclass)


  private String determineUserAttribute(HttpServletRequest request, String userName, String attributeName) {

  String attributeValue = "";

  try {

  InitialContext ctx = new InitialContext();

  Object userProvider;

  userProvider = ctx.lookup("java:comp/env/user/Provider");

  UserProvider usrProv = (UserProvider) userProvider;

  attributeValue = usrProv.getUser(request.getRemoteUser()).getAttribute("firstname");

  } catch (UnsupportedUserAttributeException e) {

  logger.error("UnsupportedUserException", e);

  } catch (PersistenceException e) {

  logger.error("PersistenceException", e);

  } catch (NamingException e) {

  logger.error("NamingException", e);

  }

  return attributeValue;

  }

any suggestions on how to proceed or what I might be missing?

Using com.sap.security.um.user.UserManagementAccessor I always get a "User Management is not initialized" exception

Is there a requirement to use the Java EE Web runtime?

Thanks,

Chris

Accepted Solutions (1)

Accepted Solutions (1)

ChrisPaine
Active Contributor
0 Kudos

OK got it!

problem is that maven dependency

    <dependency>

      <groupId>com.sap.cloud</groupId>

      <artifactId>neo-java-web-api</artifactId>

      <version>2.15.7.3</version>

      <scope>provided</scope>

    </dependency>

needs to have the scope "provided" so that it doesn't get packed in the deployable and the runtime version of that api is provided by the platform not my application.

All working now!

Thanks for help!

Answers (3)

Answers (3)

ChrisPaine
Active Contributor
0 Kudos

Interestingly when I run the application on HCP rather than locally, I get:

HTTP Status 500 - Request processing failed; nested exception is java.lang.ClassCastException: class com.sap.security.um.provider.trust.internal.TrustUserProvider:java.net.URLClassLoader@2cdc7b4e incompatible with interface com.sap.security.um.user.UserProvider:WebappClassLoader

my definition of the interface  com.sap.security.um.user.UserProvider is coming from the neo-java-web-api-2.15.7.3.jar which is pulled from my maven dependency. (as deployed to Maven Central)  - The Central Repository Search Engine

seems like that version is incompatible with runtime versions?

Former Member
0 Kudos

Are you packaging the app with the jar containing the class com.sap.security.um.provider.neo.local.UserProvider or is it available in the runtime ?

ChrisPaine
Active Contributor
0 Kudos

Hi, believe the class is part of runtime as specific to local server implementation.

ChrisPaine
Active Contributor
0 Kudos

pinging security guru to see if he has an answer...

MartinRaepple
Active Participant
0 Kudos

Hi Chris,

I copy&pasted your code and tried on my local server (using SDK 1.x), and it worked without any issues. I only had to add the resource reference as described in the documentation and a local test user with the fistname attribute set.

Did you use a different sdk?

Cheers,

Martin

ChrisPaine
Active Contributor
0 Kudos

Hi Martin, have tried running the same code on Tomcat and Java Web,

installing the latest Tomcat sdk now - seems I was running a 2.12 sdk whereas latest is 2.15 (although latest on tools.hana.ondemand.com is 2.13

hopefully will work with later SDK.

will let you know,

ChrisPaine
Active Contributor
0 Kudos

Still getting same error with Tomcat SDK neo-java-web-sdk-2.15.7.3

Will try with java web sdk neo-java-web-sdk-1.68.22.2

ChrisPaine
Active Contributor
0 Kudos

Exact same error in java web.

have the lines:

  <resource-ref>

  <res-ref-name>user/Provider</res-ref-name>

  <res-type>com.sap.security.um.user.UserProvider</res-type>

  </resource-ref>

in my web.xml

and referencing latest sdk in my pom.xml

<dependency>
<groupId>com.sap.cloud</groupId>
<artifactId>neo-java-web-api</artifactId>
<version>${hcp.sdk.version}</version>
</dependency

<properties>
<hcp.jdk.version>1.7</hcp.jdk.version>
<hcp.sdk.version>2.15.7.3</hcp.sdk.version>
<org.springframework-version>3.2.4.RELEASE</org.springframework-version>
<org.springframework.data-version>1.3.0.RELEASE</org.springframework.data-version>
<org.aspectj-version>1.6.9</org.aspectj-version>
<org.apache.cxf-version>2.7.6</org.apache.cxf-version>
<org.slf4j-version>1.7.2</org.slf4j-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

perhaps the JDK version? although I can't see how that is going to cause an issue...

ChrisPaine
Active Contributor
0 Kudos

If I tick the enable security box on the tomcat server it refuses to start,

which _might_ have something to do with it, but I doubt it.