Search in sources :

Example 1 with Userdata

use of de.ids_mannheim.korap.user.Userdata in project Kustvakt by KorAP.

the class ShibbolethUserController method updateSettings.

@Deprecated
@POST
@Path("settings")
@Consumes({ MediaType.APPLICATION_JSON })
@ResourceFilters({ AuthenticationFilter.class, PiwikFilter.class, BlockingFilter.class })
public Response updateSettings(@Context SecurityContext context, @Context Locale locale, Map settings) {
    TokenContext ctx = (TokenContext) context.getUserPrincipal();
    if (settings == null)
        return Response.notModified().build();
    try {
        User user = controller.getUser(ctx.getUsername());
        if (User.UserFactory.isDemo(ctx.getUsername()))
            return Response.notModified().build();
        Userdata data = controller.getUserData(user, UserSettingProcessor.class);
        // todo: check setting only within the scope of user settings permissions; not foundry range. Latter is part of
        // frontend which only displays available foundries and
        // SecurityManager.findbyId(us.getDefaultConstfoundry(), user, Foundry.class);
        // SecurityManager.findbyId(us.getDefaultLemmafoundry(), user, Foundry.class);
        // SecurityManager.findbyId(us.getDefaultPOSfoundry(), user, Foundry.class);
        // SecurityManager.findbyId(us.getDefaultRelfoundry(), user, Foundry.class);
        Userdata new_data = new UserSettingProcessor(user.getId());
        new_data.readQuietly((Map<String, Object>) settings, false);
        data.update(new_data);
        controller.updateUserData(data);
    } catch (KustvaktException e) {
        jlog.error("Exception encountered!", e);
        throw kustvaktResponseHandler.throwit(e);
    }
    return Response.ok().build();
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) User(de.ids_mannheim.korap.user.User) KorAPUser(de.ids_mannheim.korap.user.KorAPUser) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) Userdata(de.ids_mannheim.korap.user.Userdata) UserSettingProcessor(de.ids_mannheim.korap.user.UserSettingProcessor) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with Userdata

use of de.ids_mannheim.korap.user.Userdata in project Kustvakt by KorAP.

the class KustvaktAuthenticationManagerTest method testUserdetailsGet.

@Test
@Ignore
public void testUserdetailsGet() throws KustvaktException {
    User user = authenticationManager.getUser((String) KustvaktConfiguration.KUSTVAKT_USER.get(Attributes.USERNAME));
    Userdata data = authenticationManager.getUserData(user, UserDetails.class);
    assertNotNull(data);
}
Also used : User(de.ids_mannheim.korap.user.User) KorAPUser(de.ids_mannheim.korap.user.KorAPUser) Userdata(de.ids_mannheim.korap.user.Userdata) Ignore(org.junit.Ignore) Test(org.junit.Test) BeanConfigTest(de.ids_mannheim.korap.config.BeanConfigTest)

Example 3 with Userdata

use of de.ids_mannheim.korap.user.Userdata in project Kustvakt by KorAP.

the class KustvaktAuthenticationManagerTest method testUsersettingsGet.

@Test
@Ignore
public void testUsersettingsGet() throws KustvaktException {
    User user = authenticationManager.getUser((String) KustvaktConfiguration.KUSTVAKT_USER.get(Attributes.USERNAME));
    Userdata data = authenticationManager.getUserData(user, UserSettingProcessor.class);
    assertNotNull(data);
}
Also used : User(de.ids_mannheim.korap.user.User) KorAPUser(de.ids_mannheim.korap.user.KorAPUser) Userdata(de.ids_mannheim.korap.user.Userdata) Ignore(org.junit.Ignore) Test(org.junit.Test) BeanConfigTest(de.ids_mannheim.korap.config.BeanConfigTest)

Example 4 with Userdata

use of de.ids_mannheim.korap.user.Userdata in project Kustvakt by KorAP.

the class JWTSigner method signContent.

public SignedJWT signContent(User user, Map<String, Object> attr, int ttl) {
    String scopes;
    Builder csBuilder = new JWTClaimsSet.Builder();
    csBuilder.issuer(this.issuer.toString());
    if ((scopes = (String) attr.get(Attributes.SCOPE)) != null) {
        Userdata data = new GenericUserData();
        data.readQuietly(attr, false);
        Scopes claims = Scopes.mapScopes(scopes, data);
        Map<String, Object> map = claims.toMap();
        for (String key : map.keySet()) {
            csBuilder.claim(key, map.get(key));
        }
    }
    csBuilder.subject(user.getUsername());
    if (attr.get(Attributes.CLIENT_ID) != null) {
        csBuilder.audience((String) attr.get(Attributes.CLIENT_ID));
    }
    csBuilder.expirationTime(TimeUtils.getNow().plusSeconds(ttl).toDate());
    csBuilder.claim(Attributes.AUTHENTICATION_TIME, attr.get(Attributes.AUTHENTICATION_TIME));
    JWTClaimsSet jwtClaimsSet = csBuilder.build();
    if (DEBUG)
        jlog.debug(jwtClaimsSet.getClaim(Attributes.AUTHENTICATION_TIME));
    SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), jwtClaimsSet);
    try {
        signedJWT.sign(signer);
    } catch (JOSEException e) {
        e.printStackTrace();
    }
    return signedJWT;
}
Also used : GenericUserData(de.ids_mannheim.korap.user.GenericUserData) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Builder(com.nimbusds.jwt.JWTClaimsSet.Builder) Userdata(de.ids_mannheim.korap.user.Userdata) SignedJWT(com.nimbusds.jwt.SignedJWT) JOSEException(com.nimbusds.jose.JOSEException) JWSHeader(com.nimbusds.jose.JWSHeader)

Example 5 with Userdata

use of de.ids_mannheim.korap.user.Userdata in project Kustvakt by KorAP.

the class ShibbolethUserController method getDetails.

@GET
@Path("details")
@ResourceFilters({ AuthenticationFilter.class, DemoUserFilter.class, PiwikFilter.class, BlockingFilter.class })
public Response getDetails(@Context SecurityContext context, @Context Locale locale, @QueryParam("pointer") String pointer) {
    TokenContext ctx = (TokenContext) context.getUserPrincipal();
    String result;
    try {
        User user = controller.getUser(ctx.getUsername());
        Userdata data = controller.getUserData(user, UserDetails.class);
        data.setField(Attributes.USERNAME, ctx.getUsername());
        if (pointer != null)
            result = data.get(pointer).toString();
        else
            result = data.serialize();
    } catch (KustvaktException e) {
        jlog.error("Exception encountered: " + e.string());
        throw kustvaktResponseHandler.throwit(e);
    }
    return Response.ok(result).build();
}
Also used : TokenContext(de.ids_mannheim.korap.security.context.TokenContext) User(de.ids_mannheim.korap.user.User) KorAPUser(de.ids_mannheim.korap.user.KorAPUser) KustvaktException(de.ids_mannheim.korap.exceptions.KustvaktException) Userdata(de.ids_mannheim.korap.user.Userdata) Path(javax.ws.rs.Path) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) GET(javax.ws.rs.GET)

Aggregations

Userdata (de.ids_mannheim.korap.user.Userdata)8 User (de.ids_mannheim.korap.user.User)7 KorAPUser (de.ids_mannheim.korap.user.KorAPUser)6 KustvaktException (de.ids_mannheim.korap.exceptions.KustvaktException)5 TokenContext (de.ids_mannheim.korap.security.context.TokenContext)5 ResourceFilters (com.sun.jersey.spi.container.ResourceFilters)4 Path (javax.ws.rs.Path)4 GET (javax.ws.rs.GET)3 BeanConfigTest (de.ids_mannheim.korap.config.BeanConfigTest)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 JOSEException (com.nimbusds.jose.JOSEException)1 JWSHeader (com.nimbusds.jose.JWSHeader)1 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)1 Builder (com.nimbusds.jwt.JWTClaimsSet.Builder)1 SignedJWT (com.nimbusds.jwt.SignedJWT)1 Scopes (de.ids_mannheim.korap.config.Scopes)1 GenericUserData (de.ids_mannheim.korap.user.GenericUserData)1 UserSettingProcessor (de.ids_mannheim.korap.user.UserSettingProcessor)1 Consumes (javax.ws.rs.Consumes)1